@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.
Files changed (88) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/README.md +12 -2
  3. package/dist/assert.cjs +99 -63
  4. package/dist/assert.d.cts +37 -0
  5. package/dist/assert.d.mts +37 -0
  6. package/dist/assert.d.ts +24 -3
  7. package/dist/assert.mjs +94 -64
  8. package/dist/assertions.cjs +283 -178
  9. package/dist/assertions.d.cts +56 -0
  10. package/dist/assertions.d.mts +56 -0
  11. package/dist/assertions.d.ts +43 -45
  12. package/dist/assertions.mjs +274 -201
  13. package/dist/checkers.cjs +23 -0
  14. package/dist/checkers.d.cts +8 -0
  15. package/dist/checkers.d.mts +8 -0
  16. package/dist/checkers.d.ts +1 -1
  17. package/dist/checkers.mjs +16 -0
  18. package/dist/combinators.cjs +305 -304
  19. package/dist/combinators.d.cts +16 -0
  20. package/dist/combinators.d.mts +16 -0
  21. package/dist/combinators.d.ts +15 -16
  22. package/dist/combinators.mjs +305 -314
  23. package/dist/constraints.cjs +23 -0
  24. package/dist/constraints.d.cts +4 -0
  25. package/dist/constraints.d.mts +4 -0
  26. package/dist/constraints.d.ts +2 -2
  27. package/dist/constraints.mjs +21 -0
  28. package/dist/extractors.cjs +6 -0
  29. package/dist/extractors.d.cts +2 -0
  30. package/dist/extractors.d.mts +2 -0
  31. package/dist/extractors.mjs +5 -0
  32. package/dist/index.cjs +140 -219
  33. package/dist/index.d.cts +12 -0
  34. package/dist/index.d.mts +12 -0
  35. package/dist/index.d.ts +9 -9
  36. package/dist/index.mjs +93 -222
  37. package/dist/json-schema.cjs +364 -489
  38. package/dist/json-schema.d.cts +14 -0
  39. package/dist/json-schema.d.mts +14 -0
  40. package/dist/json-schema.d.ts +3 -3
  41. package/dist/json-schema.mjs +365 -492
  42. package/dist/metadata.cjs +98 -7
  43. package/dist/metadata.d.cts +8 -0
  44. package/dist/metadata.d.mts +8 -0
  45. package/dist/metadata.d.ts +2 -2
  46. package/dist/metadata.mjs +93 -7
  47. package/dist/predicates.cjs +98 -41
  48. package/dist/predicates.d.cts +77 -0
  49. package/dist/predicates.d.mts +77 -0
  50. package/dist/predicates.d.ts +25 -4
  51. package/dist/predicates.mjs +92 -66
  52. package/dist/types/index.d.cts +984 -0
  53. package/dist/types/index.d.mts +984 -0
  54. package/dist/types/index.d.ts +984 -0
  55. package/dist/types/json-schema.d.cts +75 -0
  56. package/dist/types/json-schema.d.mts +75 -0
  57. package/dist/types/json-schema.d.ts +75 -0
  58. package/dist/violations.cjs +81 -0
  59. package/dist/violations.d.cts +29 -0
  60. package/dist/violations.d.mts +29 -0
  61. package/dist/violations.d.ts +1 -1
  62. package/dist/violations.mjs +80 -0
  63. package/docs/RELEASING.md +66 -0
  64. package/docs/en/00-index.md +2 -0
  65. package/docs/en/01-shape-api.md +35 -10
  66. package/docs/en/02-metadata-and-introspection.md +2 -1
  67. package/docs/en/03-violations.md +1 -1
  68. package/docs/en/04-json-schema-export.md +5 -0
  69. package/docs/en/05-public-api.md +35 -3
  70. package/docs/en/06-common-recipes.md +2 -1
  71. package/docs/en/07-ai-reference.md +5 -2
  72. package/docs/en/08-violation-code-types.md +28 -2
  73. package/docs/en/09-migration.md +75 -0
  74. package/docs/ru/00-index.md +2 -0
  75. package/docs/ru/01-shape-api.md +35 -10
  76. package/docs/ru/02-metadata-and-introspection.md +2 -1
  77. package/docs/ru/03-violations.md +1 -1
  78. package/docs/ru/04-json-schema-export.md +5 -0
  79. package/docs/ru/05-public-api.md +35 -3
  80. package/docs/ru/06-common-recipes.md +2 -1
  81. package/docs/ru/07-ai-reference.md +5 -2
  82. package/docs/ru/08-violation-code-types.md +28 -2
  83. package/docs/ru/09-migration.md +76 -0
  84. package/docs/ru/README.md +10 -2
  85. package/package.json +63 -37
  86. package/types/index.d.ts +275 -115
  87. package/dist/metadata.cjs.js +0 -130
  88. package/dist/metadata.es.js +0 -131
package/dist/metadata.cjs CHANGED
@@ -1,8 +1,99 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const metadata = require("./metadata.cjs.js");
4
- exports.attachConstraintDescriptor = metadata.attachConstraintDescriptor;
5
- exports.custom = metadata.custom;
6
- exports.describe = metadata.describe;
7
- exports.describeConstraints = metadata.describeConstraints;
8
- exports.meta = metadata.meta;
2
+ const require_constraints = require("./constraints.cjs");
3
+ //#region src/metadata.ts
4
+ var constraintDescriptorSymbol = Symbol("modulify.validator.descriptor");
5
+ var constraintMetadataSymbol = Symbol("modulify.validator.metadata");
6
+ var cloneCallableConstraint = (constraint) => {
7
+ const source = constraint;
8
+ const cloned = ((value) => source(value));
9
+ const { length: _length, name: _name, prototype: _prototype, ...descriptors } = Object.getOwnPropertyDescriptors(source);
10
+ Object.defineProperties(cloned, descriptors);
11
+ try {
12
+ Object.defineProperty(cloned, "name", {
13
+ configurable: true,
14
+ value: source.name
15
+ });
16
+ } catch {}
17
+ Object.setPrototypeOf(cloned, Object.getPrototypeOf(source));
18
+ return cloned;
19
+ };
20
+ var cloneConstraint = (constraint) => {
21
+ if (typeof constraint === "function") return cloneCallableConstraint(constraint);
22
+ return Object.create(Object.getPrototypeOf(constraint), Object.getOwnPropertyDescriptors(constraint));
23
+ };
24
+ var freezeMetadata = (metadata) => Object.freeze({ ...metadata });
25
+ var getConstraintMetadata = (constraint) => {
26
+ return constraint[constraintMetadataSymbol];
27
+ };
28
+ var getDescriptorFactory = (constraint) => {
29
+ return constraint[constraintDescriptorSymbol];
30
+ };
31
+ var getPublicDescriptor = (constraint) => {
32
+ if (!require_constraints.isValidator(constraint)) return;
33
+ const { describe } = constraint;
34
+ return typeof describe === "function" ? describe.call(constraint) : void 0;
35
+ };
36
+ var inferAssertionDescriptor = (assertion) => ({
37
+ kind: "assertion",
38
+ name: assertion.name,
39
+ bail: assertion.bail,
40
+ code: assertion.name,
41
+ args: [],
42
+ constraints: assertion.constraints.map(([, , code, ...args]) => ({
43
+ code,
44
+ args
45
+ }))
46
+ });
47
+ var withMetadata = (descriptor, metadata) => {
48
+ if (!metadata) return descriptor;
49
+ return {
50
+ ...descriptor,
51
+ metadata
52
+ };
53
+ };
54
+ var attachConstraintDescriptor = (constraint, describe) => {
55
+ Object.defineProperty(constraint, constraintDescriptorSymbol, {
56
+ configurable: false,
57
+ enumerable: false,
58
+ value: describe,
59
+ writable: false
60
+ });
61
+ return constraint;
62
+ };
63
+ var meta = (constraint, metadata) => {
64
+ const cloned = cloneConstraint(constraint);
65
+ const nextMetadata = freezeMetadata({
66
+ ...getConstraintMetadata(constraint) ?? {},
67
+ ...metadata
68
+ });
69
+ Object.defineProperty(cloned, constraintMetadataSymbol, {
70
+ configurable: true,
71
+ enumerable: false,
72
+ value: nextMetadata,
73
+ writable: false
74
+ });
75
+ return cloned;
76
+ };
77
+ var custom = (validator) => validator;
78
+ var describeConstraints = (constraints) => {
79
+ const values = require_constraints.arrayify(constraints);
80
+ return values.length === 1 ? describe(values[0]) : {
81
+ kind: "allOf",
82
+ constraints: values.map((value) => describe(value))
83
+ };
84
+ };
85
+ var describe = (constraint) => {
86
+ const factory = getDescriptorFactory(constraint);
87
+ const metadata = getConstraintMetadata(constraint);
88
+ if (factory) return withMetadata(factory(), metadata);
89
+ const publicDescriptor = getPublicDescriptor(constraint);
90
+ if (publicDescriptor) return withMetadata(publicDescriptor, metadata);
91
+ if (require_constraints.isValidator(constraint)) return withMetadata({ kind: "validator" }, metadata);
92
+ return withMetadata(inferAssertionDescriptor(constraint), metadata);
93
+ };
94
+ //#endregion
95
+ exports.attachConstraintDescriptor = attachConstraintDescriptor;
96
+ exports.custom = custom;
97
+ exports.describe = describe;
98
+ exports.describeConstraints = describeConstraints;
99
+ exports.meta = meta;
@@ -0,0 +1,8 @@
1
+ import { Constraint, ConstraintDescriptor, ConstraintMetadata, DescribeConstraint, DescribeConstraints, MaybeMany, Validator } from './types/index.cjs';
2
+ type DescriptorFactory = () => ConstraintDescriptor;
3
+ export declare const attachConstraintDescriptor: <C extends Constraint>(constraint: C, describe: DescriptorFactory) => C;
4
+ export declare const meta: <const C extends Constraint, const M extends ConstraintMetadata>(constraint: C, metadata: M) => C;
5
+ export declare const custom: <const V extends Validator>(validator: V) => V;
6
+ export declare const describeConstraints: <const C extends MaybeMany<Constraint>>(constraints: C) => DescribeConstraints<C>;
7
+ export declare const describe: <const C extends Constraint>(constraint: C) => DescribeConstraint<C>;
8
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Constraint, ConstraintDescriptor, ConstraintMetadata, DescribeConstraint, DescribeConstraints, MaybeMany, Validator } from './types/index.mjs';
2
+ type DescriptorFactory = () => ConstraintDescriptor;
3
+ export declare const attachConstraintDescriptor: <C extends Constraint>(constraint: C, describe: DescriptorFactory) => C;
4
+ export declare const meta: <const C extends Constraint, const M extends ConstraintMetadata>(constraint: C, metadata: M) => C;
5
+ export declare const custom: <const V extends Validator>(validator: V) => V;
6
+ export declare const describeConstraints: <const C extends MaybeMany<Constraint>>(constraints: C) => DescribeConstraints<C>;
7
+ export declare const describe: <const C extends Constraint>(constraint: C) => DescribeConstraint<C>;
8
+ export {};
@@ -1,8 +1,8 @@
1
- import { Constraint, ConstraintDescriptor, ConstraintMetadata, DescribeConstraint, DescribeMaybeMany, MaybeMany, Validator } from '../types';
1
+ import { Constraint, ConstraintDescriptor, ConstraintMetadata, DescribeConstraint, DescribeConstraints, MaybeMany, Validator } from './types/index.js';
2
2
  type DescriptorFactory = () => ConstraintDescriptor;
3
3
  export declare const attachConstraintDescriptor: <C extends Constraint>(constraint: C, describe: DescriptorFactory) => C;
4
4
  export declare const meta: <const C extends Constraint, const M extends ConstraintMetadata>(constraint: C, metadata: M) => C;
5
5
  export declare const custom: <const V extends Validator>(validator: V) => V;
6
- export declare const describeConstraints: <const C extends MaybeMany<Constraint>>(constraints: C) => DescribeMaybeMany<C>;
6
+ export declare const describeConstraints: <const C extends MaybeMany<Constraint>>(constraints: C) => DescribeConstraints<C>;
7
7
  export declare const describe: <const C extends Constraint>(constraint: C) => DescribeConstraint<C>;
8
8
  export {};
package/dist/metadata.mjs CHANGED
@@ -1,8 +1,94 @@
1
- import { e, c, b, d, m } from "./metadata.es.js";
2
- export {
3
- e as attachConstraintDescriptor,
4
- c as custom,
5
- b as describe,
6
- d as describeConstraints,
7
- m as meta
1
+ import { arrayify, isValidator } from "./constraints.mjs";
2
+ //#region src/metadata.ts
3
+ var constraintDescriptorSymbol = Symbol("modulify.validator.descriptor");
4
+ var constraintMetadataSymbol = Symbol("modulify.validator.metadata");
5
+ var cloneCallableConstraint = (constraint) => {
6
+ const source = constraint;
7
+ const cloned = ((value) => source(value));
8
+ const { length: _length, name: _name, prototype: _prototype, ...descriptors } = Object.getOwnPropertyDescriptors(source);
9
+ Object.defineProperties(cloned, descriptors);
10
+ try {
11
+ Object.defineProperty(cloned, "name", {
12
+ configurable: true,
13
+ value: source.name
14
+ });
15
+ } catch {}
16
+ Object.setPrototypeOf(cloned, Object.getPrototypeOf(source));
17
+ return cloned;
8
18
  };
19
+ var cloneConstraint = (constraint) => {
20
+ if (typeof constraint === "function") return cloneCallableConstraint(constraint);
21
+ return Object.create(Object.getPrototypeOf(constraint), Object.getOwnPropertyDescriptors(constraint));
22
+ };
23
+ var freezeMetadata = (metadata) => Object.freeze({ ...metadata });
24
+ var getConstraintMetadata = (constraint) => {
25
+ return constraint[constraintMetadataSymbol];
26
+ };
27
+ var getDescriptorFactory = (constraint) => {
28
+ return constraint[constraintDescriptorSymbol];
29
+ };
30
+ var getPublicDescriptor = (constraint) => {
31
+ if (!isValidator(constraint)) return;
32
+ const { describe } = constraint;
33
+ return typeof describe === "function" ? describe.call(constraint) : void 0;
34
+ };
35
+ var inferAssertionDescriptor = (assertion) => ({
36
+ kind: "assertion",
37
+ name: assertion.name,
38
+ bail: assertion.bail,
39
+ code: assertion.name,
40
+ args: [],
41
+ constraints: assertion.constraints.map(([, , code, ...args]) => ({
42
+ code,
43
+ args
44
+ }))
45
+ });
46
+ var withMetadata = (descriptor, metadata) => {
47
+ if (!metadata) return descriptor;
48
+ return {
49
+ ...descriptor,
50
+ metadata
51
+ };
52
+ };
53
+ var attachConstraintDescriptor = (constraint, describe) => {
54
+ Object.defineProperty(constraint, constraintDescriptorSymbol, {
55
+ configurable: false,
56
+ enumerable: false,
57
+ value: describe,
58
+ writable: false
59
+ });
60
+ return constraint;
61
+ };
62
+ var meta = (constraint, metadata) => {
63
+ const cloned = cloneConstraint(constraint);
64
+ const nextMetadata = freezeMetadata({
65
+ ...getConstraintMetadata(constraint) ?? {},
66
+ ...metadata
67
+ });
68
+ Object.defineProperty(cloned, constraintMetadataSymbol, {
69
+ configurable: true,
70
+ enumerable: false,
71
+ value: nextMetadata,
72
+ writable: false
73
+ });
74
+ return cloned;
75
+ };
76
+ var custom = (validator) => validator;
77
+ var describeConstraints = (constraints) => {
78
+ const values = arrayify(constraints);
79
+ return values.length === 1 ? describe(values[0]) : {
80
+ kind: "allOf",
81
+ constraints: values.map((value) => describe(value))
82
+ };
83
+ };
84
+ var describe = (constraint) => {
85
+ const factory = getDescriptorFactory(constraint);
86
+ const metadata = getConstraintMetadata(constraint);
87
+ if (factory) return withMetadata(factory(), metadata);
88
+ const publicDescriptor = getPublicDescriptor(constraint);
89
+ if (publicDescriptor) return withMetadata(publicDescriptor, metadata);
90
+ if (isValidator(constraint)) return withMetadata({ kind: "validator" }, metadata);
91
+ return withMetadata(inferAssertionDescriptor(constraint), metadata);
92
+ };
93
+ //#endregion
94
+ export { attachConstraintDescriptor, custom, describe, describeConstraints, meta };
@@ -1,95 +1,145 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/predicates.ts
3
+ /** Checks if a value has a property */
3
4
  function hasProperty(key) {
4
- return (value) => {
5
- return isObject(value) && !isNull(value) && Object.prototype.hasOwnProperty.call(value, key);
6
- };
5
+ return (value) => {
6
+ return isObject(value) && !isNull(value) && Object.prototype.hasOwnProperty.call(value, key);
7
+ };
7
8
  }
9
+ /** Checks if a value is an array */
8
10
  function isArray(value) {
9
- return Array.isArray(value);
11
+ return Array.isArray(value);
10
12
  }
13
+ /** Checks if a value is a boolean */
11
14
  function isBoolean(value) {
12
- return typeof value === "boolean";
15
+ return typeof value === "boolean";
13
16
  }
17
+ /** Checks if a value is a bigint */
14
18
  function isBigInt(value) {
15
- return typeof value === "bigint";
19
+ return typeof value === "bigint";
16
20
  }
21
+ /** Checks if a value is a Blob */
17
22
  function isBlob(value) {
18
- return typeof Blob !== "undefined" && value instanceof Blob;
23
+ return typeof Blob !== "undefined" && value instanceof Blob;
19
24
  }
25
+ /** Checks if value is Date */
20
26
  function isDate(value) {
21
- return value instanceof Date;
27
+ return value instanceof Date;
22
28
  }
29
+ /** Checks if value is a valid Date */
30
+ function isValidDate(value) {
31
+ return isDate(value) && !Number.isNaN(value.getTime());
32
+ }
33
+ /** Checks if a value is an email */
23
34
  function isEmail(value) {
24
- const pattern = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i;
25
- return isString(value) && pattern.test(value);
35
+ return isString(value) && /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/i.test(value);
26
36
  }
37
+ /** Creates a predicate that checks if a value is equal to specified */
27
38
  function isExact(exact) {
28
- return (value) => value === exact;
39
+ return (value) => value === exact;
29
40
  }
41
+ /** Checks if a value is a File */
30
42
  function isFile(value) {
31
- return typeof File !== "undefined" && value instanceof File;
43
+ return typeof File !== "undefined" && value instanceof File;
44
+ }
45
+ /** Checks if a value is an Error */
46
+ function isError(value) {
47
+ return value instanceof Error;
32
48
  }
49
+ /** Checks if a value is a function */
33
50
  function isFunction(value) {
34
- return typeof value === "function";
51
+ return typeof value === "function";
35
52
  }
53
+ /** Checks if a value is a Map */
36
54
  function isMap(value) {
37
- return value instanceof Map;
55
+ return value instanceof Map;
38
56
  }
57
+ /** Checks if a value is NaN */
39
58
  function isNaN(value) {
40
- return typeof value === "number" && Number.isNaN(value);
59
+ return typeof value === "number" && Number.isNaN(value);
41
60
  }
61
+ /** Checks if a value is null */
42
62
  function isNull(value) {
43
- return value === null;
63
+ return value === null;
44
64
  }
65
+ /** Checks if a value is a number */
45
66
  function isNumber(value) {
46
- return typeof value === "number" && !isNaN(value);
67
+ return typeof value === "number" && !isNaN(value);
68
+ }
69
+ /** Checks if a value is a finite number */
70
+ function isFiniteNumber(value) {
71
+ return isNumber(value) && Number.isFinite(value);
72
+ }
73
+ /** Checks if a value is an integer */
74
+ function isInteger(value) {
75
+ return isNumber(value) && Number.isInteger(value);
47
76
  }
77
+ /** Checks if a value is an object, excluding null value */
48
78
  function isObject(value) {
49
- return typeof value === "object" && value !== null;
79
+ return typeof value === "object" && value !== null;
50
80
  }
81
+ /** Checks if a value is promise-like */
82
+ function isPromiseLike(value) {
83
+ return (isObject(value) || isFunction(value)) && "then" in value && isFunction(value.then);
84
+ }
85
+ /** Checks if a value is a regular expression */
86
+ function isRegExp(value) {
87
+ return value instanceof RegExp;
88
+ }
89
+ /** Check if a value is a record like Record<PropertyKey, unknown> */
51
90
  function isRecord(value) {
52
- return isObject(value) && !isNull(value) && constructorOf(value) === Object && Object.keys(prototypeOf(value)).length === 0;
91
+ return isObject(value) && !isNull(value) && constructorOf(value) === Object && Object.keys(prototypeOf(value)).length === 0;
92
+ }
93
+ /** Checks if a value is a safe integer */
94
+ function isSafeInteger(value) {
95
+ return isNumber(value) && Number.isSafeInteger(value);
53
96
  }
97
+ /** Checks if a value is a Set */
54
98
  function isSet(value) {
55
- return value instanceof Set;
99
+ return value instanceof Set;
56
100
  }
101
+ /** Checks if a value is a string */
57
102
  function isString(value) {
58
- return typeof value === "string";
103
+ return typeof value === "string";
59
104
  }
105
+ /** Checks if a value is a symbol */
60
106
  function isSymbol(value) {
61
- return typeof value === "symbol";
107
+ return typeof value === "symbol";
62
108
  }
109
+ /** Checks if a value is undefined */
63
110
  function isUndefined(value) {
64
- return typeof value === "undefined";
111
+ return typeof value === "undefined";
65
112
  }
66
113
  function constructorOf(value) {
67
- return prototypeOf(value).constructor;
114
+ return prototypeOf(value).constructor;
68
115
  }
69
116
  function prototypeOf(value) {
70
- return Object.getPrototypeOf(value);
117
+ return Object.getPrototypeOf(value);
71
118
  }
72
119
  function And(...predicates) {
73
- return (value) => {
74
- return predicates.every((predicate) => predicate(value));
75
- };
120
+ return (value) => {
121
+ return predicates.every((predicate) => predicate(value));
122
+ };
76
123
  }
77
124
  function Or(...predicates) {
78
- return (value) => {
79
- return predicates.some((predicate) => predicate(value));
80
- };
125
+ return (value) => {
126
+ return predicates.some((predicate) => predicate(value));
127
+ };
81
128
  }
82
129
  function Not(predicate) {
83
- return (value) => !predicate(value);
84
- }
85
- const isShape = (shape) => {
86
- const properties = Object.keys(shape);
87
- return (value) => isObject(value) && properties.every((p) => {
88
- const config = shape[p];
89
- const [predicate, required] = isArray(config) ? config : [config, true];
90
- return p in value && value[p] !== void 0 && predicate(value[p]) || !required;
91
- });
130
+ return (value) => !predicate(value);
131
+ }
132
+ /** Checks present fields with their predicates; optional fields may be absent. */
133
+ var isShape = (shape) => {
134
+ const properties = Object.keys(shape);
135
+ return (value) => isObject(value) && properties.every((p) => {
136
+ const config = shape[p];
137
+ const [predicate, required] = isArray(config) ? config : [config, true];
138
+ if (!(p in value)) return !required;
139
+ return predicate(value[p]);
140
+ });
92
141
  };
142
+ //#endregion
93
143
  exports.And = And;
94
144
  exports.Not = Not;
95
145
  exports.Or = Or;
@@ -100,17 +150,24 @@ exports.isBlob = isBlob;
100
150
  exports.isBoolean = isBoolean;
101
151
  exports.isDate = isDate;
102
152
  exports.isEmail = isEmail;
153
+ exports.isError = isError;
103
154
  exports.isExact = isExact;
104
155
  exports.isFile = isFile;
156
+ exports.isFiniteNumber = isFiniteNumber;
105
157
  exports.isFunction = isFunction;
158
+ exports.isInteger = isInteger;
106
159
  exports.isMap = isMap;
107
160
  exports.isNaN = isNaN;
108
161
  exports.isNull = isNull;
109
162
  exports.isNumber = isNumber;
110
163
  exports.isObject = isObject;
164
+ exports.isPromiseLike = isPromiseLike;
111
165
  exports.isRecord = isRecord;
166
+ exports.isRegExp = isRegExp;
167
+ exports.isSafeInteger = isSafeInteger;
112
168
  exports.isSet = isSet;
113
169
  exports.isShape = isShape;
114
170
  exports.isString = isString;
115
171
  exports.isSymbol = isSymbol;
116
172
  exports.isUndefined = isUndefined;
173
+ exports.isValidDate = isValidDate;
@@ -0,0 +1,77 @@
1
+ import { Intersect, Predicate } from './types/index.cjs';
2
+ /** Checks if a value has a property */
3
+ export declare function hasProperty<K extends PropertyKey = PropertyKey>(key: K): (value: unknown) => value is { [k in K]: unknown; };
4
+ /** Checks if a value is an array */
5
+ export declare function isArray(value: unknown): value is unknown[];
6
+ /** Checks if a value is a boolean */
7
+ export declare function isBoolean(value: unknown): value is boolean;
8
+ /** Checks if a value is a bigint */
9
+ export declare function isBigInt(value: unknown): value is bigint;
10
+ /** Checks if a value is a Blob */
11
+ export declare function isBlob(value: unknown): value is Blob;
12
+ /** Checks if value is Date */
13
+ export declare function isDate(value: unknown): value is Date;
14
+ /** Checks if value is a valid Date */
15
+ export declare function isValidDate(value: unknown): value is Date;
16
+ /** Checks if a value is an email */
17
+ export declare function isEmail(value: unknown): value is string;
18
+ /** Creates a predicate that checks if a value is equal to specified */
19
+ export declare function isExact<T = unknown>(exact: T): (value: unknown) => value is T;
20
+ /** Checks if a value is a File */
21
+ export declare function isFile(value: unknown): value is File;
22
+ /** Checks if a value is an Error */
23
+ export declare function isError(value: unknown): value is Error;
24
+ /** Checks if a value is a function */
25
+ export declare function isFunction<T extends (...args: never[]) => unknown = (...args: never[]) => unknown>(value: unknown): value is T;
26
+ /** Checks if a value is a Map */
27
+ export declare function isMap<K = unknown, V = unknown>(value: unknown): value is Map<K, V>;
28
+ /** Checks if a value is NaN */
29
+ export declare function isNaN(value: unknown): value is number;
30
+ /** Checks if a value is null */
31
+ export declare function isNull(value: unknown): value is null;
32
+ /** Checks if a value is a number */
33
+ export declare function isNumber(value: unknown): value is number;
34
+ /** Checks if a value is a finite number */
35
+ export declare function isFiniteNumber(value: unknown): value is number;
36
+ /** Checks if a value is an integer */
37
+ export declare function isInteger(value: unknown): value is number;
38
+ /** Checks if a value is an object, excluding null value */
39
+ export declare function isObject(value: unknown): value is object;
40
+ /** Checks if a value is promise-like */
41
+ export declare function isPromiseLike<T = unknown>(value: unknown): value is PromiseLike<T>;
42
+ /** Checks if a value is a regular expression */
43
+ export declare function isRegExp(value: unknown): value is RegExp;
44
+ /** Check if a value is a record like Record<PropertyKey, unknown> */
45
+ export declare function isRecord(value: unknown): value is Record<PropertyKey, unknown>;
46
+ /** Checks if a value is a safe integer */
47
+ export declare function isSafeInteger(value: unknown): value is number;
48
+ /** Checks if a value is a Set */
49
+ export declare function isSet<T = unknown>(value: unknown): value is Set<T>;
50
+ /** Checks if a value is a string */
51
+ export declare function isString(value: unknown): value is string;
52
+ /** Checks if a value is a symbol */
53
+ export declare function isSymbol(value: unknown): value is symbol;
54
+ /** Checks if a value is undefined */
55
+ export declare function isUndefined(value: unknown): value is undefined;
56
+ export declare function And<T extends unknown[]>(...predicates: [...{
57
+ [K in keyof T]: Predicate<T[K]>;
58
+ }]): Predicate<Intersect<T>>;
59
+ export declare function Or<T extends unknown[]>(...predicates: [...{
60
+ [K in keyof T]: Predicate<T[K]>;
61
+ }]): Predicate<T[number]>;
62
+ export declare function Not<T>(predicate: Predicate<T>): Predicate;
63
+ export type Shape<T extends object> = {
64
+ [K in keyof T]: [Predicate<T[K]>, boolean] | Predicate<T[K]>;
65
+ };
66
+ type ShapePropertyType<Config> = Config extends Predicate<infer U> ? U : Config extends [Predicate<infer U>, boolean] ? U : never;
67
+ type OptionalShapeKeys<T> = {
68
+ [K in keyof T]: T[K] extends [Predicate, infer Required] ? false extends Required ? K : never : never;
69
+ }[keyof T];
70
+ type ExtractType<T> = {
71
+ [K in Exclude<keyof T, OptionalShapeKeys<T>>]: ShapePropertyType<T[K]>;
72
+ } & {
73
+ [K in OptionalShapeKeys<T>]?: ShapePropertyType<T[K]>;
74
+ };
75
+ /** Checks present fields with their predicates; optional fields may be absent. */
76
+ export declare const isShape: <S extends Shape<any>>(shape: S) => (value: unknown) => value is ExtractType<S>;
77
+ export {};
@@ -0,0 +1,77 @@
1
+ import { Intersect, Predicate } from './types/index.mjs';
2
+ /** Checks if a value has a property */
3
+ export declare function hasProperty<K extends PropertyKey = PropertyKey>(key: K): (value: unknown) => value is { [k in K]: unknown; };
4
+ /** Checks if a value is an array */
5
+ export declare function isArray(value: unknown): value is unknown[];
6
+ /** Checks if a value is a boolean */
7
+ export declare function isBoolean(value: unknown): value is boolean;
8
+ /** Checks if a value is a bigint */
9
+ export declare function isBigInt(value: unknown): value is bigint;
10
+ /** Checks if a value is a Blob */
11
+ export declare function isBlob(value: unknown): value is Blob;
12
+ /** Checks if value is Date */
13
+ export declare function isDate(value: unknown): value is Date;
14
+ /** Checks if value is a valid Date */
15
+ export declare function isValidDate(value: unknown): value is Date;
16
+ /** Checks if a value is an email */
17
+ export declare function isEmail(value: unknown): value is string;
18
+ /** Creates a predicate that checks if a value is equal to specified */
19
+ export declare function isExact<T = unknown>(exact: T): (value: unknown) => value is T;
20
+ /** Checks if a value is a File */
21
+ export declare function isFile(value: unknown): value is File;
22
+ /** Checks if a value is an Error */
23
+ export declare function isError(value: unknown): value is Error;
24
+ /** Checks if a value is a function */
25
+ export declare function isFunction<T extends (...args: never[]) => unknown = (...args: never[]) => unknown>(value: unknown): value is T;
26
+ /** Checks if a value is a Map */
27
+ export declare function isMap<K = unknown, V = unknown>(value: unknown): value is Map<K, V>;
28
+ /** Checks if a value is NaN */
29
+ export declare function isNaN(value: unknown): value is number;
30
+ /** Checks if a value is null */
31
+ export declare function isNull(value: unknown): value is null;
32
+ /** Checks if a value is a number */
33
+ export declare function isNumber(value: unknown): value is number;
34
+ /** Checks if a value is a finite number */
35
+ export declare function isFiniteNumber(value: unknown): value is number;
36
+ /** Checks if a value is an integer */
37
+ export declare function isInteger(value: unknown): value is number;
38
+ /** Checks if a value is an object, excluding null value */
39
+ export declare function isObject(value: unknown): value is object;
40
+ /** Checks if a value is promise-like */
41
+ export declare function isPromiseLike<T = unknown>(value: unknown): value is PromiseLike<T>;
42
+ /** Checks if a value is a regular expression */
43
+ export declare function isRegExp(value: unknown): value is RegExp;
44
+ /** Check if a value is a record like Record<PropertyKey, unknown> */
45
+ export declare function isRecord(value: unknown): value is Record<PropertyKey, unknown>;
46
+ /** Checks if a value is a safe integer */
47
+ export declare function isSafeInteger(value: unknown): value is number;
48
+ /** Checks if a value is a Set */
49
+ export declare function isSet<T = unknown>(value: unknown): value is Set<T>;
50
+ /** Checks if a value is a string */
51
+ export declare function isString(value: unknown): value is string;
52
+ /** Checks if a value is a symbol */
53
+ export declare function isSymbol(value: unknown): value is symbol;
54
+ /** Checks if a value is undefined */
55
+ export declare function isUndefined(value: unknown): value is undefined;
56
+ export declare function And<T extends unknown[]>(...predicates: [...{
57
+ [K in keyof T]: Predicate<T[K]>;
58
+ }]): Predicate<Intersect<T>>;
59
+ export declare function Or<T extends unknown[]>(...predicates: [...{
60
+ [K in keyof T]: Predicate<T[K]>;
61
+ }]): Predicate<T[number]>;
62
+ export declare function Not<T>(predicate: Predicate<T>): Predicate;
63
+ export type Shape<T extends object> = {
64
+ [K in keyof T]: [Predicate<T[K]>, boolean] | Predicate<T[K]>;
65
+ };
66
+ type ShapePropertyType<Config> = Config extends Predicate<infer U> ? U : Config extends [Predicate<infer U>, boolean] ? U : never;
67
+ type OptionalShapeKeys<T> = {
68
+ [K in keyof T]: T[K] extends [Predicate, infer Required] ? false extends Required ? K : never : never;
69
+ }[keyof T];
70
+ type ExtractType<T> = {
71
+ [K in Exclude<keyof T, OptionalShapeKeys<T>>]: ShapePropertyType<T[K]>;
72
+ } & {
73
+ [K in OptionalShapeKeys<T>]?: ShapePropertyType<T[K]>;
74
+ };
75
+ /** Checks present fields with their predicates; optional fields may be absent. */
76
+ export declare const isShape: <S extends Shape<any>>(shape: S) => (value: unknown) => value is ExtractType<S>;
77
+ export {};