@local901/validator 0.2.3 → 0.2.5
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/index.d.ts +25 -26
- package/index.js +44 -13
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { OptionalValidator } from "./types/util/OptionalValidator";
|
|
6
|
-
import { stringValidator, type StringValidationOptions } from "./types/string/StringValidator";
|
|
1
|
+
import { type IntValidationOptions } from "./types/number/IntValidator";
|
|
2
|
+
import { type NumberValidationOptions } from "./types/number/NumberValidator";
|
|
3
|
+
import { type FieldValidators } from "./types/object/ObjectValidator";
|
|
4
|
+
import { type StringValidationOptions } from "./types/string/StringValidator";
|
|
7
5
|
import { Validator } from "./Validator";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { RecordValidator, type RecordType, type RecordTypeValidator } from "./types/object/RecordValidator";
|
|
6
|
+
import { type OrValidators } from "./types/util/OrValidator";
|
|
7
|
+
import { type ArrayValidatorOptions } from "./types/object/ArrayValidator";
|
|
8
|
+
import { type EnumLike } from "./types/object/EnumValidator";
|
|
9
|
+
import { type TupleValidators } from "./types/object/TupleValidator";
|
|
10
|
+
import { type ConstructorType, type InstanceofValidationOptions } from "./types/util/InstanceofValidator";
|
|
11
|
+
import { type RecordType, type RecordTypeValidator } from "./types/object/RecordValidator";
|
|
15
12
|
export { Validator } from "./Validator";
|
|
16
13
|
export { ErrorType, type ErrorValue } from "./errors/ErrorType";
|
|
17
14
|
export { ValidationError, type ErrorFields } from "./errors/ValidationError";
|
|
18
15
|
export declare class v {
|
|
19
|
-
static boolean
|
|
20
|
-
static int
|
|
21
|
-
static number
|
|
22
|
-
static array
|
|
23
|
-
static enum
|
|
24
|
-
static object
|
|
25
|
-
static record
|
|
26
|
-
static tuple
|
|
27
|
-
static string
|
|
28
|
-
static any
|
|
29
|
-
static instanceof
|
|
30
|
-
static optional
|
|
31
|
-
static
|
|
16
|
+
static boolean(): Validator<boolean>;
|
|
17
|
+
static int(options?: IntValidationOptions): Validator<number>;
|
|
18
|
+
static number(options?: NumberValidationOptions): Validator<number>;
|
|
19
|
+
static array<T>(item: Validator<T>, options?: ArrayValidatorOptions): Validator<T[]>;
|
|
20
|
+
static enum<T extends EnumLike>(enumInstance: T): Validator<T[keyof T]>;
|
|
21
|
+
static object<T extends object>(fields: FieldValidators<T>): Validator<T>;
|
|
22
|
+
static record<T extends RecordType>(field: RecordTypeValidator<T>): Validator<T>;
|
|
23
|
+
static tuple<T extends [...unknown[]]>(validators: TupleValidators<T>): Validator<T>;
|
|
24
|
+
static string<T extends string = string>(options?: StringValidationOptions): Validator<T>;
|
|
25
|
+
static any<T>(): Validator<T>;
|
|
26
|
+
static instanceof<T>(instance: ConstructorType<T>, options: InstanceofValidationOptions<T>): Validator<T>;
|
|
27
|
+
static optional<T>(val: Validator<Exclude<T, undefined | null>>, type?: undefined): Validator<T | undefined | null>;
|
|
28
|
+
static optional<T>(val: Validator<Exclude<T, undefined | null>>, type: "undefined"): Validator<T | undefined>;
|
|
29
|
+
static optional<T>(val: Validator<Exclude<T, undefined | null>>, type: "null"): Validator<T | null>;
|
|
30
|
+
static or<T>(validators: OrValidators<T>): Validator<T>;
|
|
32
31
|
}
|
package/index.js
CHANGED
|
@@ -21,19 +21,50 @@ Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function ()
|
|
|
21
21
|
var ValidationError_1 = require("./errors/ValidationError");
|
|
22
22
|
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return ValidationError_1.ValidationError; } });
|
|
23
23
|
class v {
|
|
24
|
-
|
|
25
|
-
static
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
static
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
static
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
static
|
|
24
|
+
// Boolean
|
|
25
|
+
static boolean() {
|
|
26
|
+
return new BooleanValidator_1.BooleanValidator();
|
|
27
|
+
}
|
|
28
|
+
// Numbers
|
|
29
|
+
static int(options) {
|
|
30
|
+
return new IntValidator_1.IntValidator(options);
|
|
31
|
+
}
|
|
32
|
+
static number(options) {
|
|
33
|
+
return new NumberValidator_1.NumberValidator(options);
|
|
34
|
+
}
|
|
35
|
+
// Objects
|
|
36
|
+
static array(item, options) {
|
|
37
|
+
return new ArrayValidator_1.ArrayValidator(item, options);
|
|
38
|
+
}
|
|
39
|
+
static enum(enumInstance) {
|
|
40
|
+
return new EnumValidator_1.EnumValidator(enumInstance);
|
|
41
|
+
}
|
|
42
|
+
static object(fields) {
|
|
43
|
+
return new ObjectValidator_1.ObjectValidator(fields);
|
|
44
|
+
}
|
|
45
|
+
static record(field) {
|
|
46
|
+
return new RecordValidator_1.RecordValidator(field);
|
|
47
|
+
}
|
|
48
|
+
static tuple(validators) {
|
|
49
|
+
return new TupleValidator_1.TupleValidator(validators);
|
|
50
|
+
}
|
|
51
|
+
// Strings
|
|
52
|
+
static string(options) {
|
|
53
|
+
return new StringValidator_1.stringValidator(options);
|
|
54
|
+
}
|
|
55
|
+
// Utility
|
|
56
|
+
static any() {
|
|
57
|
+
return new AnyValidator_1.AnyValidator();
|
|
58
|
+
}
|
|
59
|
+
static instanceof(instance, options) {
|
|
60
|
+
return new InstanceofValidator_1.InstanceofValidator(instance, options);
|
|
61
|
+
}
|
|
62
|
+
static optional(val, type) {
|
|
63
|
+
return new OptionalValidator_1.OptionalValidator(val, { only: type });
|
|
64
|
+
}
|
|
65
|
+
static or(validators) {
|
|
66
|
+
return new OrValidator_1.OrValidator(validators);
|
|
67
|
+
}
|
|
37
68
|
}
|
|
38
69
|
exports.v = v;
|
|
39
70
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oEAAiE;AACjE,8DAAsF;AACtF,oEAA+F;AAC/F,oEAAuF;AACvF,sEAAmE;AACnE,oEAA+F;AAE/F,4DAAyD;AACzD,0DAA0E;AAC1E,kEAA2F;AAC3F,gEAA4E;AAC5E,kEAAqF;AACrF,0EAA+H;AAC/H,oEAA4G;AAE5G,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,gDAAgE;AAAvD,sGAAA,SAAS,OAAA;AAClB,4DAA6E;AAApE,kHAAA,eAAe,OAAA;AAExB,MAAa,CAAC;IACH,MAAM,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,oEAAiE;AACjE,8DAAsF;AACtF,oEAA+F;AAC/F,oEAAuF;AACvF,sEAAmE;AACnE,oEAA+F;AAE/F,4DAAyD;AACzD,0DAA0E;AAC1E,kEAA2F;AAC3F,gEAA4E;AAC5E,kEAAqF;AACrF,0EAA+H;AAC/H,oEAA4G;AAE5G,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,gDAAgE;AAAvD,sGAAA,SAAS,OAAA;AAClB,4DAA6E;AAApE,kHAAA,eAAe,OAAA;AAExB,MAAa,CAAC;IACV,UAAU;IACH,MAAM,CAAC,OAAO;QACjB,OAAO,IAAI,mCAAgB,EAAE,CAAC;IAClC,CAAC;IAED,UAAU;IACH,MAAM,CAAC,GAAG,CAAC,OAA8B;QAC5C,OAAO,IAAI,2BAAY,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IACM,MAAM,CAAC,MAAM,CAAC,OAAiC;QAClD,OAAO,IAAI,iCAAe,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,UAAU;IACH,MAAM,CAAC,KAAK,CAAI,IAAkB,EAAE,OAA+B;QACtE,OA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