n4s 5.0.1 → 5.0.2
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 +0 -4
- package/README.md +2 -0
- package/compose/package.json +2 -0
- package/compounds/package.json +2 -0
- package/date/package.json +9 -0
- package/dist/cjs/compose.development.js +14 -97
- package/dist/cjs/compose.js +0 -1
- package/dist/cjs/compose.production.js +1 -1
- package/dist/cjs/compounds.development.js +30 -86
- package/dist/cjs/compounds.js +0 -1
- package/dist/cjs/compounds.production.js +1 -1
- package/dist/cjs/date.development.js +186 -0
- package/dist/cjs/date.js +6 -0
- package/dist/cjs/date.production.js +1 -0
- package/dist/cjs/email.development.js +363 -0
- package/dist/cjs/email.js +6 -0
- package/dist/cjs/email.production.js +1 -0
- package/dist/cjs/isURL.development.js +353 -0
- package/dist/cjs/isURL.js +6 -0
- package/dist/cjs/isURL.production.js +1 -0
- package/dist/cjs/n4s.development.js +205 -387
- package/dist/cjs/n4s.js +0 -1
- package/dist/cjs/n4s.production.js +1 -1
- package/dist/cjs/schema.development.js +19 -80
- package/dist/cjs/schema.js +0 -1
- package/dist/cjs/schema.production.js +1 -1
- package/dist/es/compose.development.js +14 -97
- package/dist/es/compose.production.js +1 -1
- package/dist/es/compounds.development.js +28 -84
- package/dist/es/compounds.production.js +1 -1
- package/dist/es/date.development.js +184 -0
- package/dist/es/date.production.js +1 -0
- package/dist/es/email.development.js +361 -0
- package/dist/es/email.production.js +1 -0
- package/dist/es/isURL.development.js +351 -0
- package/dist/es/isURL.production.js +1 -0
- package/dist/es/n4s.development.js +192 -372
- package/dist/es/n4s.production.js +1 -1
- package/dist/es/schema.development.js +16 -75
- package/dist/es/schema.production.js +1 -1
- package/dist/umd/compose.development.js +18 -102
- package/dist/umd/compose.production.js +1 -1
- package/dist/umd/compounds.development.js +34 -91
- package/dist/umd/compounds.production.js +1 -1
- package/dist/umd/date.development.js +190 -0
- package/dist/umd/date.production.js +1 -0
- package/dist/umd/email.development.js +367 -0
- package/dist/umd/email.production.js +1 -0
- package/dist/umd/isURL.development.js +357 -0
- package/dist/umd/isURL.production.js +1 -0
- package/dist/umd/n4s.development.js +209 -392
- package/dist/umd/n4s.production.js +1 -1
- package/dist/umd/schema.development.js +23 -85
- package/dist/umd/schema.production.js +1 -1
- package/email/package.json +9 -0
- package/isURL/package.json +9 -0
- package/package.json +162 -55
- package/schema/package.json +2 -0
- package/testUtils/TEnforceMock.ts +3 -0
- package/types/compose.d.ts +46 -55
- package/types/compose.d.ts.map +1 -0
- package/types/compounds.d.ts +50 -62
- package/types/compounds.d.ts.map +1 -0
- package/types/date.d.ts +18 -0
- package/types/date.d.ts.map +1 -0
- package/types/email.d.ts +12 -0
- package/types/email.d.ts.map +1 -0
- package/types/isURL.d.ts +12 -0
- package/types/isURL.d.ts.map +1 -0
- package/types/n4s.d.ts +62 -73
- package/types/n4s.d.ts.map +1 -0
- package/types/schema.d.ts +55 -63
- package/types/schema.d.ts.map +1 -0
- package/docs/.nojekyll +0 -0
- package/docs/README.md +0 -44
- package/docs/_sidebar.md +0 -5
- package/docs/external.md +0 -27
- package/docs/index.html +0 -32
- package/docs/rules.md +0 -1282
- package/tsconfig.json +0 -8
package/types/n4s.d.ts
CHANGED
|
@@ -1,69 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
bind: <Fn extends (...args: any[]) => any>(ctxRef: Partial<CTXType>, fn: Fn) => Fn;
|
|
4
|
-
use: () => CTXType | undefined;
|
|
5
|
-
useX: (errorMessage?: string | undefined) => CTXType;
|
|
6
|
-
};
|
|
1
|
+
import { Nullable, DropFirst, Stringable, BlankValue, CB, DynamicValue } from "vest-utils";
|
|
2
|
+
declare const ctx: import("context").CtxCascadeApi<CTXType>;
|
|
7
3
|
type CTXType = {
|
|
8
4
|
meta: Record<string, any>;
|
|
9
5
|
value: any;
|
|
10
6
|
set?: boolean;
|
|
11
|
-
parent: () => CTXType
|
|
7
|
+
parent: () => Nullable<CTXType>;
|
|
12
8
|
};
|
|
13
|
-
type
|
|
9
|
+
type EnforceContext = Nullable<{
|
|
14
10
|
meta: Record<string, any>;
|
|
15
11
|
value: any;
|
|
16
|
-
parent: () =>
|
|
17
|
-
}
|
|
18
|
-
type
|
|
19
|
-
unknown,
|
|
20
|
-
...infer U
|
|
21
|
-
] ? U : never;
|
|
22
|
-
type TStringable = string | ((...args: any[]) => string);
|
|
23
|
-
type TRuleReturn = boolean | {
|
|
12
|
+
parent: () => EnforceContext;
|
|
13
|
+
}>;
|
|
14
|
+
type RuleReturn = boolean | {
|
|
24
15
|
pass: boolean;
|
|
25
|
-
message?:
|
|
16
|
+
message?: Stringable;
|
|
26
17
|
};
|
|
27
|
-
type
|
|
18
|
+
type RuleDetailedResult = {
|
|
28
19
|
pass: boolean;
|
|
29
20
|
message?: string;
|
|
30
21
|
};
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
type
|
|
36
|
-
type KBaseRules = keyof
|
|
37
|
-
declare function condition(value: any, callback: (value: any) =>
|
|
22
|
+
type Args = any[];
|
|
23
|
+
type RuleValue = any;
|
|
24
|
+
type RuleBase = (value: RuleValue, ...args: Args) => RuleReturn;
|
|
25
|
+
type Rule = Record<string, RuleBase>;
|
|
26
|
+
type BaseRules = typeof baseRules;
|
|
27
|
+
type KBaseRules = keyof BaseRules;
|
|
28
|
+
declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
|
|
38
29
|
declare function endsWith(value: string, arg1: string): boolean;
|
|
39
30
|
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
40
|
-
declare function greaterThan(value: number | string, gt: number | string): boolean;
|
|
41
31
|
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
42
32
|
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
43
|
-
// The module is named "isArrayValue" since it
|
|
44
|
-
// is conflicting with a nested npm dependency.
|
|
45
|
-
// We may need to revisit this in the future.
|
|
46
|
-
declare function isArray(value: unknown): value is Array<unknown>;
|
|
47
33
|
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
48
|
-
declare function isBlank(value: unknown):
|
|
49
|
-
declare function
|
|
50
|
-
declare function isEmpty(value: unknown): boolean;
|
|
34
|
+
declare function isBlank(value: unknown): value is BlankValue;
|
|
35
|
+
declare function isKeyOf(key: string | symbol | number, obj: any): boolean;
|
|
51
36
|
declare function isNaN(value: unknown): boolean;
|
|
52
37
|
declare function isNegative(value: number | string): boolean;
|
|
53
|
-
declare function isNull(value: unknown): value is null;
|
|
54
|
-
declare function isNullish(value: any): value is null | undefined;
|
|
55
38
|
declare function isNumber(value: unknown): value is number;
|
|
56
|
-
declare function isNumeric(value: string | number): boolean;
|
|
57
|
-
declare function isStringValue(v: unknown): v is string;
|
|
58
39
|
declare function isTruthy(value: unknown): boolean;
|
|
59
|
-
declare function
|
|
60
|
-
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
40
|
+
declare function isValueOf(value: any, objectToCheck: any): boolean;
|
|
61
41
|
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
62
42
|
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
63
|
-
declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
|
|
64
43
|
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
65
44
|
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
66
|
-
declare function numberEquals(value: string | number, eq: string | number): boolean;
|
|
67
45
|
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
68
46
|
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
69
47
|
declare function startsWith(value: string, arg1: string): boolean;
|
|
@@ -73,18 +51,19 @@ declare const baseRules: {
|
|
|
73
51
|
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
74
52
|
endsWith: typeof endsWith;
|
|
75
53
|
equals: typeof equals;
|
|
76
|
-
greaterThan: typeof greaterThan;
|
|
54
|
+
greaterThan: typeof import("vest-utils").greaterThan;
|
|
77
55
|
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
78
|
-
gt: typeof greaterThan;
|
|
56
|
+
gt: typeof import("vest-utils").greaterThan;
|
|
79
57
|
gte: typeof greaterThanOrEquals;
|
|
80
58
|
inside: typeof inside;
|
|
81
|
-
isArray: typeof isArray;
|
|
59
|
+
isArray: typeof import("vest-utils").isArray;
|
|
82
60
|
isBetween: typeof isBetween;
|
|
83
61
|
isBlank: typeof isBlank;
|
|
84
|
-
isBoolean: typeof isBoolean;
|
|
85
|
-
isEmpty: typeof isEmpty;
|
|
62
|
+
isBoolean: typeof import("vest-utils").isBoolean;
|
|
63
|
+
isEmpty: typeof import("vest-utils").isEmpty;
|
|
86
64
|
isEven: (value: any) => boolean;
|
|
87
65
|
isFalsy: (value: unknown) => boolean;
|
|
66
|
+
isKeyOf: typeof isKeyOf;
|
|
88
67
|
isNaN: typeof isNaN;
|
|
89
68
|
isNegative: typeof isNegative;
|
|
90
69
|
isNotArray: (value: unknown) => boolean;
|
|
@@ -92,6 +71,7 @@ declare const baseRules: {
|
|
|
92
71
|
isNotBlank: (value: unknown) => boolean;
|
|
93
72
|
isNotBoolean: (value: unknown) => boolean;
|
|
94
73
|
isNotEmpty: (value: unknown) => boolean;
|
|
74
|
+
isNotKeyOf: (key: string | number | symbol, obj: any) => boolean;
|
|
95
75
|
isNotNaN: (value: unknown) => boolean;
|
|
96
76
|
isNotNull: (value: unknown) => boolean;
|
|
97
77
|
isNotNullish: (value: any) => boolean;
|
|
@@ -99,20 +79,22 @@ declare const baseRules: {
|
|
|
99
79
|
isNotNumeric: (value: string | number) => boolean;
|
|
100
80
|
isNotString: (v: unknown) => boolean;
|
|
101
81
|
isNotUndefined: (value?: unknown) => boolean;
|
|
102
|
-
|
|
103
|
-
|
|
82
|
+
isNotValueOf: (value: any, objectToCheck: any) => boolean;
|
|
83
|
+
isNull: typeof import("vest-utils").isNull;
|
|
84
|
+
isNullish: typeof import("vest-utils").isNullish;
|
|
104
85
|
isNumber: typeof isNumber;
|
|
105
|
-
isNumeric: typeof isNumeric;
|
|
86
|
+
isNumeric: typeof import("vest-utils").isNumeric;
|
|
106
87
|
isOdd: (value: any) => boolean;
|
|
107
|
-
isPositive: (
|
|
108
|
-
isString: typeof isStringValue;
|
|
88
|
+
isPositive: typeof import("vest-utils").isPositive;
|
|
89
|
+
isString: typeof import("vest-utils").isStringValue;
|
|
109
90
|
isTruthy: typeof isTruthy;
|
|
110
|
-
isUndefined: typeof isUndefined;
|
|
111
|
-
|
|
91
|
+
isUndefined: typeof import("vest-utils").isUndefined;
|
|
92
|
+
isValueOf: typeof isValueOf;
|
|
93
|
+
lengthEquals: typeof import("vest-utils").lengthEquals;
|
|
112
94
|
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
113
95
|
lessThan: typeof lessThan;
|
|
114
96
|
lessThanOrEquals: typeof lessThanOrEquals;
|
|
115
|
-
longerThan: typeof longerThan;
|
|
97
|
+
longerThan: typeof import("vest-utils").longerThan;
|
|
116
98
|
longerThanOrEquals: typeof longerThanOrEquals;
|
|
117
99
|
lt: typeof lessThan;
|
|
118
100
|
lte: typeof lessThanOrEquals;
|
|
@@ -120,43 +102,49 @@ declare const baseRules: {
|
|
|
120
102
|
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
121
103
|
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
122
104
|
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
123
|
-
numberEquals: typeof numberEquals;
|
|
105
|
+
numberEquals: typeof import("vest-utils").numberEquals;
|
|
124
106
|
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
125
107
|
shorterThan: typeof shorterThan;
|
|
126
108
|
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
127
109
|
startsWith: typeof startsWith;
|
|
128
110
|
};
|
|
129
|
-
type
|
|
130
|
-
[P in KBaseRules]: (...args: DropFirst<Parameters<
|
|
111
|
+
type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
|
|
112
|
+
[P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
|
|
131
113
|
};
|
|
132
114
|
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
133
115
|
declare global {
|
|
134
116
|
namespace n4s {
|
|
135
|
-
interface IRules<E> extends
|
|
117
|
+
interface IRules<E> extends Rules<E> {
|
|
136
118
|
}
|
|
137
119
|
}
|
|
138
120
|
}
|
|
139
121
|
type IRules = n4s.IRules<Record<string, any>>;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
type
|
|
122
|
+
type TModifiers = {
|
|
123
|
+
message: (input: string) => EnforceEagerReturn;
|
|
124
|
+
};
|
|
125
|
+
type EnforceEagerReturn = IRules & TModifiers;
|
|
126
|
+
type EnforceEager = (value: RuleValue) => EnforceEagerReturn;
|
|
127
|
+
type LazyRules = n4s.IRules<LazyRuleMethods>;
|
|
128
|
+
type Lazy = LazyRules & LazyRuleMethods &
|
|
144
129
|
// This is a "catch all" hack to make TS happy while not
|
|
145
130
|
// losing type hints
|
|
146
|
-
Record<string,
|
|
147
|
-
type
|
|
148
|
-
message: (message:
|
|
131
|
+
Record<string, CB>;
|
|
132
|
+
type LazyRuleMethods = LazyRuleRunners & {
|
|
133
|
+
message: (message: LazyMessage) => Lazy;
|
|
149
134
|
};
|
|
150
|
-
type
|
|
135
|
+
type LazyRuleRunners = {
|
|
151
136
|
test: (value: unknown) => boolean;
|
|
152
|
-
run: (value: unknown) =>
|
|
137
|
+
run: (value: unknown) => RuleDetailedResult;
|
|
153
138
|
};
|
|
154
|
-
type
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
139
|
+
type LazyMessage = DynamicValue<string, [
|
|
140
|
+
value: unknown,
|
|
141
|
+
originalMessage?: Stringable
|
|
142
|
+
]>;
|
|
143
|
+
declare const enforce: Enforce;
|
|
144
|
+
type Enforce = EnforceMethods & LazyRules & EnforceEager;
|
|
145
|
+
type EnforceMethods = {
|
|
146
|
+
context: () => EnforceContext;
|
|
147
|
+
extend: (customRules: Rule) => void;
|
|
160
148
|
};
|
|
161
149
|
declare global {
|
|
162
150
|
namespace n4s {
|
|
@@ -165,3 +153,4 @@ declare global {
|
|
|
165
153
|
}
|
|
166
154
|
}
|
|
167
155
|
export { enforce, ctx };
|
|
156
|
+
//# sourceMappingURL=n4s.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"n4s.d.ts","sourceRoot":"","sources":["../src/n4s.ts","../src/runtime/enforceContext.ts","../src/lib/ruleReturn.ts","../src/rules/endsWith.ts","../src/rules/equals.ts","../src/rules/greaterThanOrEquals.ts","../src/rules/inside.ts","../src/rules/lessThan.ts","../src/rules/lessThanOrEquals.ts","../src/rules/isBetween.ts","../src/rules/isBlank.ts","../src/rules/isBoolean.ts","../src/rules/isEven.ts","../src/rules/isKeyOf.ts","../src/rules/isNaN.ts","../src/rules/isNegative.ts","../src/rules/isNumber.ts","../src/rules/isOdd.ts","../src/rules/isString.ts","../src/rules/isTruthy.ts","../src/rules/isValueOf.ts","../src/rules/longerThanOrEquals.ts","../src/rules/matches.ts","../src/rules/ruleCondition.ts","../src/rules/shorterThan.ts","../src/rules/shorterThanOrEquals.ts","../src/rules/startsWith.ts","../src/runtime/rules.ts","../src/runtime/runtimeRules.ts","../src/lib/transformResult.ts","../src/runtime/enforceEager.ts","../src/runtime/genEnforceLazy.ts","../src/runtime/enforce.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,QAAQ,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,qBAAqB,CAAC,CAAC;SAAI;KACtC;CACF;AARD,OAAO,gBAAW,CAAgB"}
|
package/types/schema.d.ts
CHANGED
|
@@ -1,49 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
] ? U : never;
|
|
5
|
-
type TStringable = string | ((...args: any[]) => string);
|
|
6
|
-
type TRuleReturn = boolean | {
|
|
1
|
+
import { CB, DropFirst, Stringable, DynamicValue, BlankValue } from "vest-utils";
|
|
2
|
+
type EnforceCustomMatcher<F extends CB, R> = (...args: DropFirst<Parameters<F>>) => R;
|
|
3
|
+
type RuleReturn = boolean | {
|
|
7
4
|
pass: boolean;
|
|
8
|
-
message?:
|
|
5
|
+
message?: Stringable;
|
|
9
6
|
};
|
|
10
|
-
type
|
|
7
|
+
type RuleDetailedResult = {
|
|
11
8
|
pass: boolean;
|
|
12
9
|
message?: string;
|
|
13
10
|
};
|
|
14
|
-
type
|
|
15
|
-
type
|
|
16
|
-
type KBaseRules = keyof
|
|
17
|
-
declare function condition(value: any, callback: (value: any) =>
|
|
11
|
+
type Args = any[];
|
|
12
|
+
type BaseRules = typeof baseRules;
|
|
13
|
+
type KBaseRules = keyof BaseRules;
|
|
14
|
+
declare function condition(value: any, callback: (value: any) => RuleReturn): RuleReturn;
|
|
18
15
|
declare function endsWith(value: string, arg1: string): boolean;
|
|
19
16
|
declare function equals(value: unknown, arg1: unknown): boolean;
|
|
20
|
-
declare function greaterThan(value: number | string, gt: number | string): boolean;
|
|
21
17
|
declare function greaterThanOrEquals(value: string | number, gte: string | number): boolean;
|
|
22
18
|
declare function inside(value: unknown, arg1: string | unknown[]): boolean;
|
|
23
|
-
// The module is named "isArrayValue" since it
|
|
24
|
-
// is conflicting with a nested npm dependency.
|
|
25
|
-
// We may need to revisit this in the future.
|
|
26
|
-
declare function isArray(value: unknown): value is Array<unknown>;
|
|
27
19
|
declare function isBetween(value: number | string, min: number | string, max: number | string): boolean;
|
|
28
|
-
declare function isBlank(value: unknown):
|
|
29
|
-
declare function
|
|
30
|
-
declare function isEmpty(value: unknown): boolean;
|
|
20
|
+
declare function isBlank(value: unknown): value is BlankValue;
|
|
21
|
+
declare function isKeyOf(key: string | symbol | number, obj: any): boolean;
|
|
31
22
|
declare function isNaN(value: unknown): boolean;
|
|
32
23
|
declare function isNegative(value: number | string): boolean;
|
|
33
|
-
declare function isNull(value: unknown): value is null;
|
|
34
|
-
declare function isNullish(value: any): value is null | undefined;
|
|
35
24
|
declare function isNumber(value: unknown): value is number;
|
|
36
|
-
declare function isNumeric(value: string | number): boolean;
|
|
37
|
-
declare function isStringValue(v: unknown): v is string;
|
|
38
25
|
declare function isTruthy(value: unknown): boolean;
|
|
39
|
-
declare function
|
|
40
|
-
declare function lengthEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
26
|
+
declare function isValueOf(value: any, objectToCheck: any): boolean;
|
|
41
27
|
declare function lessThan(value: string | number, lt: string | number): boolean;
|
|
42
28
|
declare function lessThanOrEquals(value: string | number, lte: string | number): boolean;
|
|
43
|
-
declare function longerThan(value: string | unknown[], arg1: string | number): boolean;
|
|
44
29
|
declare function longerThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
45
30
|
declare function matches(value: string, regex: RegExp | string): boolean;
|
|
46
|
-
declare function numberEquals(value: string | number, eq: string | number): boolean;
|
|
47
31
|
declare function shorterThan(value: string | unknown[], arg1: string | number): boolean;
|
|
48
32
|
declare function shorterThanOrEquals(value: string | unknown[], arg1: string | number): boolean;
|
|
49
33
|
declare function startsWith(value: string, arg1: string): boolean;
|
|
@@ -53,18 +37,19 @@ declare const baseRules: {
|
|
|
53
37
|
doesNotStartWith: (value: string, arg1: string) => boolean;
|
|
54
38
|
endsWith: typeof endsWith;
|
|
55
39
|
equals: typeof equals;
|
|
56
|
-
greaterThan: typeof greaterThan;
|
|
40
|
+
greaterThan: typeof import("vest-utils").greaterThan;
|
|
57
41
|
greaterThanOrEquals: typeof greaterThanOrEquals;
|
|
58
|
-
gt: typeof greaterThan;
|
|
42
|
+
gt: typeof import("vest-utils").greaterThan;
|
|
59
43
|
gte: typeof greaterThanOrEquals;
|
|
60
44
|
inside: typeof inside;
|
|
61
|
-
isArray: typeof isArray;
|
|
45
|
+
isArray: typeof import("vest-utils").isArray;
|
|
62
46
|
isBetween: typeof isBetween;
|
|
63
47
|
isBlank: typeof isBlank;
|
|
64
|
-
isBoolean: typeof isBoolean;
|
|
65
|
-
isEmpty: typeof isEmpty;
|
|
48
|
+
isBoolean: typeof import("vest-utils").isBoolean;
|
|
49
|
+
isEmpty: typeof import("vest-utils").isEmpty;
|
|
66
50
|
isEven: (value: any) => boolean;
|
|
67
51
|
isFalsy: (value: unknown) => boolean;
|
|
52
|
+
isKeyOf: typeof isKeyOf;
|
|
68
53
|
isNaN: typeof isNaN;
|
|
69
54
|
isNegative: typeof isNegative;
|
|
70
55
|
isNotArray: (value: unknown) => boolean;
|
|
@@ -72,6 +57,7 @@ declare const baseRules: {
|
|
|
72
57
|
isNotBlank: (value: unknown) => boolean;
|
|
73
58
|
isNotBoolean: (value: unknown) => boolean;
|
|
74
59
|
isNotEmpty: (value: unknown) => boolean;
|
|
60
|
+
isNotKeyOf: (key: string | number | symbol, obj: any) => boolean;
|
|
75
61
|
isNotNaN: (value: unknown) => boolean;
|
|
76
62
|
isNotNull: (value: unknown) => boolean;
|
|
77
63
|
isNotNullish: (value: any) => boolean;
|
|
@@ -79,20 +65,22 @@ declare const baseRules: {
|
|
|
79
65
|
isNotNumeric: (value: string | number) => boolean;
|
|
80
66
|
isNotString: (v: unknown) => boolean;
|
|
81
67
|
isNotUndefined: (value?: unknown) => boolean;
|
|
82
|
-
|
|
83
|
-
|
|
68
|
+
isNotValueOf: (value: any, objectToCheck: any) => boolean;
|
|
69
|
+
isNull: typeof import("vest-utils").isNull;
|
|
70
|
+
isNullish: typeof import("vest-utils").isNullish;
|
|
84
71
|
isNumber: typeof isNumber;
|
|
85
|
-
isNumeric: typeof isNumeric;
|
|
72
|
+
isNumeric: typeof import("vest-utils").isNumeric;
|
|
86
73
|
isOdd: (value: any) => boolean;
|
|
87
|
-
isPositive: (
|
|
88
|
-
isString: typeof isStringValue;
|
|
74
|
+
isPositive: typeof import("vest-utils").isPositive;
|
|
75
|
+
isString: typeof import("vest-utils").isStringValue;
|
|
89
76
|
isTruthy: typeof isTruthy;
|
|
90
|
-
isUndefined: typeof isUndefined;
|
|
91
|
-
|
|
77
|
+
isUndefined: typeof import("vest-utils").isUndefined;
|
|
78
|
+
isValueOf: typeof isValueOf;
|
|
79
|
+
lengthEquals: typeof import("vest-utils").lengthEquals;
|
|
92
80
|
lengthNotEquals: (value: string | unknown[], arg1: string | number) => boolean;
|
|
93
81
|
lessThan: typeof lessThan;
|
|
94
82
|
lessThanOrEquals: typeof lessThanOrEquals;
|
|
95
|
-
longerThan: typeof longerThan;
|
|
83
|
+
longerThan: typeof import("vest-utils").longerThan;
|
|
96
84
|
longerThanOrEquals: typeof longerThanOrEquals;
|
|
97
85
|
lt: typeof lessThan;
|
|
98
86
|
lte: typeof lessThanOrEquals;
|
|
@@ -100,52 +88,56 @@ declare const baseRules: {
|
|
|
100
88
|
notEquals: (value: unknown, arg1: unknown) => boolean;
|
|
101
89
|
notInside: (value: unknown, arg1: string | unknown[]) => boolean;
|
|
102
90
|
notMatches: (value: string, regex: string | RegExp) => boolean;
|
|
103
|
-
numberEquals: typeof numberEquals;
|
|
91
|
+
numberEquals: typeof import("vest-utils").numberEquals;
|
|
104
92
|
numberNotEquals: (value: string | number, eq: string | number) => boolean;
|
|
105
93
|
shorterThan: typeof shorterThan;
|
|
106
94
|
shorterThanOrEquals: typeof shorterThanOrEquals;
|
|
107
95
|
startsWith: typeof startsWith;
|
|
108
96
|
};
|
|
109
|
-
type
|
|
110
|
-
[P in KBaseRules]: (...args: DropFirst<Parameters<
|
|
97
|
+
type Rules<E = Record<string, unknown>> = n4s.EnforceCustomMatchers<Rules<E> & E> & Record<string, (...args: Args) => Rules<E> & E> & {
|
|
98
|
+
[P in KBaseRules]: (...args: DropFirst<Parameters<BaseRules[P]>> | Args) => Rules<E> & E;
|
|
111
99
|
};
|
|
112
100
|
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/no-empty-interface */
|
|
113
101
|
declare global {
|
|
114
102
|
namespace n4s {
|
|
115
|
-
interface IRules<E> extends
|
|
103
|
+
interface IRules<E> extends Rules<E> {
|
|
116
104
|
}
|
|
117
105
|
}
|
|
118
106
|
}
|
|
119
|
-
type
|
|
120
|
-
type
|
|
107
|
+
type LazyRules = n4s.IRules<LazyRuleMethods>;
|
|
108
|
+
type Lazy = LazyRules & LazyRuleMethods &
|
|
121
109
|
// This is a "catch all" hack to make TS happy while not
|
|
122
110
|
// losing type hints
|
|
123
|
-
Record<string,
|
|
124
|
-
type
|
|
125
|
-
message: (message:
|
|
111
|
+
Record<string, CB>;
|
|
112
|
+
type LazyRuleMethods = LazyRuleRunners & {
|
|
113
|
+
message: (message: LazyMessage) => Lazy;
|
|
126
114
|
};
|
|
127
|
-
type
|
|
115
|
+
type LazyRuleRunners = {
|
|
128
116
|
test: (value: unknown) => boolean;
|
|
129
|
-
run: (value: unknown) =>
|
|
117
|
+
run: (value: unknown) => RuleDetailedResult;
|
|
130
118
|
};
|
|
131
|
-
type
|
|
132
|
-
|
|
133
|
-
|
|
119
|
+
type LazyMessage = DynamicValue<string, [
|
|
120
|
+
value: unknown,
|
|
121
|
+
originalMessage?: Stringable
|
|
122
|
+
]>;
|
|
123
|
+
declare function isArrayOf(inputArray: any[], currentRule: LazyRuleRunners): RuleDetailedResult;
|
|
124
|
+
interface ShapeObject extends Record<string, any>, Record<string, LazyRuleRunners> {
|
|
134
125
|
}
|
|
135
|
-
declare function loose(inputObject: Record<string, any>, shapeObject:
|
|
136
|
-
declare function optional(value: any, ruleChain:
|
|
137
|
-
declare function shape(inputObject: Record<string, any>, shapeObject:
|
|
126
|
+
declare function loose(inputObject: Record<string, any>, shapeObject: ShapeObject): RuleDetailedResult;
|
|
127
|
+
declare function optional(value: any, ruleChain: Lazy): RuleDetailedResult;
|
|
128
|
+
declare function shape(inputObject: Record<string, any>, shapeObject: ShapeObject): RuleDetailedResult;
|
|
138
129
|
// Help needed improving the typings of this file.
|
|
139
|
-
// Ideally, we'd be able to extend
|
|
130
|
+
// Ideally, we'd be able to extend ShapeObject, but that's not possible.
|
|
140
131
|
declare function partial<T extends Record<any, any>>(shapeObject: T): T;
|
|
141
132
|
declare global {
|
|
142
133
|
namespace n4s {
|
|
143
134
|
interface EnforceCustomMatchers<R> {
|
|
144
|
-
isArrayOf:
|
|
145
|
-
loose:
|
|
146
|
-
shape:
|
|
147
|
-
optional:
|
|
135
|
+
isArrayOf: EnforceCustomMatcher<typeof isArrayOf, R>;
|
|
136
|
+
loose: EnforceCustomMatcher<typeof loose, R>;
|
|
137
|
+
shape: EnforceCustomMatcher<typeof shape, R>;
|
|
138
|
+
optional: EnforceCustomMatcher<typeof optional, R>;
|
|
148
139
|
}
|
|
149
140
|
}
|
|
150
141
|
}
|
|
151
142
|
export { partial };
|
|
143
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/exports/schema.ts","../src/lib/enforceUtilityTypes.ts","../src/runtime/enforceContext.ts","../src/lib/ruleReturn.ts","../src/rules/endsWith.ts","../src/rules/equals.ts","../src/rules/greaterThanOrEquals.ts","../src/rules/inside.ts","../src/rules/lessThan.ts","../src/rules/lessThanOrEquals.ts","../src/rules/isBetween.ts","../src/rules/isBlank.ts","../src/rules/isBoolean.ts","../src/rules/isEven.ts","../src/rules/isKeyOf.ts","../src/rules/isNaN.ts","../src/rules/isNegative.ts","../src/rules/isNumber.ts","../src/rules/isOdd.ts","../src/rules/isString.ts","../src/rules/isTruthy.ts","../src/rules/isValueOf.ts","../src/rules/longerThanOrEquals.ts","../src/rules/matches.ts","../src/rules/ruleCondition.ts","../src/rules/shorterThan.ts","../src/rules/shorterThanOrEquals.ts","../src/rules/startsWith.ts","../src/runtime/rules.ts","../src/runtime/runtimeRules.ts","../src/lib/transformResult.ts","../src/runtime/genEnforceLazy.ts","../src/lib/runLazyRule.ts","../src/plugins/schema/isArrayOf.ts","../src/plugins/schema/schemaTypes.ts","../src/plugins/schema/loose.ts","../src/plugins/schema/optional.ts","../src/plugins/schema/shape.ts","../src/plugins/schema/partial.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,QAAQ,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,qBAAqB,CAAC,CAAC;YAC/B,SAAS,EAAE,oBAAoB,CAAC,OAAO,SAAS,EAAE,CAAC,CAAC,CAAC;YACrD,KAAK,EAAE,oBAAoB,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;YAC7C,KAAK,EAAE,oBAAoB,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC;YAC7C,QAAQ,EAAE,oBAAoB,CAAC,OAAO,QAAQ,EAAE,CAAC,CAAC,CAAC;SACpD;KACF;CACF;AAdD,OAAO,WAAW,CAAgB"}
|
package/docs/.nojekyll
DELETED
|
File without changes
|
package/docs/README.md
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Enforce - n4s
|
|
2
|
-
|
|
3
|
-
Enforce is a validations assertions library. It provides rules that you can test your data against.
|
|
4
|
-
|
|
5
|
-
By default, enforce throws an error when your validations fail. These errors should be caught by a validation testing framework such as [Vest](https://github.com/ealush/vest).
|
|
6
|
-
|
|
7
|
-
You can extend Enforce per need, and you can add your custom validation rules in your app.
|
|
8
|
-
|
|
9
|
-
```js
|
|
10
|
-
import { enforce } from 'n4s';
|
|
11
|
-
|
|
12
|
-
enforce(4).isNumber();
|
|
13
|
-
// passes
|
|
14
|
-
|
|
15
|
-
enforce(4).isNumber().greaterThan(2);
|
|
16
|
-
// passes
|
|
17
|
-
|
|
18
|
-
enforce(4)
|
|
19
|
-
.lessThan(2) // throws an error, will not carry on to the next rule
|
|
20
|
-
.greaterThan(3);
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Installation
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
npm i n4s
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Non throwing validations
|
|
30
|
-
|
|
31
|
-
> This functionality replaces the no-longer supported ensure export, as it performs the same functionality with better performance.
|
|
32
|
-
|
|
33
|
-
If you wish to use enforce's functionality safely with a boolean return interface instead, you can use its lazy validation interface:
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
enforce.isArray().longerThan(3).test([1, 2, 3]);
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Content
|
|
40
|
-
|
|
41
|
-
- [List of Enforce rules](./rules)
|
|
42
|
-
- [Business reated rules](./business_rules)
|
|
43
|
-
- [Schema validation](./shape)
|
|
44
|
-
- [Custom Enforce Rules](./custom)
|
package/docs/_sidebar.md
DELETED
package/docs/external.md
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Consuming external rules
|
|
2
|
-
|
|
3
|
-
Enforce comes with the bare minimum of rules needed for input validation, not assuming your business logic constraints.
|
|
4
|
-
|
|
5
|
-
In some cases you might require more validations such as `isEmail` or `isPhoneNumber`. Enforce intentionally does not include those, since those validations may not necessarily reflect the way those validations should work in your app.
|
|
6
|
-
|
|
7
|
-
Luckily, there are numerous packages that can be used along with enforce to add those validations. One of the most popular, and most compatible is `validator.js`.
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
npm i validator
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Validator.js is a pretty big package. To prevent it from unnecessarily increasing your bundle size for rules you don't use, import the ones you use individually.
|
|
14
|
-
|
|
15
|
-
Then add those rules with `enforce.extend`:
|
|
16
|
-
|
|
17
|
-
```js
|
|
18
|
-
import isEmail from 'validator/es/lib/isEmail';
|
|
19
|
-
import isMobilePhone from 'validator/es/lib/isMobilePhone';
|
|
20
|
-
|
|
21
|
-
enforce.extend({ isEmail, isMobilePhone });
|
|
22
|
-
|
|
23
|
-
enforce('example@example.com').isEmail(); // ✅
|
|
24
|
-
enforce('example[at]example[dot]com').isEmail(); // 🚨
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
A full list of the supported validator.js rules can be found on [npmjs.com/package/validator](https://www.npmjs.com/package/validator).
|
package/docs/index.html
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<title>n4s - Enforce - Validation assertions library</title>
|
|
6
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
7
|
-
<meta
|
|
8
|
-
name="description"
|
|
9
|
-
content="Enforce - Validation assertions library"
|
|
10
|
-
/>
|
|
11
|
-
<meta
|
|
12
|
-
name="viewport"
|
|
13
|
-
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
|
|
14
|
-
/>
|
|
15
|
-
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css" />
|
|
16
|
-
</head>
|
|
17
|
-
<body>
|
|
18
|
-
<div id="app"></div>
|
|
19
|
-
<script>
|
|
20
|
-
window.$docsify = {
|
|
21
|
-
name: 'n4s - enforce',
|
|
22
|
-
repo: 'https://github.com/ealush/n4s',
|
|
23
|
-
search: 'auto',
|
|
24
|
-
loadSidebar: true,
|
|
25
|
-
subMaxLevel: 2,
|
|
26
|
-
themeColor: '#539BDB',
|
|
27
|
-
};
|
|
28
|
-
</script>
|
|
29
|
-
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
|
30
|
-
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
|
31
|
-
</body>
|
|
32
|
-
</html>
|