-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvalidators.js
More file actions
60 lines (60 loc) · 2.02 KB
/
validators.js
File metadata and controls
60 lines (60 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
48
49
50
51
52
53
54
55
56
57
58
59
60
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sym = require("./symbols");
const common_1 = require("./common");
var ValidationOptions;
(function (ValidationOptions) {
ValidationOptions[ValidationOptions["any"] = 0] = "any";
ValidationOptions[ValidationOptions["all"] = 1] = "all";
})(ValidationOptions = exports.ValidationOptions || (exports.ValidationOptions = {}));
function Primative(ctor) {
return Type(ctor);
}
exports.Primative = Primative;
function Type(ctor) {
if (common_1.nullOrUndef(ctor) || common_1.nullOrUndef(ctor.prototype))
throw new Error('Schema error, not a valid type.');
let result = (() => { });
result[sym.Validator] = sym.TypeValidator;
result[sym.TypeValidator] = ctor.prototype.constructor.name;
return result;
}
exports.Type = Type;
function Options(schemas, name = Options.name, option = ValidationOptions.any) {
let result = (() => { });
result[sym.Validator] = sym.OptionsValidator;
result[sym.OptionsValidator] = { schemas, option };
result[sym.Metadata] = { name };
return result;
}
exports.Options = Options;
function Any(schemas, name = Any.name) {
return Options(schemas, name, ValidationOptions.any);
}
exports.Any = Any;
function All(schemas, name = All.name) {
return Options(schemas, name, ValidationOptions.all);
}
exports.All = All;
function Optional(schema, name = Optional.name) {
return Options([schema, undefined], name);
}
exports.Optional = Optional;
function Nullable(schema, name = Nullable.name) {
return Options([schema, null], name);
}
exports.Nullable = Nullable;
function Validator(method, name = Validator.name) {
const result = (() => { });
result[sym.Validator] = sym.CustomValidator;
result[sym.CustomValidator] = method;
result[sym.Metadata] = { name };
return result;
}
exports.Validator = Validator;
function Alias(validator, name = Alias.name) {
validator[sym.Metadata].name = name;
return validator;
}
exports.Alias = Alias;
//# sourceMappingURL=validators.js.map