In version 4.x of @sapphire/shapeshift we have changed the entire API to support supplying custom messages for your errors in order to allow for better localization and customization of the error messages. This guide will help you migrate your code from v3.x to v4.x.
Before we start we should note that with the amount of changes that have been made it is entirely possible that we have forgot to mention something in this guide. We therefore strongly recommend the usage of some form of type checking (i.e. through TypeScript) for your code base to ensure that all your code is compliant and correctly migrated. If you find that we have failed to mention anything, we would also greatly appreciate a Pull Request to update this document.
In general the biggest change between v3.x and v4.x is that where before you would write validators like this:
import { s } from '@sapphire/shapeshift';
const validator = s.string;
Wherein string
would be a getter for our StringValidator
class, you would now write validators like this:
import { s } from '@sapphire/shapeshift';
const validator = s.string();
This is to allow for passing arguments to the method, currently only a custom message but potentially more in the
future. These kind of methods accept a single parameter which is an object with a message
key. This message represents
the custom message that will be available on the error object when the validation fails.
An example of this would be:
import { s } from '@sapphire/shapeshift';
const validator = s.string({ message: 'This is a custom message' });
For a (non-exhaustive) list of all the methods there we changed please see List of function changes below.
Three types were removed that were previously marked as @deprecated
in v3.x. We took the oppertunity of the major
release to remove these deprecated types. For a list of all the types that were removed please see List of Type Only
changes below.
s.any
is nows.any()
to allow for custom options as argument.s.array(T).lengthEqual
is nows.array(T).lengthEqual()
to allow for custom options as argument.s.array(T).lengthGreaterThan
is nows.array(T).lengthGreaterThan()
to allow for custom options as argument.s.array(T).lengthGreaterThanOrEqual
is nows.array(T).lengthGreaterThanOrEqual()
to allow for custom options as argument.s.array(T).lengthLessThan
is nows.array(T).lengthLessThan()
to allow for custom options as argument.s.array(T).lengthLessThanOrEqual
is nows.array(T).lengthLessThanOrEqual()
to allow for custom options as argument.s.array(T).lengthNotEqual
is nows.array(T).lengthNotEqual()
to allow for custom options as argument.s.array(T).lengthRange
is nows.array(T).lengthRange()
to allow for custom options as argument.s.array(T).lengthRangeExclusive
is nows.array(T).lengthRangeExclusive()
to allow for custom options as argument.s.array(T).lengthRangeInclusive
is nows.array(T).lengthRangeInclusive()
to allow for custom options as argument.s.array(T).unique
is nows.array(T).unique()
to allow for custom options as argument.s.array
is nows.array()
to allow for custom options as argument.s.bigint.divisibleBy
is nows.bigint().divisibleBy()
to allow for custom options as argument.s.bigint.equal
is nows.bigint().equal()
to allow for custom options as argument.s.bigint.greaterThan
is nows.bigint().greaterThan()
to allow for custom options as argument.s.bigint.greaterThanOrEqual
is nows.bigint().greaterThanOrEqual()
to allow for custom options as argument.s.bigint.lessThan
is nows.bigint().lessThan()
to allow for custom options as argument.s.bigint.lessThanOrEqual
is nows.bigint().lessThanOrEqual()
to allow for custom options as argument.s.bigint.notEqual
is nows.bigint().notEqual()
to allow for custom options as argument.s.bigint().abs
is nows.bigint().abs()
to allow for custom options as second argument.s.bigint().negative
is nows.bigint().negative()
to allow for custom options as second argument.s.bigint().positive
is nows.bigint().positive()
to allow for custom options as second argument.s.bigint
is nows.bigint()
to allow for custom options as argument.s.bigInt64Array
is nows.bigInt64Array()
to allow for custom options as argument.s.bigUint64Array
is nows.bigUint64Array()
to allow for custom options as argument.s.boolean.false
is nows.boolean().false()
to allow for custom options as second argument.s.boolean.true
is nows.boolean().true()
to allow for custom options as second argument.s.boolean
is nows.boolean()
to allow for custom options as argument.s.default(...)
now gets a second parameter to allow for custom options as argument.s.default(...).default(...)
now gets a second parameter to allow for custom options as argument.s.date.equal
is nows.date().equal()
to allow for custom options as argument.s.date.greaterThan
is nows.date().greaterThan()
to allow for custom options as argument.s.date.greaterThanOrEqual
is nows.date().greaterThanOrEqual()
to allow for custom options as argument.s.date.invalid
is nows.date().invalid()
to allow for custom options as argument.s.date.lessThan
is nows.date().lessThan()
to allow for custom options as argument.s.date.lessThanOrEqual
is nows.date().lessThanOrEqual()
to allow for custom options as argument.s.date.notEqual
is nows.date().notEqual()
to allow for custom options as argument.s.date.valid
is nows.date().valid()
to allow for custom options as argument.s.date
is nows.date()
to allow for custom options as argument.s.enum(1, 2, 3)
is nows.enum([1, 2, 3])
to allow for custom options as second argument.s.float32Array
is nows.float32Array()
to allow for custom options as argument.s.float64Array
is nows.float64Array()
to allow for custom options as argument.s.int16Array
is nows.int16Array()
to allow for custom options as argument.s.int32Array
is nows.int32Array()
to allow for custom options as argument.s.int8Array
is nows.int8Array()
to allow for custom options as argument.s.never
is nows.never()
to allow for custom options as argument.s.null
is nows.null()
to allow for custom options as argument.s.nullable
is nows.nullable()
to allow for custom options as argument.s.nullish
is nows.nullish()
to allow for custom options as argument.s.nullish
is nows.nullish()
to allow for custom options as argument.s.number.abs
is nows.number().abs()
to allow for custom options as argument.s.number.ceil
is nows.number().ceil()
to allow for custom options as argument.s.number.divisibleBy
is nows.number().divisibleBy()
to allow for custom options as argument.s.number.equal
is nows.number().equal()
to allow for custom options as argument.s.number.finite
is nows.number().finite()
to allow for custom options as argument.s.number.floor
is nows.number().floor()
to allow for custom options as argument.s.number.fround
is nows.number().fround()
to allow for custom options as argument.s.number.greaterThan
is nows.number().greaterThan()
to allow for custom options as argument.s.number.greaterThanOrEqual
is nows.number().greaterThanOrEqual()
to allow for custom options as argument.s.number.int
is nows.number().int()
to allow for custom options as argument.s.number.lessThan
is nows.number().lessThan()
to allow for custom options as argument.s.number.lessThanOrEqual
is nows.number().lessThanOrEqual()
to allow for custom options as argument.s.number.negative
is nows.number().negative()
to allow for custom options as argument.s.number.notEqual
is nows.number().notEqual()
to allow for custom options as argument.s.number.positive
is nows.number().positive()
to allow for custom options as argument.s.number.round
is nows.number().round()
to allow for custom options as argument.s.number.safeInt
is nows.number().safeInt()
to allow for custom options as argument.s.number.sign
is nows.number().sign()
to allow for custom options as argument.s.number.trunc
is nows.number().trunc()
to allow for custom options as argument.s.number
is nows.number()
to allow for custom options as argument.s.object.ignore
is nows.object().ignore()
to allow for custom options as argument.s.object.partial
is nows.object().partial()
to allow for custom options as argument.s.object.passthrough
is nows.object().passthrough()
to allow for custom options as argument.s.object.required
is nows.object().required()
to allow for custom options as argument.s.object.strict
is nows.object().strict()
to allow for custom options as argument.s.optional
is nows.optional()
to allow for custom options as argument.s.required(...)
now gets a second parameter to allow for custom options as argument.s.set
is nows.set()
to allow for custom options as argument.s.string.date
is nows.string().date()
to allow for custom options as argument.s.string.email
is nows.string().email()
to allow for custom options as argument.s.string.ipv4
is nows.string().ipv4()
to allow for custom options as argument.s.string.ipv6
is nows.string().ipv6()
to allow for custom options as argument.s.string().ip
is nows.string().ip()
to allow for custom options as argument.s.string().lengthEqual
is nows.string().lengthEqual()
to allow for custom options as argument.s.string().lengthGreaterThan
is nows.string().lengthGreaterThan()
to allow for custom options as argument.s.string().lengthGreaterThanOrEqual
is nows.string().lengthGreaterThanOrEqual()
to allow for custom options as argument.s.string().lengthLessThan
is nows.string().lengthLessThan()
to allow for custom options as argument.s.string().lengthLessThanOrEqual
is nows.string().lengthLessThanOrEqual()
to allow for custom options as argument.s.string().lengthNotEqual
is nows.string().lengthNotEqual()
to allow for custom options as argument.s.string().phone
is nows.string().phone()
to allow for custom options as argument.s.string().regex
is nows.string().regex()
to allow for custom options as argument.s.string().url
is nows.string().url()
to allow for custom options as argument.s.string
is nows.string()
to allow for custom options as argument.s.tuple(1, 2, 3)
is nows.tuple([1, 2, 3])
to allow for custom options as second argument.s.typedArray(T).byteLengthEqual
is nows.typedArray(T).byteLengthEqual()
to allow for custom options as argument.s.typedArray(T).byteLengthGreaterThan
is nows.typedArray(T).byteLengthGreaterThan()
to allow for custom options as argument.s.typedArray(T).byteLengthGreaterThanOrEqual
is nows.typedArray(T).byteLengthGreaterThanOrEqual()
to allow for custom options as argument.s.typedArray(T).byteLengthLessThan
is nows.typedArray(T).byteLengthLessThan()
to allow for custom options as argument.s.typedArray(T).byteLengthLessThanOrEqual
is nows.typedArray(T).byteLengthLessThanOrEqual()
to allow for custom options as argument.s.typedArray(T).byteLengthNotEqual
is nows.typedArray(T).byteLengthNotEqual()
to allow for custom options as argument.s.typedArray(T).byteLengthRange
is nows.typedArray(T).byteLengthRange()
to allow for custom options as argument.s.typedArray(T).byteLengthRangeExclusive
is nows.typedArray(T).byteLengthRangeExclusive()
to allow for custom options as argument.s.typedArray(T).byteLengthRangeInclusive
is nows.typedArray(T).byteLengthRangeInclusive()
to allow for custom options as argument.s.typedArray(T).lengthEqual
is nows.typedArray(T).lengthEqual()
to allow for custom options as argument.s.typedArray(T).lengthGreaterThan
is nows.typedArray(T).lengthGreaterThan()
to allow for custom options as argument.s.typedArray(T).lengthGreaterThanOrEqual
is nows.typedArray(T).lengthGreaterThanOrEqual()
to allow for custom options as argument.s.typedArray(T).lengthLessThan
is nows.typedArray(T).lengthLessThan()
to allow for custom options as argument.s.typedArray(T).lengthLessThanOrEqual
is nows.typedArray(T).lengthLessThanOrEqual()
to allow for custom options as argument.s.typedArray(T).lengthNotEqual
is nows.typedArray(T).lengthNotEqual()
to allow for custom options as argument.s.typedArray(T).lengthRange
is nows.typedArray(T).lengthRange()
to allow for custom options as argument.s.typedArray(T).lengthRangeExclusive
is nows.typedArray(T).lengthRangeExclusive()
to allow for custom options as argument.s.typedArray(T).lengthRangeInclusive
is nows.typedArray(T).lengthRangeInclusive()
to allow for custom options as argument.s.uint16Array
is nows.uint16Array()
to allow for custom options as argument.s.uint32Array
is nows.uint32Array()
to allow for custom options as argument.s.uint8Array
is nows.uint8Array()
to allow for custom options as argument.s.uint8ClampedArray
is nows.uint8ClampedArray()
to allow for custom options as argument.s.undefined
is nows.undefined()
to allow for custom options as argument.s.union(1, 2, 3).required
is nows.union(1, 2, 3).required()
to allow for custom options as argument.s.union(1, 2, 3)
is nows.union([1, 2, 3])
to allow for custom options as second argument.s.unknown
is nows.unknown()
to allow for custom options as argument.uniqueArray
is now a function (instead of a constant) to allow for custom options as argument.dateInvalid
is now a function (instead of a constant) to allow for custom options as argument.dateValid
is now a function (instead of a constant) to allow for custom options as argument.numberFinite
is now a function (instead of a constant) to allow for custom options as argument.numberInt
is now a function (instead of a constant) to allow for custom options as argument.numberNaN
is now a function (instead of a constant) to allow for custom options as argument.numberNotNaN
is now a function (instead of a constant) to allow for custom options as argument.numberSafeInt
is now a function (instead of a constant) to allow for custom options as argument.
PickDefined
utility type has been removed.PickUndefinedMakeOptional
utility type has been removed.NonNullObject
utility type has been removed.