@sapphire/shapeshift
Advanced tools
Comparing version 2.2.1-next.c83b3d0.0 to 3.0.0-next.2fef902.0
@@ -21,9 +21,9 @@ /// <reference types="node" /> | ||
declare type ArrayConstraintName = `s.array(T).length${'Lt' | 'Le' | 'Gt' | 'Ge' | 'Eq' | 'Ne' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`; | ||
declare function arrayLengthLt<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthLe<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthGt<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthGe<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthEq<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthNe<T>(value: number): IConstraint<T[]>; | ||
declare type ArrayConstraintName = `s.array(T).length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`; | ||
declare function arrayLengthLessThan<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthLessThanOrEqual<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthGreaterThan<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthGreaterThanOrEqual<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthEqual<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthNotEqual<T>(value: number): IConstraint<T[]>; | ||
declare function arrayLengthRange<T>(start: number, endBefore: number): IConstraint<T[]>; | ||
@@ -33,2 +33,63 @@ declare function arrayLengthRangeInclusive<T>(start: number, end: number): IConstraint<T[]>; | ||
declare type BigIntConstraintName = `s.bigint.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'divisibleBy'}`; | ||
declare function bigintLessThan(value: bigint): IConstraint<bigint>; | ||
declare function bigintLessThanOrEqual(value: bigint): IConstraint<bigint>; | ||
declare function bigintGreaterThan(value: bigint): IConstraint<bigint>; | ||
declare function bigintGreaterThanOrEqual(value: bigint): IConstraint<bigint>; | ||
declare function bigintEqual(value: bigint): IConstraint<bigint>; | ||
declare function bigintNotEqual(value: bigint): IConstraint<bigint>; | ||
declare function bigintDivisibleBy(divider: bigint): IConstraint<bigint>; | ||
declare type BooleanConstraintName = `s.boolean.${boolean}`; | ||
declare const booleanTrue: IConstraint<boolean, true>; | ||
declare const booleanFalse: IConstraint<boolean, false>; | ||
declare type DateConstraintName = `s.date.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'notEqual' | 'valid' | 'invalid'}`; | ||
declare function dateLessThan(value: Date): IConstraint<Date>; | ||
declare function dateLessThanOrEqual(value: Date): IConstraint<Date>; | ||
declare function dateGreaterThan(value: Date): IConstraint<Date>; | ||
declare function dateGreaterThanOrEqual(value: Date): IConstraint<Date>; | ||
declare function dateEqual(value: Date): IConstraint<Date>; | ||
declare function dateNotEqual(value: Date): IConstraint<Date>; | ||
declare const dateInvalid: IConstraint<Date>; | ||
declare const dateValid: IConstraint<Date>; | ||
declare type NumberConstraintName = `s.number.${'lessThan' | 'lessThanOrEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'equal' | 'equal(NaN)' | 'notEqual' | 'notEqual(NaN)' | 'int' | 'safeInt' | 'finite' | 'divisibleBy'}`; | ||
declare function numberLessThan(value: number): IConstraint<number>; | ||
declare function numberLessThanOrEqual(value: number): IConstraint<number>; | ||
declare function numberGreaterThan(value: number): IConstraint<number>; | ||
declare function numberGreaterThanOrEqual(value: number): IConstraint<number>; | ||
declare function numberEqual(value: number): IConstraint<number>; | ||
declare function numberNotEqual(value: number): IConstraint<number>; | ||
declare const numberInt: IConstraint<number>; | ||
declare const numberSafeInt: IConstraint<number>; | ||
declare const numberFinite: IConstraint<number>; | ||
declare const numberNaN: IConstraint<number>; | ||
declare const numberNotNaN: IConstraint<number>; | ||
declare function numberDivisibleBy(divider: number): IConstraint<number>; | ||
declare type StringConstraintName = `s.string.${`length${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual'}` | 'regex' | 'url' | 'uuid' | 'email' | `ip${'v4' | 'v6' | ''}`}`; | ||
declare type StringProtocol = `${string}:`; | ||
declare type StringDomain = `${string}.${string}`; | ||
interface UrlOptions { | ||
allowedProtocols?: StringProtocol[]; | ||
allowedDomains?: StringDomain[]; | ||
} | ||
declare type UUIDVersion = 1 | 3 | 4 | 5; | ||
interface StringUuidOptions { | ||
version?: UUIDVersion | `${UUIDVersion}-${UUIDVersion}` | null; | ||
nullable?: boolean; | ||
} | ||
declare function stringLengthLessThan(length: number): IConstraint<string>; | ||
declare function stringLengthLessThanOrEqual(length: number): IConstraint<string>; | ||
declare function stringLengthGreaterThan(length: number): IConstraint<string>; | ||
declare function stringLengthGreaterThanOrEqual(length: number): IConstraint<string>; | ||
declare function stringLengthEqual(length: number): IConstraint<string>; | ||
declare function stringLengthNotEqual(length: number): IConstraint<string>; | ||
declare function stringEmail(): IConstraint<string>; | ||
declare function stringUrl(options?: UrlOptions): IConstraint<string>; | ||
declare function stringIp(version?: 4 | 6): IConstraint<string>; | ||
declare function stringRegex(regex: RegExp): IConstraint<string, string>; | ||
declare function stringUuid({ version, nullable }?: StringUuidOptions): IConstraint<string, string>; | ||
declare const customInspectSymbol: unique symbol; | ||
@@ -71,9 +132,9 @@ declare const customInspectSymbolStackLess: unique symbol; | ||
declare type TypedArrayConstraintName = `s.typedArray(T).${'byteLength' | 'length'}${'Lt' | 'Le' | 'Gt' | 'Ge' | 'Eq' | 'Ne' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`; | ||
declare function typedArrayByteLengthLt<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthLe<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthGt<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthGe<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthEq<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthNe<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare type TypedArrayConstraintName = `s.typedArray(T).${'byteLength' | 'length'}${'LessThan' | 'LessThanOrEqual' | 'GreaterThan' | 'GreaterThanOrEqual' | 'Equal' | 'NotEqual' | 'Range' | 'RangeInclusive' | 'RangeExclusive'}`; | ||
declare function typedArrayByteLengthLessThan<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthLessThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthGreaterThan<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthGreaterThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthNotEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayByteLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>; | ||
@@ -84,8 +145,8 @@ declare function typedArrayByteLengthRangeInclusive<T extends TypedArray>(start: number, end: number): { | ||
declare function typedArrayByteLengthRangeExclusive<T extends TypedArray>(startAfter: number, endBefore: number): IConstraint<T>; | ||
declare function typedArrayLengthLt<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthLe<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthGt<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthGe<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthEq<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthNe<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthLessThan<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthLessThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthGreaterThan<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthGreaterThanOrEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthNotEqual<T extends TypedArray>(value: number): IConstraint<T>; | ||
declare function typedArrayLengthRange<T extends TypedArray>(start: number, endBefore: number): IConstraint<T>; | ||
@@ -95,63 +156,2 @@ declare function typedArrayLengthRangeInclusive<T extends TypedArray>(start: number, end: number): IConstraint<T>; | ||
declare type BigIntConstraintName = `s.bigint.${'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'ne' | 'divisibleBy'}`; | ||
declare function bigintLt(value: bigint): IConstraint<bigint>; | ||
declare function bigintLe(value: bigint): IConstraint<bigint>; | ||
declare function bigintGt(value: bigint): IConstraint<bigint>; | ||
declare function bigintGe(value: bigint): IConstraint<bigint>; | ||
declare function bigintEq(value: bigint): IConstraint<bigint>; | ||
declare function bigintNe(value: bigint): IConstraint<bigint>; | ||
declare function bigintDivisibleBy(divider: bigint): IConstraint<bigint>; | ||
declare type BooleanConstraintName = `s.boolean.${boolean}`; | ||
declare const booleanTrue: IConstraint<boolean, true>; | ||
declare const booleanFalse: IConstraint<boolean, false>; | ||
declare type DateConstraintName = `s.date.${'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'ne' | 'valid' | 'invalid'}`; | ||
declare function dateLt(value: Date): IConstraint<Date>; | ||
declare function dateLe(value: Date): IConstraint<Date>; | ||
declare function dateGt(value: Date): IConstraint<Date>; | ||
declare function dateGe(value: Date): IConstraint<Date>; | ||
declare function dateEq(value: Date): IConstraint<Date>; | ||
declare function dateNe(value: Date): IConstraint<Date>; | ||
declare const dateInvalid: IConstraint<Date>; | ||
declare const dateValid: IConstraint<Date>; | ||
declare type NumberConstraintName = `s.number.${'lt' | 'le' | 'gt' | 'ge' | 'eq' | 'eq(NaN)' | 'ne' | 'ne(NaN)' | 'int' | 'safeInt' | 'finite' | 'divisibleBy'}`; | ||
declare function numberLt(value: number): IConstraint<number>; | ||
declare function numberLe(value: number): IConstraint<number>; | ||
declare function numberGt(value: number): IConstraint<number>; | ||
declare function numberGe(value: number): IConstraint<number>; | ||
declare function numberEq(value: number): IConstraint<number>; | ||
declare function numberNe(value: number): IConstraint<number>; | ||
declare const numberInt: IConstraint<number>; | ||
declare const numberSafeInt: IConstraint<number>; | ||
declare const numberFinite: IConstraint<number>; | ||
declare const numberNaN: IConstraint<number>; | ||
declare const numberNeNaN: IConstraint<number>; | ||
declare function numberDivisibleBy(divider: number): IConstraint<number>; | ||
declare type StringConstraintName = `s.string.${`length${'Lt' | 'Le' | 'Gt' | 'Ge' | 'Eq' | 'Ne'}` | 'regex' | 'url' | 'uuid' | 'email' | `ip${'v4' | 'v6' | ''}`}`; | ||
declare type StringProtocol = `${string}:`; | ||
declare type StringDomain = `${string}.${string}`; | ||
interface UrlOptions { | ||
allowedProtocols?: StringProtocol[]; | ||
allowedDomains?: StringDomain[]; | ||
} | ||
declare type UUIDVersion = 1 | 3 | 4 | 5; | ||
interface StringUuidOptions { | ||
version?: UUIDVersion | `${UUIDVersion}-${UUIDVersion}` | null; | ||
nullable?: boolean; | ||
} | ||
declare function stringLengthLt(length: number): IConstraint<string>; | ||
declare function stringLengthLe(length: number): IConstraint<string>; | ||
declare function stringLengthGt(length: number): IConstraint<string>; | ||
declare function stringLengthGe(length: number): IConstraint<string>; | ||
declare function stringLengthEq(length: number): IConstraint<string>; | ||
declare function stringLengthNe(length: number): IConstraint<string>; | ||
declare function stringEmail(): IConstraint<string>; | ||
declare function stringUrl(options?: UrlOptions): IConstraint<string>; | ||
declare function stringIp(version?: 4 | 6): IConstraint<string>; | ||
declare function stringRegex(regex: RegExp): IConstraint<string, string>; | ||
declare function stringUuid({ version, nullable }?: StringUuidOptions): IConstraint<string, string>; | ||
declare type ConstraintErrorNames = TypedArrayConstraintName | ArrayConstraintName | BigIntConstraintName | BooleanConstraintName | DateConstraintName | NumberConstraintName | StringConstraintName; | ||
@@ -230,8 +230,8 @@ declare abstract class BaseConstraintError<T = unknown> extends BaseError { | ||
constructor(validator: BaseValidator<T>, constraints?: readonly IConstraint<T[]>[]); | ||
lengthLt<N extends number>(length: N): BaseValidator<ExpandSmallerTuples<UnshiftTuple<[...Tuple<T, N>]>>>; | ||
lengthLe<N extends number>(length: N): BaseValidator<ExpandSmallerTuples<[...Tuple<T, N>]>>; | ||
lengthGt<N extends number>(length: N): BaseValidator<[...Tuple<T, N>, T, ...T[]]>; | ||
lengthGe<N extends number>(length: N): BaseValidator<[...Tuple<T, N>, ...T[]]>; | ||
lengthEq<N extends number>(length: N): BaseValidator<[...Tuple<T, N>]>; | ||
lengthNe(length: number): BaseValidator<[...T[]]>; | ||
lengthLessThan<N extends number>(length: N): BaseValidator<ExpandSmallerTuples<UnshiftTuple<[...Tuple<T, N>]>>>; | ||
lengthLessThanOrEqual<N extends number>(length: N): BaseValidator<ExpandSmallerTuples<[...Tuple<T, N>]>>; | ||
lengthGreaterThan<N extends number>(length: N): BaseValidator<[...Tuple<T, N>, T, ...T[]]>; | ||
lengthGreaterThanOrEqual<N extends number>(length: N): BaseValidator<[...Tuple<T, N>, ...T[]]>; | ||
lengthEqual<N extends number>(length: N): BaseValidator<[...Tuple<T, N>]>; | ||
lengthNotEqual(length: number): BaseValidator<[...T[]]>; | ||
lengthRange<S extends number, E extends number>(start: S, endBefore: E): BaseValidator<Exclude<ExpandSmallerTuples<UnshiftTuple<[...Tuple<T, E>]>>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<T, S>]>>>>; | ||
@@ -251,8 +251,8 @@ lengthRangeInclusive<S extends number, E extends number>(startAt: S, endAt: E): BaseValidator<Exclude<ExpandSmallerTuples<[...Tuple<T, E>]>, ExpandSmallerTuples<UnshiftTuple<[...Tuple<T, S>]>>>>; | ||
declare class BigIntValidator<T extends bigint> extends BaseValidator<T> { | ||
lt(number: bigint): this; | ||
le(number: bigint): this; | ||
gt(number: bigint): this; | ||
ge(number: bigint): this; | ||
eq<N extends bigint>(number: N): BigIntValidator<N>; | ||
ne(number: bigint): this; | ||
lessThan(number: bigint): this; | ||
lessThanOrEqual(number: bigint): this; | ||
greaterThan(number: bigint): this; | ||
greaterThanOrEqual(number: bigint): this; | ||
equal<N extends bigint>(number: N): BigIntValidator<N>; | ||
notEqual(number: bigint): this; | ||
get positive(): this; | ||
@@ -270,4 +270,4 @@ get negative(): this; | ||
get false(): BooleanValidator<false>; | ||
eq<R extends true | false>(value: R): BooleanValidator<R>; | ||
ne<R extends true | false>(value: R): BooleanValidator<R>; | ||
equal<R extends true | false>(value: R): BooleanValidator<R>; | ||
notEqual<R extends true | false>(value: R): BooleanValidator<R>; | ||
protected handle(value: unknown): Result<T, ValidationError>; | ||
@@ -277,8 +277,8 @@ } | ||
declare class DateValidator extends BaseValidator<Date> { | ||
lt(date: Date | number | string): this; | ||
le(date: Date | number | string): this; | ||
gt(date: Date | number | string): this; | ||
ge(date: Date | number | string): this; | ||
eq(date: Date | number | string): this; | ||
ne(date: Date | number | string): this; | ||
lessThan(date: Date | number | string): this; | ||
lessThanOrEqual(date: Date | number | string): this; | ||
greaterThan(date: Date | number | string): this; | ||
greaterThanOrEqual(date: Date | number | string): this; | ||
equal(date: Date | number | string): this; | ||
notEqual(date: Date | number | string): this; | ||
get valid(): this; | ||
@@ -331,8 +331,8 @@ get invalid(): this; | ||
declare class NumberValidator<T extends number> extends BaseValidator<T> { | ||
lt(number: number): this; | ||
le(number: number): this; | ||
gt(number: number): this; | ||
ge(number: number): this; | ||
eq<N extends number>(number: N): NumberValidator<N>; | ||
ne(number: number): this; | ||
lessThan(number: number): this; | ||
lessThanOrEqual(number: number): this; | ||
greaterThan(number: number): this; | ||
greaterThanOrEqual(number: number): this; | ||
equal<N extends number>(number: N): NumberValidator<N>; | ||
notEqual(number: number): this; | ||
get int(): this; | ||
@@ -359,2 +359,4 @@ get safeInt(): this; | ||
private readonly handleStrategy; | ||
private readonly requiredKeys; | ||
private readonly possiblyUndefinedKeys; | ||
constructor(shape: MappedObjectValidator<T>, strategy?: ObjectValidatorStrategy, constraints?: readonly IConstraint<T>[]); | ||
@@ -407,8 +409,8 @@ get strict(): ObjectValidator<{ | ||
declare class StringValidator<T extends string> extends BaseValidator<T> { | ||
lengthLt(length: number): this; | ||
lengthLe(length: number): this; | ||
lengthGt(length: number): this; | ||
lengthGe(length: number): this; | ||
lengthEq(length: number): this; | ||
lengthNe(length: number): this; | ||
lengthLessThan(length: number): this; | ||
lengthLessThanOrEqual(length: number): this; | ||
lengthGreaterThan(length: number): this; | ||
lengthGreaterThanOrEqual(length: number): this; | ||
lengthEqual(length: number): this; | ||
lengthNotEqual(length: number): this; | ||
get email(): this; | ||
@@ -476,17 +478,17 @@ url(options?: UrlOptions): this; | ||
constructor(type: TypedArrayName, constraints?: readonly IConstraint<T>[]); | ||
byteLengthLt(length: number): this; | ||
byteLengthLe(length: number): this; | ||
byteLengthGt(length: number): this; | ||
byteLengthGe(length: number): this; | ||
byteLengthEq(length: number): this; | ||
byteLengthNe(length: number): this; | ||
byteLengthLessThan(length: number): this; | ||
byteLengthLessThanOrEqual(length: number): this; | ||
byteLengthGreaterThan(length: number): this; | ||
byteLengthGreaterThanOrEqual(length: number): this; | ||
byteLengthEqual(length: number): this; | ||
byteLengthNotEqual(length: number): this; | ||
byteLengthRange(start: number, endBefore: number): this; | ||
byteLengthRangeInclusive(startAt: number, endAt: number): this; | ||
byteLengthRangeExclusive(startAfter: number, endBefore: number): this; | ||
lengthLt(length: number): this; | ||
lengthLe(length: number): this; | ||
lengthGt(length: number): this; | ||
lengthGe(length: number): this; | ||
lengthEq(length: number): this; | ||
lengthNe(length: number): this; | ||
lengthLessThan(length: number): this; | ||
lengthLessThanOrEqual(length: number): this; | ||
lengthGreaterThan(length: number): this; | ||
lengthGreaterThanOrEqual(length: number): this; | ||
lengthEqual(length: number): this; | ||
lengthNotEqual(length: number): this; | ||
lengthRange(start: number, endBefore: number): this; | ||
@@ -572,4 +574,86 @@ lengthRangeInclusive(startAt: number, endAt: number): this; | ||
/** | ||
* An alias of {@link ObjectValidator} with a name more common among object validation libraries. | ||
* This is the type of a schema after using `s.object({ ... })` | ||
* @example | ||
* ```ts | ||
* import { s, SchemaOf } from '@sapphire/shapeshift'; | ||
* | ||
* interface IIngredient { | ||
* ingredientId: string | undefined; | ||
* name: string | undefined; | ||
* } | ||
* | ||
* interface IInstruction { | ||
* instructionId: string | undefined; | ||
* message: string | undefined; | ||
* } | ||
* | ||
* interface IRecipe { | ||
* recipeId: string | undefined; | ||
* title: string; | ||
* description: string; | ||
* instructions: IInstruction[]; | ||
* ingredients: IIngredient[]; | ||
* } | ||
* | ||
* type InstructionSchemaType = SchemaOf<IInstruction>; | ||
* // Expected Type: ObjectValidator<IInstruction> | ||
* | ||
* type IngredientSchemaType = SchemaOf<IIngredient>; | ||
* // Expected Type: ObjectValidator<IIngredient> | ||
* | ||
* type RecipeSchemaType = SchemaOf<IRecipe>; | ||
* // Expected Type: ObjectValidator<IRecipe> | ||
* | ||
* const instructionSchema: InstructionSchemaType = s.object({ | ||
* instructionId: s.string.optional, | ||
* message: s.string | ||
* }); | ||
* | ||
* const ingredientSchema: IngredientSchemaType = s.object({ | ||
* ingredientId: s.string.optional, | ||
* name: s.string | ||
* }); | ||
* | ||
* const recipeSchema: RecipeSchemaType = s.object({ | ||
* recipeId: s.string.optional, | ||
* title: s.string, | ||
* description: s.string, | ||
* instructions: s.array(instructionSchema), | ||
* ingredients: s.array(ingredientSchema) | ||
* }); | ||
* ``` | ||
*/ | ||
declare type SchemaOf<T> = ObjectValidator<T>; | ||
/** | ||
* Infers the type of a schema object given `typeof schema`. | ||
* The schema has to extend {@link ObjectValidator}. | ||
* @example | ||
* ```ts | ||
* import { InferType, s } from '@sapphire/shapeshift'; | ||
* | ||
* const schema = s.object({ | ||
* foo: s.string, | ||
* bar: s.number, | ||
* baz: s.boolean, | ||
* qux: s.bigint, | ||
* quux: s.date | ||
* }); | ||
* | ||
* type Inferredtype = InferType<typeof schema>; | ||
* // Expected type: | ||
* // type Inferredtype = { | ||
* // foo: string; | ||
* // bar: number; | ||
* // baz: boolean; | ||
* // qux: bigint; | ||
* // quux: Date; | ||
* // }; | ||
* ``` | ||
*/ | ||
declare type InferType<T extends ObjectValidator<any>> = T extends ObjectValidator<infer U> ? U : never; | ||
declare const s: Shapes; | ||
export { ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, GrowExp, GrowExpRev, IConstraint, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, NativeEnumLike, NativeEnumValidator, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, RecordValidator, Result, SetValidator, Shapes, Shift, StringConstraintName, StringDomain, StringProtocol, StringUuidOptions, StringValidator, Tuple, TupleValidator, Type, TypedArrayConstraintName, TypedArrayValidator, UUIDVersion, UnionValidator, UnknownEnumValueError, UnknownPropertyError, UnshiftTuple, Unwrap, UnwrapTuple, UrlOptions, ValidationError, ValidatorError, arrayLengthEq, arrayLengthGe, arrayLengthGt, arrayLengthLe, arrayLengthLt, arrayLengthNe, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEq, bigintGe, bigintGt, bigintLe, bigintLt, bigintNe, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEq, dateGe, dateGt, dateInvalid, dateLe, dateLt, dateNe, dateValid, numberDivisibleBy, numberEq, numberFinite, numberGe, numberGt, numberInt, numberLe, numberLt, numberNaN, numberNe, numberNeNaN, numberSafeInt, s, stringEmail, stringIp, stringLengthEq, stringLengthGe, stringLengthGt, stringLengthLe, stringLengthLt, stringLengthNe, stringRegex, stringUrl, stringUuid, typedArrayByteLengthEq, typedArrayByteLengthGe, typedArrayByteLengthGt, typedArrayByteLengthLe, typedArrayByteLengthLt, typedArrayByteLengthNe, typedArrayByteLengthRange, typedArrayByteLengthRangeExclusive, typedArrayByteLengthRangeInclusive, typedArrayLengthEq, typedArrayLengthGe, typedArrayLengthGt, typedArrayLengthLe, typedArrayLengthLt, typedArrayLengthNe, typedArrayLengthRange, typedArrayLengthRangeExclusive, typedArrayLengthRangeInclusive }; | ||
export { ArrayConstraintName, ArrayValidator, BaseConstraintError, BaseError, BaseValidator, BigIntConstraintName, BigIntValidator, BooleanConstraintName, BooleanValidator, CombinedError, CombinedPropertyError, ConstraintErrorNames, Constructor, DateConstraintName, DateValidator, DefaultValidator, ExpandSmallerTuples, ExpectedConstraintError, ExpectedValidationError, GrowExp, GrowExpRev, IConstraint, InferType, InstanceValidator, LiteralValidator, MapValidator, MappedObjectValidator, MissingPropertyError, MultiplePossibilitiesConstraintError, NativeEnumLike, NativeEnumValidator, NeverValidator, NonNullObject, NullishValidator, NumberConstraintName, NumberValidator, ObjectValidator, ObjectValidatorStrategy, PassthroughValidator, RecordValidator, Result, SchemaOf, SetValidator, Shapes, Shift, StringConstraintName, StringDomain, StringProtocol, StringUuidOptions, StringValidator, Tuple, TupleValidator, Type, TypedArrayConstraintName, TypedArrayValidator, UUIDVersion, UnionValidator, UnknownEnumValueError, UnknownPropertyError, UnshiftTuple, Unwrap, UnwrapTuple, UrlOptions, ValidationError, ValidatorError, arrayLengthEqual, arrayLengthGreaterThan, arrayLengthGreaterThanOrEqual, arrayLengthLessThan, arrayLengthLessThanOrEqual, arrayLengthNotEqual, arrayLengthRange, arrayLengthRangeExclusive, arrayLengthRangeInclusive, bigintDivisibleBy, bigintEqual, bigintGreaterThan, bigintGreaterThanOrEqual, bigintLessThan, bigintLessThanOrEqual, bigintNotEqual, booleanFalse, booleanTrue, customInspectSymbol, customInspectSymbolStackLess, dateEqual, dateGreaterThan, dateGreaterThanOrEqual, dateInvalid, dateLessThan, dateLessThanOrEqual, dateNotEqual, dateValid, numberDivisibleBy, numberEqual, numberFinite, numberGreaterThan, numberGreaterThanOrEqual, numberInt, numberLessThan, numberLessThanOrEqual, numberNaN, numberNotEqual, numberNotNaN, numberSafeInt, s, stringEmail, stringIp, stringLengthEqual, stringLengthGreaterThan, stringLengthGreaterThanOrEqual, stringLengthLessThan, stringLengthLessThanOrEqual, stringLengthNotEqual, stringRegex, stringUrl, stringUuid, typedArrayByteLengthEqual, typedArrayByteLengthGreaterThan, typedArrayByteLengthGreaterThanOrEqual, typedArrayByteLengthLessThan, typedArrayByteLengthLessThanOrEqual, typedArrayByteLengthNotEqual, typedArrayByteLengthRange, typedArrayByteLengthRangeExclusive, typedArrayByteLengthRangeInclusive, typedArrayLengthEqual, typedArrayLengthGreaterThan, typedArrayLengthGreaterThanOrEqual, typedArrayLengthLessThan, typedArrayLengthLessThanOrEqual, typedArrayLengthNotEqual, typedArrayLengthRange, typedArrayLengthRangeExclusive, typedArrayLengthRangeInclusive }; |
{ | ||
"name": "@sapphire/shapeshift", | ||
"version": "2.2.1-next.c83b3d0.0", | ||
"version": "3.0.0-next.2fef902.0", | ||
"description": "Blazing fast input validation and transformation ⚡", | ||
@@ -5,0 +5,0 @@ "author": "@sapphire", |
@@ -94,3 +94,3 @@ <div align="center"> | ||
s.literal(true); | ||
s.literal(new Date(1639278160000)); // s.date.eq(1639278160000); | ||
s.literal(new Date(1639278160000)); // s.date.equal(1639278160000); | ||
``` | ||
@@ -103,8 +103,8 @@ | ||
```typescript | ||
s.string.lengthLt(5); | ||
s.string.lengthLe(5); | ||
s.string.lengthGt(5); | ||
s.string.lengthGe(5); | ||
s.string.lengthEq(5); | ||
s.string.lengthNe(5); | ||
s.string.lengthLessThan(5); | ||
s.string.lengthLessThanOrEqual(5); | ||
s.string.lengthGreaterThan(5); | ||
s.string.lengthGreaterThanOrEqual(5); | ||
s.string.lengthEqual(5); | ||
s.string.lengthNotEqual(5); | ||
s.string.email; | ||
@@ -124,11 +124,11 @@ s.string.url(); | ||
```typescript | ||
s.number.gt(5); // > 5 | ||
s.number.ge(5); // >= 5 | ||
s.number.lt(5); // < 5 | ||
s.number.le(5); // <= 5 | ||
s.number.eq(5); // === 5 | ||
s.number.ne(5); // !== 5 | ||
s.number.greaterThan(5); // > 5 | ||
s.number.greaterThanOrEqual(5); // >= 5 | ||
s.number.lessThan(5); // < 5 | ||
s.number.lessThanOrEqual(5); // <= 5 | ||
s.number.equal(5); // === 5 | ||
s.number.notEqual(5); // !== 5 | ||
s.number.eq(NaN); // special case: Number.isNaN | ||
s.number.ne(NaN); // special case: !Number.isNaN | ||
s.number.equal(NaN); // special case: Number.isNaN | ||
s.number.notEqual(NaN); // special case: !Number.isNaN | ||
@@ -139,4 +139,4 @@ s.number.int; // value must be an integer | ||
s.number.positive; // .ge(0) | ||
s.number.negative; // .lt(0) | ||
s.number.positive; // .greaterThanOrEqual(0) | ||
s.number.negative; // .lessThan(0) | ||
@@ -164,11 +164,11 @@ s.number.divisibleBy(5); // Divisible by 5 | ||
```typescript | ||
s.bigint.gt(5n); // > 5n | ||
s.bigint.ge(5n); // >= 5n | ||
s.bigint.lt(5n); // < 5n | ||
s.bigint.le(5n); // <= 5n | ||
s.bigint.eq(5n); // === 5n | ||
s.bigint.ne(5n); // !== 5n | ||
s.bigint.greaterThan(5n); // > 5n | ||
s.bigint.greaterThanOrEqual(5n); // >= 5n | ||
s.bigint.lessThan(5n); // < 5n | ||
s.bigint.lessThanOrEqual(5n); // <= 5n | ||
s.bigint.equal(5n); // === 5n | ||
s.bigint.notEqual(5n); // !== 5n | ||
s.bigint.positive; // .ge(0n) | ||
s.bigint.negative; // .lt(0n) | ||
s.bigint.positive; // .greaterThanOrEqual(0n) | ||
s.bigint.negative; // .lessThan(0n) | ||
@@ -195,7 +195,7 @@ s.bigint.divisibleBy(5n); // Divisible by 5n | ||
s.boolean.eq(true); // s.boolean.true | ||
s.boolean.eq(false); // s.boolean.false | ||
s.boolean.equal(true); // s.boolean.true | ||
s.boolean.equal(false); // s.boolean.false | ||
s.boolean.ne(true); // s.boolean.false | ||
s.boolean.ne(false); // s.boolean.true | ||
s.boolean.notEqual(true); // s.boolean.false | ||
s.boolean.notEqual(false); // s.boolean.true | ||
``` | ||
@@ -213,8 +213,8 @@ | ||
```typescript | ||
s.string.array.lengthLt(5); // Must have less than 5 elements | ||
s.string.array.lengthLe(5); // Must have 5 or less elements | ||
s.string.array.lengthGt(5); // Must have more than 5 elements | ||
s.string.array.lengthGe(5); // Must have 5 or more elements | ||
s.string.array.lengthEq(5); // Must have exactly 5 elements | ||
s.string.array.lengthNe(5); // Must not have exactly 5 elements | ||
s.string.array.lengthLessThan(5); // Must have less than 5 elements | ||
s.string.array.lengthLessThanOrEqual(5); // Must have 5 or less elements | ||
s.string.array.lengthGreaterThan(5); // Must have more than 5 elements | ||
s.string.array.lengthGreaterThanOrEqual(5); // Must have 5 or more elements | ||
s.string.array.lengthEqual(5); // Must have exactly 5 elements | ||
s.string.array.lengthNotEqual(5); // Must not have exactly 5 elements | ||
s.string.array.lengthRange(0, 4); // Must have at least 0 elements and less than 4 elements (in math, that is [0, 4)) | ||
@@ -225,3 +225,3 @@ s.string.array.lengthRangeInclusive(0, 4); // Must have at least 0 elements and at most 4 elements (in math, that is [0, 4]) | ||
> **Note**: All `.length` methods define tuple types with the given amount of elements. For example, `s.string.array.lengthGe(2)`'s inferred type is `[string, string, ...string[]]` | ||
> **Note**: All `.length` methods define tuple types with the given amount of elements. For example, `s.string.array.lengthGreaterThanOrEqual(2)`'s inferred type is `[string, string, ...string[]]` | ||
@@ -452,8 +452,8 @@ #### Tuples | ||
```typescript | ||
s.typedArray().lengthLt(5); // Length must be less than 5 | ||
s.typedArray().lengthLe(5); // Length must be 5 or less | ||
s.typedArray().lengthGt(5); // Length must be more than 5 | ||
s.typedArray().lengthGe(5); // Length must be 5 or more | ||
s.typedArray().lengthEq(5); // Length must be exactly 5 | ||
s.typedArray().lengthNe(5); // Length must not be 5 | ||
s.typedArray().lengthLessThan(5); // Length must be less than 5 | ||
s.typedArray().lengthLessThanOrEqual(5); // Length must be 5 or less | ||
s.typedArray().lengthGreaterThan(5); // Length must be more than 5 | ||
s.typedArray().lengthGreaterThanOrEqual(5); // Length must be 5 or more | ||
s.typedArray().lengthEqual(5); // Length must be exactly 5 | ||
s.typedArray().lengthNotEqual(5); // Length must not be 5 | ||
s.typedArray().lengthRange(0, 4); // Length L must satisfy 0 <= L < 4 | ||
@@ -464,3 +464,3 @@ s.typedArray().lengthRangeInclusive(0, 4); // Length L must satisfy 0 <= L <= 4 | ||
Note that all of these methods have analogous methods for working with the typed array's byte length, `s.typedArray().byteLengthX()` - for instance, `s.typedArray().byteLengthLt(5)` is the same as `s.typedArray().lengthLt(5)` but for the array's byte length. | ||
Note that all of these methods have analogous methods for working with the typed array's byte length, `s.typedArray().byteLengthX()` - for instance, `s.typedArray().byteLengthLessThan(5)` is the same as `s.typedArray().lengthLessThan(5)` but for the array's byte length. | ||
@@ -467,0 +467,0 @@ ### BaseValidator: methods and properties |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
748412
6471