@modulify/validator 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -1
- package/README.md +12 -2
- package/dist/assert.cjs +99 -63
- package/dist/assert.d.cts +37 -0
- package/dist/assert.d.mts +37 -0
- package/dist/assert.d.ts +24 -3
- package/dist/assert.mjs +94 -64
- package/dist/assertions.cjs +283 -178
- package/dist/assertions.d.cts +56 -0
- package/dist/assertions.d.mts +56 -0
- package/dist/assertions.d.ts +43 -45
- package/dist/assertions.mjs +274 -201
- package/dist/checkers.cjs +23 -0
- package/dist/checkers.d.cts +8 -0
- package/dist/checkers.d.mts +8 -0
- package/dist/checkers.d.ts +1 -1
- package/dist/checkers.mjs +16 -0
- package/dist/combinators.cjs +305 -304
- package/dist/combinators.d.cts +16 -0
- package/dist/combinators.d.mts +16 -0
- package/dist/combinators.d.ts +15 -16
- package/dist/combinators.mjs +305 -314
- package/dist/constraints.cjs +23 -0
- package/dist/constraints.d.cts +4 -0
- package/dist/constraints.d.mts +4 -0
- package/dist/constraints.d.ts +2 -2
- package/dist/constraints.mjs +21 -0
- package/dist/extractors.cjs +6 -0
- package/dist/extractors.d.cts +2 -0
- package/dist/extractors.d.mts +2 -0
- package/dist/extractors.mjs +5 -0
- package/dist/index.cjs +140 -219
- package/dist/index.d.cts +12 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.mjs +93 -222
- package/dist/json-schema.cjs +364 -489
- package/dist/json-schema.d.cts +14 -0
- package/dist/json-schema.d.mts +14 -0
- package/dist/json-schema.d.ts +3 -3
- package/dist/json-schema.mjs +365 -492
- package/dist/metadata.cjs +98 -7
- package/dist/metadata.d.cts +8 -0
- package/dist/metadata.d.mts +8 -0
- package/dist/metadata.d.ts +2 -2
- package/dist/metadata.mjs +93 -7
- package/dist/predicates.cjs +98 -41
- package/dist/predicates.d.cts +77 -0
- package/dist/predicates.d.mts +77 -0
- package/dist/predicates.d.ts +25 -4
- package/dist/predicates.mjs +92 -66
- package/dist/types/index.d.cts +984 -0
- package/dist/types/index.d.mts +984 -0
- package/dist/types/index.d.ts +984 -0
- package/dist/types/json-schema.d.cts +75 -0
- package/dist/types/json-schema.d.mts +75 -0
- package/dist/types/json-schema.d.ts +75 -0
- package/dist/violations.cjs +81 -0
- package/dist/violations.d.cts +29 -0
- package/dist/violations.d.mts +29 -0
- package/dist/violations.d.ts +1 -1
- package/dist/violations.mjs +80 -0
- package/docs/RELEASING.md +66 -0
- package/docs/en/00-index.md +2 -0
- package/docs/en/01-shape-api.md +35 -10
- package/docs/en/02-metadata-and-introspection.md +2 -1
- package/docs/en/03-violations.md +1 -1
- package/docs/en/04-json-schema-export.md +5 -0
- package/docs/en/05-public-api.md +35 -3
- package/docs/en/06-common-recipes.md +2 -1
- package/docs/en/07-ai-reference.md +5 -2
- package/docs/en/08-violation-code-types.md +28 -2
- package/docs/en/09-migration.md +75 -0
- package/docs/ru/00-index.md +2 -0
- package/docs/ru/01-shape-api.md +35 -10
- package/docs/ru/02-metadata-and-introspection.md +2 -1
- package/docs/ru/03-violations.md +1 -1
- package/docs/ru/04-json-schema-export.md +5 -0
- package/docs/ru/05-public-api.md +35 -3
- package/docs/ru/06-common-recipes.md +2 -1
- package/docs/ru/07-ai-reference.md +5 -2
- package/docs/ru/08-violation-code-types.md +28 -2
- package/docs/ru/09-migration.md +76 -0
- package/docs/ru/README.md +10 -2
- package/package.json +63 -37
- package/types/index.d.ts +275 -115
- package/dist/metadata.cjs.js +0 -130
- package/dist/metadata.es.js +0 -131
package/dist/assertions.d.ts
CHANGED
|
@@ -1,58 +1,56 @@
|
|
|
1
|
-
import { AssertionConstraint,
|
|
2
|
-
import { assert } from './assert';
|
|
3
|
-
export { assert };
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
export declare const isBoolean: Assertion<boolean, [], "type.boolean", undefined, "isBoolean">;
|
|
8
|
-
export declare const isBigInt: Assertion<bigint, [], "type.bigint", undefined, "isBigInt">;
|
|
9
|
-
export declare const isBlob: Assertion<Blob, [], "type.blob", undefined, "isBlob">;
|
|
10
|
-
export declare const isDate: Assertion<Date, [], "type.date", undefined, "isDate">;
|
|
11
|
-
export declare const isDefined: Assertion<{}, [], "value.defined", undefined, "isDefined">;
|
|
12
|
-
export declare const isEmail: Assertion<string, [], "string.email", undefined, "isEmail">;
|
|
13
|
-
export declare const isFile: Assertion<File, [], "type.file", undefined, "isFile">;
|
|
14
|
-
export declare const isFunction: Assertion<(...args: never[]) => unknown, [], "type.function", undefined, "isFunction">;
|
|
15
|
-
export declare const isMap: Assertion<Map<unknown, unknown>, [], "type.map", undefined, "isMap">;
|
|
16
|
-
export declare const isNaN: Assertion<number, [], "number.nan", undefined, "isNaN">;
|
|
17
|
-
export declare const isNull: Assertion<null, [], "type.null", undefined, "isNull">;
|
|
18
|
-
export declare const isNumber: Assertion<number, [], "type.number", undefined, "isNumber">;
|
|
19
|
-
export declare const isSet: Assertion<Set<unknown>, [], "type.set", undefined, "isSet">;
|
|
20
|
-
export declare const isString: Assertion<string, [], "type.string", undefined, "isString">;
|
|
21
|
-
export declare const isSymbol: Assertion<symbol, [], "type.symbol", undefined, "isSymbol">;
|
|
22
|
-
export declare const hasLength: ({ exact, max, min, range, bail, }?: {
|
|
1
|
+
import { AssertionConstraint, Guard, Refinement, Extractor, Checker } from './types/index.js';
|
|
2
|
+
import { assert, refine } from './assert.js';
|
|
3
|
+
export { assert, refine, };
|
|
4
|
+
type Defined = {} | null;
|
|
5
|
+
type EmptyOptions = Record<never, never>;
|
|
6
|
+
type BoundedAssertionOptions = {
|
|
23
7
|
exact?: number | null;
|
|
24
8
|
max?: number | null;
|
|
25
9
|
min?: number | null;
|
|
26
|
-
range?: [number, number] | null;
|
|
27
|
-
bail?: boolean;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
10
|
+
range?: readonly [number, number] | null;
|
|
11
|
+
bail?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type OptionNumber<O, K extends PropertyKey> = K extends keyof O ? Extract<O[K], number> : never;
|
|
14
|
+
type OptionRange<O, K extends PropertyKey> = K extends keyof O ? Extract<O[K], readonly [number, number] | [number, number]> extends infer R ? R extends readonly [infer Min extends number, infer Max extends number] ? readonly [Min, Max] : never : never : never;
|
|
15
|
+
type IncludeConstraint<Value, C extends AssertionConstraint> = [Value] extends [never] ? [] : [C];
|
|
16
|
+
export declare const isBoolean: Guard<boolean, [], "type.boolean", [], "isBoolean">;
|
|
17
|
+
export declare const isBigInt: Guard<bigint, [], "type.bigint", [], "isBigInt">;
|
|
18
|
+
export declare const isBlob: Guard<Blob, [], "type.blob", [], "isBlob">;
|
|
19
|
+
export declare const isDate: Guard<Date, [], "type.date", [], "isDate">;
|
|
20
|
+
export declare const isDefined: Guard<Defined, [], "value.defined", [], "isDefined">;
|
|
21
|
+
export declare const isEmail: Guard<string, [], "string.email", [], "isEmail">;
|
|
22
|
+
export declare const isError: Guard<Error, [], "type.error", [], "isError">;
|
|
23
|
+
export declare const isFiniteNumber: Guard<number, [], "number.finite", [], "isFiniteNumber">;
|
|
24
|
+
export declare const isFile: Guard<File, [], "type.file", [], "isFile">;
|
|
25
|
+
export declare const isFunction: Guard<(...args: never[]) => unknown, [], "type.function", [], "isFunction">;
|
|
26
|
+
export declare const isInteger: Guard<number, [], "number.integer", [], "isInteger">;
|
|
27
|
+
export declare const isMap: Guard<Map<unknown, unknown>, [], "type.map", [], "isMap">;
|
|
28
|
+
export declare const isNaN: Guard<number, [], "number.nan", [], "isNaN">;
|
|
29
|
+
export declare const isNull: Guard<null, [], "type.null", [], "isNull">;
|
|
30
|
+
export declare const isNumber: Guard<number, [], "type.number", [], "isNumber">;
|
|
31
|
+
export declare const isPromiseLike: Guard<PromiseLike<unknown>, [], "type.promise-like", [], "isPromiseLike">;
|
|
32
|
+
export declare const isRegExp: Guard<RegExp, [], "type.regexp", [], "isRegExp">;
|
|
33
|
+
export declare const isSafeInteger: Guard<number, [], "number.safe-integer", [], "isSafeInteger">;
|
|
34
|
+
export declare const isSet: Guard<Set<unknown>, [], "type.set", [], "isSet">;
|
|
35
|
+
export declare const isString: Guard<string, [], "type.string", [], "isString">;
|
|
36
|
+
export declare const isSymbol: Guard<symbol, [], "type.symbol", [], "isSymbol">;
|
|
37
|
+
export declare const isValidDate: Guard<Date, [], "date.valid", [], "isValidDate">;
|
|
38
|
+
export declare const hasLength: <const O extends BoundedAssertionOptions = EmptyOptions>(options?: O) => Refinement<[...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<string | unknown[], number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "length.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<string | unknown[], number>, Checker<number, [max: OptionNumber<O, "max">]>, "length.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<string | unknown[], number>, Checker<number, [min: OptionNumber<O, "min">]>, "length.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<string | unknown[], number>, Checker<number, [range: OptionRange<O, "range">]>, "length.range", range: OptionRange<O, "range">]>] extends infer T ? T extends [...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<string | unknown[], number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "length.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<string | unknown[], number>, Checker<number, [max: OptionNumber<O, "max">]>, "length.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<string | unknown[], number>, Checker<number, [min: OptionNumber<O, "min">]>, "length.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<string | unknown[], number>, Checker<number, [range: OptionRange<O, "range">]>, "length.range", range: OptionRange<O, "range">]>] ? T extends readonly [] ? unknown : (T[number] extends infer T_1 ? T_1 extends T[number] ? T_1 extends unknown ? (value: Parameters<T_1[0]>[0]) => void : never : never : never) extends (value: infer Input) => void ? Input : never : never : never, [...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<string | unknown[], number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "length.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<string | unknown[], number>, Checker<number, [max: OptionNumber<O, "max">]>, "length.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<string | unknown[], number>, Checker<number, [min: OptionNumber<O, "min">]>, "length.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<string | unknown[], number>, Checker<number, [range: OptionRange<O, "range">]>, "length.range", range: OptionRange<O, "range">]>], "length.unsupported-type", [], "hasLength">;
|
|
39
|
+
export declare const hasSize: <const O extends BoundedAssertionOptions = EmptyOptions>(options?: O) => Refinement<[...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "size.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [max: OptionNumber<O, "max">]>, "size.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [min: OptionNumber<O, "min">]>, "size.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [range: OptionRange<O, "range">]>, "size.range", range: OptionRange<O, "range">]>] extends infer T ? T extends [...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "size.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [max: OptionNumber<O, "max">]>, "size.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [min: OptionNumber<O, "min">]>, "size.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [range: OptionRange<O, "range">]>, "size.range", range: OptionRange<O, "range">]>] ? T extends readonly [] ? unknown : (T[number] extends infer T_1 ? T_1 extends T[number] ? T_1 extends unknown ? (value: Parameters<T_1[0]>[0]) => void : never : never : never) extends (value: infer Input) => void ? Input : never : never : never, [...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "size.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [max: OptionNumber<O, "max">]>, "size.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [min: OptionNumber<O, "min">]>, "size.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<Map<unknown, unknown> | Set<unknown>, number>, Checker<number, [range: OptionRange<O, "range">]>, "size.range", range: OptionRange<O, "range">]>], "size.unsupported-type", [], "hasSize">;
|
|
36
40
|
export declare const hasPattern: (pattern: RegExp, { bail, }?: {
|
|
37
41
|
bail?: boolean;
|
|
38
|
-
}) =>
|
|
42
|
+
}) => Refinement<string, readonly [readonly [(value: string) => string, (value: string, pattern: RegExp) => boolean, "string.pattern", RegExp]], "string.unsupported-type", [], "hasPattern">;
|
|
39
43
|
export declare const startsWith: (prefix: string, { bail, }?: {
|
|
40
44
|
bail?: boolean;
|
|
41
|
-
}) =>
|
|
45
|
+
}) => Refinement<string, readonly [readonly [(value: string) => string, (value: string, prefix: string) => boolean, "string.starts-with", string]], "string.unsupported-type", [], "startsWith">;
|
|
42
46
|
export declare const endsWith: (suffix: string, { bail, }?: {
|
|
43
47
|
bail?: boolean;
|
|
44
|
-
}) =>
|
|
45
|
-
export declare const hasValue: (
|
|
46
|
-
|
|
47
|
-
max?: number | null;
|
|
48
|
-
min?: number | null;
|
|
49
|
-
range?: [number, number] | null;
|
|
50
|
-
bail?: boolean;
|
|
51
|
-
}) => Assertion<number, ValueAssertionConstraint[], "number.unsupported-type", undefined, "hasValue">;
|
|
52
|
-
export declare const multipleOf: (step: number, { bail, }?: {
|
|
48
|
+
}) => Refinement<string, readonly [readonly [(value: string) => string, (value: string, suffix: string) => boolean, "string.ends-with", string]], "string.unsupported-type", [], "endsWith">;
|
|
49
|
+
export declare const hasValue: <const O extends BoundedAssertionOptions = EmptyOptions>(options?: O) => Refinement<[...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<number, number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "number.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<number, number>, Checker<number, [max: OptionNumber<O, "max">]>, "number.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<number, number>, Checker<number, [min: OptionNumber<O, "min">]>, "number.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<number, number>, Checker<number, [range: OptionRange<O, "range">]>, "number.range", range: OptionRange<O, "range">]>] extends infer T ? T extends [...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<number, number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "number.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<number, number>, Checker<number, [max: OptionNumber<O, "max">]>, "number.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<number, number>, Checker<number, [min: OptionNumber<O, "min">]>, "number.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<number, number>, Checker<number, [range: OptionRange<O, "range">]>, "number.range", range: OptionRange<O, "range">]>] ? T extends readonly [] ? unknown : (T[number] extends infer T_1 ? T_1 extends T[number] ? T_1 extends unknown ? (value: Parameters<T_1[0]>[0]) => void : never : never : never) extends (value: infer Input) => void ? Input : never : never : never, [...IncludeConstraint<OptionNumber<O, "exact">, readonly [ Extractor<number, number>, Checker<number, [exact: OptionNumber<O, "exact">]>, "number.exact", exact: OptionNumber<O, "exact">]>, ...IncludeConstraint<OptionNumber<O, "max">, readonly [ Extractor<number, number>, Checker<number, [max: OptionNumber<O, "max">]>, "number.max", max: OptionNumber<O, "max">]>, ...IncludeConstraint<OptionNumber<O, "min">, readonly [ Extractor<number, number>, Checker<number, [min: OptionNumber<O, "min">]>, "number.min", min: OptionNumber<O, "min">]>, ...IncludeConstraint<OptionRange<O, "range">, readonly [ Extractor<number, number>, Checker<number, [range: OptionRange<O, "range">]>, "number.range", range: OptionRange<O, "range">]>], "number.unsupported-type", [], "hasValue">;
|
|
50
|
+
export declare const multipleOf: <const Step extends number>(step: Step, { bail, }?: {
|
|
53
51
|
bail?: boolean;
|
|
54
|
-
}) =>
|
|
52
|
+
}) => Refinement<number, readonly [readonly [(value: number) => number, (value: number, step: number) => boolean, "number.multiple-of", Step]], "number.unsupported-type", [], "multipleOf">;
|
|
55
53
|
export declare const oneOf: <Actual = unknown>(values: Actual[] | Record<string, Actual>, { equalTo, bail, }?: {
|
|
56
54
|
equalTo?: (a: Actual, b: unknown) => boolean;
|
|
57
55
|
bail?: boolean;
|
|
58
|
-
}) =>
|
|
56
|
+
}) => Guard<Actual, [], "value.one-of", readonly [Actual[]], "oneOf">;
|
package/dist/assertions.mjs
CHANGED
|
@@ -1,207 +1,280 @@
|
|
|
1
|
-
import { assert } from "./assert.mjs";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { assert, createRefinement, refine } from "./assert.mjs";
|
|
2
|
+
import { endsWith as endsWith$1, inRange, isEqual, isGte, isLte, isMultipleOf, matchesPattern, startsWith as startsWith$1 } from "./checkers.mjs";
|
|
3
|
+
import { length, size } from "./extractors.mjs";
|
|
4
|
+
import { isArray, isBigInt as isBigInt$1, isBlob as isBlob$1, isBoolean as isBoolean$1, isDate as isDate$1, isEmail as isEmail$1, isError as isError$1, isFile as isFile$1, isFiniteNumber as isFiniteNumber$1, isFunction as isFunction$1, isInteger as isInteger$1, isMap as isMap$1, isNaN as isNaN$1, isNull as isNull$1, isNumber as isNumber$1, isPromiseLike as isPromiseLike$1, isRegExp as isRegExp$1, isSafeInteger as isSafeInteger$1, isSet as isSet$1, isString as isString$1, isSymbol as isSymbol$1, isValidDate as isValidDate$1 } from "./predicates.mjs";
|
|
5
|
+
//#region src/assertions.ts
|
|
6
|
+
var buildLengthConstraints = (options) => {
|
|
7
|
+
const { exact = null, max = null, min = null, range = null } = options;
|
|
8
|
+
const constraints = [];
|
|
9
|
+
if (exact !== null) constraints.push([
|
|
10
|
+
length,
|
|
11
|
+
isEqual,
|
|
12
|
+
"length.exact",
|
|
13
|
+
exact
|
|
14
|
+
]);
|
|
15
|
+
if (max !== null) constraints.push([
|
|
16
|
+
length,
|
|
17
|
+
isLte,
|
|
18
|
+
"length.max",
|
|
19
|
+
max
|
|
20
|
+
]);
|
|
21
|
+
if (min !== null) constraints.push([
|
|
22
|
+
length,
|
|
23
|
+
isGte,
|
|
24
|
+
"length.min",
|
|
25
|
+
min
|
|
26
|
+
]);
|
|
27
|
+
if (range !== null) constraints.push([
|
|
28
|
+
length,
|
|
29
|
+
inRange,
|
|
30
|
+
"length.range",
|
|
31
|
+
range
|
|
32
|
+
]);
|
|
33
|
+
return constraints;
|
|
18
34
|
};
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const constraints = [];
|
|
48
|
-
if (exact !== null) constraints.push([length, isEqual, "length.exact", exact]);
|
|
49
|
-
if (max !== null) constraints.push([length, isLte, "length.max", max]);
|
|
50
|
-
if (min !== null) constraints.push([length, isGte, "length.min", min]);
|
|
51
|
-
if (range !== null) constraints.push([length, inRange, "length.range", range]);
|
|
52
|
-
return assert(
|
|
53
|
-
(value) => isArray(value) || isString$1(value),
|
|
54
|
-
{
|
|
55
|
-
name: "hasLength",
|
|
56
|
-
bail,
|
|
57
|
-
code: "length.unsupported-type"
|
|
58
|
-
},
|
|
59
|
-
constraints
|
|
60
|
-
);
|
|
35
|
+
var buildSizeConstraints = (options) => {
|
|
36
|
+
const { exact = null, max = null, min = null, range = null } = options;
|
|
37
|
+
const constraints = [];
|
|
38
|
+
if (exact !== null) constraints.push([
|
|
39
|
+
size,
|
|
40
|
+
isEqual,
|
|
41
|
+
"size.exact",
|
|
42
|
+
exact
|
|
43
|
+
]);
|
|
44
|
+
if (max !== null) constraints.push([
|
|
45
|
+
size,
|
|
46
|
+
isLte,
|
|
47
|
+
"size.max",
|
|
48
|
+
max
|
|
49
|
+
]);
|
|
50
|
+
if (min !== null) constraints.push([
|
|
51
|
+
size,
|
|
52
|
+
isGte,
|
|
53
|
+
"size.min",
|
|
54
|
+
min
|
|
55
|
+
]);
|
|
56
|
+
if (range !== null) constraints.push([
|
|
57
|
+
size,
|
|
58
|
+
inRange,
|
|
59
|
+
"size.range",
|
|
60
|
+
range
|
|
61
|
+
]);
|
|
62
|
+
return constraints;
|
|
61
63
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
64
|
+
var buildValueConstraints = (options) => {
|
|
65
|
+
const { exact = null, max = null, min = null, range = null } = options;
|
|
66
|
+
const constraints = [];
|
|
67
|
+
if (exact !== null) constraints.push([
|
|
68
|
+
(value) => value,
|
|
69
|
+
isEqual,
|
|
70
|
+
"number.exact",
|
|
71
|
+
exact
|
|
72
|
+
]);
|
|
73
|
+
if (max !== null) constraints.push([
|
|
74
|
+
(value) => value,
|
|
75
|
+
isLte,
|
|
76
|
+
"number.max",
|
|
77
|
+
max
|
|
78
|
+
]);
|
|
79
|
+
if (min !== null) constraints.push([
|
|
80
|
+
(value) => value,
|
|
81
|
+
isGte,
|
|
82
|
+
"number.min",
|
|
83
|
+
min
|
|
84
|
+
]);
|
|
85
|
+
if (range !== null) constraints.push([
|
|
86
|
+
(value) => value,
|
|
87
|
+
inRange,
|
|
88
|
+
"number.range",
|
|
89
|
+
range
|
|
90
|
+
]);
|
|
91
|
+
return constraints;
|
|
83
92
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
93
|
+
var isBoolean = /* @__PURE__ */ assert(isBoolean$1, {
|
|
94
|
+
name: "isBoolean",
|
|
95
|
+
bail: true,
|
|
96
|
+
code: "type.boolean"
|
|
97
|
+
});
|
|
98
|
+
var isBigInt = /* @__PURE__ */ assert(isBigInt$1, {
|
|
99
|
+
name: "isBigInt",
|
|
100
|
+
bail: true,
|
|
101
|
+
code: "type.bigint"
|
|
102
|
+
});
|
|
103
|
+
var isBlob = /* @__PURE__ */ assert(isBlob$1, {
|
|
104
|
+
name: "isBlob",
|
|
105
|
+
bail: true,
|
|
106
|
+
code: "type.blob"
|
|
107
|
+
});
|
|
108
|
+
var isDate = /* @__PURE__ */ assert(isDate$1, {
|
|
109
|
+
name: "isDate",
|
|
110
|
+
bail: true,
|
|
111
|
+
code: "type.date"
|
|
112
|
+
});
|
|
113
|
+
var isDefined = /* @__PURE__ */ assert((value) => value !== void 0, {
|
|
114
|
+
name: "isDefined",
|
|
115
|
+
bail: true,
|
|
116
|
+
code: "value.defined"
|
|
117
|
+
});
|
|
118
|
+
var isEmail = /* @__PURE__ */ assert(isEmail$1, {
|
|
119
|
+
name: "isEmail",
|
|
120
|
+
bail: true,
|
|
121
|
+
code: "string.email"
|
|
122
|
+
});
|
|
123
|
+
var isError = /* @__PURE__ */ assert(isError$1, {
|
|
124
|
+
name: "isError",
|
|
125
|
+
bail: true,
|
|
126
|
+
code: "type.error"
|
|
127
|
+
});
|
|
128
|
+
var isFiniteNumber = /* @__PURE__ */ assert(isFiniteNumber$1, {
|
|
129
|
+
name: "isFiniteNumber",
|
|
130
|
+
bail: true,
|
|
131
|
+
code: "number.finite"
|
|
132
|
+
});
|
|
133
|
+
var isFile = /* @__PURE__ */ assert(isFile$1, {
|
|
134
|
+
name: "isFile",
|
|
135
|
+
bail: true,
|
|
136
|
+
code: "type.file"
|
|
137
|
+
});
|
|
138
|
+
var isFunction = /* @__PURE__ */ assert(isFunction$1, {
|
|
139
|
+
name: "isFunction",
|
|
140
|
+
bail: true,
|
|
141
|
+
code: "type.function"
|
|
142
|
+
});
|
|
143
|
+
var isInteger = /* @__PURE__ */ assert(isInteger$1, {
|
|
144
|
+
name: "isInteger",
|
|
145
|
+
bail: true,
|
|
146
|
+
code: "number.integer"
|
|
147
|
+
});
|
|
148
|
+
var isMap = /* @__PURE__ */ assert(isMap$1, {
|
|
149
|
+
name: "isMap",
|
|
150
|
+
bail: true,
|
|
151
|
+
code: "type.map"
|
|
152
|
+
});
|
|
153
|
+
var isNaN = /* @__PURE__ */ assert(isNaN$1, {
|
|
154
|
+
name: "isNaN",
|
|
155
|
+
bail: true,
|
|
156
|
+
code: "number.nan"
|
|
157
|
+
});
|
|
158
|
+
var isNull = /* @__PURE__ */ assert(isNull$1, {
|
|
159
|
+
name: "isNull",
|
|
160
|
+
bail: true,
|
|
161
|
+
code: "type.null"
|
|
162
|
+
});
|
|
163
|
+
var isNumber = /* @__PURE__ */ assert(isNumber$1, {
|
|
164
|
+
name: "isNumber",
|
|
165
|
+
bail: true,
|
|
166
|
+
code: "type.number"
|
|
167
|
+
});
|
|
168
|
+
var isPromiseLike = /* @__PURE__ */ assert(isPromiseLike$1, {
|
|
169
|
+
name: "isPromiseLike",
|
|
170
|
+
bail: true,
|
|
171
|
+
code: "type.promise-like"
|
|
172
|
+
});
|
|
173
|
+
var isRegExp = /* @__PURE__ */ assert(isRegExp$1, {
|
|
174
|
+
name: "isRegExp",
|
|
175
|
+
bail: true,
|
|
176
|
+
code: "type.regexp"
|
|
177
|
+
});
|
|
178
|
+
var isSafeInteger = /* @__PURE__ */ assert(isSafeInteger$1, {
|
|
179
|
+
name: "isSafeInteger",
|
|
180
|
+
bail: true,
|
|
181
|
+
code: "number.safe-integer"
|
|
182
|
+
});
|
|
183
|
+
var isSet = /* @__PURE__ */ assert(isSet$1, {
|
|
184
|
+
name: "isSet",
|
|
185
|
+
bail: true,
|
|
186
|
+
code: "type.set"
|
|
187
|
+
});
|
|
188
|
+
var isString = /* @__PURE__ */ assert(isString$1, {
|
|
189
|
+
name: "isString",
|
|
190
|
+
bail: true,
|
|
191
|
+
code: "type.string"
|
|
192
|
+
});
|
|
193
|
+
var isSymbol = /* @__PURE__ */ assert(isSymbol$1, {
|
|
194
|
+
name: "isSymbol",
|
|
195
|
+
bail: true,
|
|
196
|
+
code: "type.symbol"
|
|
197
|
+
});
|
|
198
|
+
var isValidDate = /* @__PURE__ */ assert(isValidDate$1, {
|
|
199
|
+
name: "isValidDate",
|
|
200
|
+
bail: true,
|
|
201
|
+
code: "date.valid"
|
|
202
|
+
});
|
|
203
|
+
var hasLength = (options = {}) => {
|
|
204
|
+
const { bail = false } = options;
|
|
205
|
+
const constraints = buildLengthConstraints(options);
|
|
206
|
+
return /* @__PURE__ */ createRefinement({
|
|
207
|
+
name: "hasLength",
|
|
208
|
+
bail,
|
|
209
|
+
code: "length.unsupported-type"
|
|
210
|
+
}, constraints);
|
|
211
|
+
};
|
|
212
|
+
var hasSize = (options = {}) => {
|
|
213
|
+
const { bail = false } = options;
|
|
214
|
+
const constraints = buildSizeConstraints(options);
|
|
215
|
+
return /* @__PURE__ */ createRefinement({
|
|
216
|
+
name: "hasSize",
|
|
217
|
+
bail,
|
|
218
|
+
code: "size.unsupported-type"
|
|
219
|
+
}, constraints);
|
|
153
220
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
221
|
+
var hasPattern = (pattern, { bail = false } = {}) => /* @__PURE__ */ createRefinement({
|
|
222
|
+
name: "hasPattern",
|
|
223
|
+
bail,
|
|
224
|
+
code: "string.unsupported-type"
|
|
225
|
+
}, [[
|
|
226
|
+
(value) => value,
|
|
227
|
+
matchesPattern,
|
|
228
|
+
"string.pattern",
|
|
229
|
+
pattern
|
|
230
|
+
]]);
|
|
231
|
+
var startsWith = (prefix, { bail = false } = {}) => /* @__PURE__ */ createRefinement({
|
|
232
|
+
name: "startsWith",
|
|
233
|
+
bail,
|
|
234
|
+
code: "string.unsupported-type"
|
|
235
|
+
}, [[
|
|
236
|
+
(value) => value,
|
|
237
|
+
startsWith$1,
|
|
238
|
+
"string.starts-with",
|
|
239
|
+
prefix
|
|
240
|
+
]]);
|
|
241
|
+
var endsWith = (suffix, { bail = false } = {}) => /* @__PURE__ */ createRefinement({
|
|
242
|
+
name: "endsWith",
|
|
243
|
+
bail,
|
|
244
|
+
code: "string.unsupported-type"
|
|
245
|
+
}, [[
|
|
246
|
+
(value) => value,
|
|
247
|
+
endsWith$1,
|
|
248
|
+
"string.ends-with",
|
|
249
|
+
suffix
|
|
250
|
+
]]);
|
|
251
|
+
var hasValue = (options = {}) => {
|
|
252
|
+
const { bail = false } = options;
|
|
253
|
+
const constraints = buildValueConstraints(options);
|
|
254
|
+
return /* @__PURE__ */ createRefinement({
|
|
255
|
+
name: "hasValue",
|
|
256
|
+
bail,
|
|
257
|
+
code: "number.unsupported-type"
|
|
258
|
+
}, constraints);
|
|
181
259
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
isNumber,
|
|
201
|
-
isSet,
|
|
202
|
-
isString,
|
|
203
|
-
isSymbol,
|
|
204
|
-
multipleOf,
|
|
205
|
-
oneOf,
|
|
206
|
-
startsWith
|
|
260
|
+
var multipleOf = (step, { bail = false } = {}) => /* @__PURE__ */ createRefinement({
|
|
261
|
+
name: "multipleOf",
|
|
262
|
+
bail,
|
|
263
|
+
code: "number.unsupported-type"
|
|
264
|
+
}, [[
|
|
265
|
+
(value) => value,
|
|
266
|
+
isMultipleOf,
|
|
267
|
+
"number.multiple-of",
|
|
268
|
+
step
|
|
269
|
+
]]);
|
|
270
|
+
var oneOf = (values, { equalTo = (a, b) => a === b, bail = false } = {}) => {
|
|
271
|
+
const haystack = isArray(values) ? values : Object.values(values);
|
|
272
|
+
return /* @__PURE__ */ assert((value) => haystack.some((item) => equalTo(item, value)), {
|
|
273
|
+
name: "oneOf",
|
|
274
|
+
bail,
|
|
275
|
+
code: "value.one-of",
|
|
276
|
+
args: [haystack]
|
|
277
|
+
});
|
|
207
278
|
};
|
|
279
|
+
//#endregion
|
|
280
|
+
export { assert, endsWith, hasLength, hasPattern, hasSize, hasValue, isBigInt, isBlob, isBoolean, isDate, isDefined, isEmail, isError, isFile, isFiniteNumber, isFunction, isInteger, isMap, isNaN, isNull, isNumber, isPromiseLike, isRegExp, isSafeInteger, isSet, isString, isSymbol, isValidDate, multipleOf, oneOf, refine, startsWith };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/checkers.ts
|
|
2
|
+
var isEqual = (value, exact) => value === exact;
|
|
3
|
+
var isGte = (value, min) => value >= min;
|
|
4
|
+
var isLte = (value, max) => value <= max;
|
|
5
|
+
var inRange = (value, [min, max]) => value >= min && value <= max;
|
|
6
|
+
var startsWith = (value, prefix) => value.startsWith(prefix);
|
|
7
|
+
var endsWith = (value, suffix) => value.endsWith(suffix);
|
|
8
|
+
var matchesPattern = (value, pattern) => new RegExp(pattern.source, pattern.flags).test(value);
|
|
9
|
+
var isMultipleOf = (value, step) => {
|
|
10
|
+
if (step === 0) return false;
|
|
11
|
+
const quotient = value / step;
|
|
12
|
+
const delta = Math.abs(quotient - Math.round(quotient));
|
|
13
|
+
return Number.isFinite(quotient) && delta <= Number.EPSILON * Math.max(1, Math.abs(quotient)) * 16;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.endsWith = endsWith;
|
|
17
|
+
exports.inRange = inRange;
|
|
18
|
+
exports.isEqual = isEqual;
|
|
19
|
+
exports.isGte = isGte;
|
|
20
|
+
exports.isLte = isLte;
|
|
21
|
+
exports.isMultipleOf = isMultipleOf;
|
|
22
|
+
exports.matchesPattern = matchesPattern;
|
|
23
|
+
exports.startsWith = startsWith;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const isEqual: (value: number, exact: number) => boolean;
|
|
2
|
+
export declare const isGte: (value: number, min: number) => boolean;
|
|
3
|
+
export declare const isLte: (value: number, max: number) => boolean;
|
|
4
|
+
export declare const inRange: (value: number, [min, max]: readonly [number, number]) => boolean;
|
|
5
|
+
export declare const startsWith: (value: string, prefix: string) => boolean;
|
|
6
|
+
export declare const endsWith: (value: string, suffix: string) => boolean;
|
|
7
|
+
export declare const matchesPattern: (value: string, pattern: RegExp) => boolean;
|
|
8
|
+
export declare const isMultipleOf: (value: number, step: number) => boolean;
|