n4s 4.1.9 → 4.2.2-dev-fcaa09
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/dist/cjs/compose.development.js +1 -1
- package/dist/cjs/compose.production.js +1 -1
- package/dist/cjs/compounds.development.js +1 -1
- package/dist/cjs/compounds.production.js +1 -1
- package/dist/cjs/n4s.development.js +2 -2
- package/dist/cjs/n4s.production.js +1 -1
- package/dist/cjs/schema.development.js +1 -1
- package/dist/cjs/schema.production.js +1 -1
- package/dist/es/compose.development.js +1 -1
- package/dist/es/compose.production.js +1 -1
- package/dist/es/compounds.development.js +1 -1
- package/dist/es/compounds.production.js +1 -1
- package/dist/es/n4s.development.js +3 -3
- package/dist/es/n4s.production.js +1 -1
- package/dist/es/schema.development.js +1 -1
- package/dist/es/schema.production.js +1 -1
- package/dist/umd/compose.development.js +8 -62
- package/dist/umd/compose.production.js +1 -1
- package/dist/umd/compounds.development.js +11 -55
- package/dist/umd/compounds.production.js +1 -1
- package/dist/umd/n4s.development.js +71 -268
- package/dist/umd/n4s.production.js +1 -1
- package/dist/umd/schema.development.js +8 -61
- package/dist/umd/schema.production.js +1 -1
- package/package.json +3 -3
- package/tsconfig.json +55 -1
- package/types/compose.d.ts +16 -20
- package/types/compose.d.ts.map +1 -0
- package/types/compounds.d.ts +22 -29
- package/types/compounds.d.ts.map +1 -0
- package/types/n4s.d.ts +18 -28
- package/types/n4s.d.ts.map +1 -0
- package/types/schema.d.ts +21 -24
- package/types/schema.d.ts.map +1 -0
|
@@ -1,206 +1,60 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function bindNot(fn) {
|
|
8
|
-
return function () {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
return !fn.apply(void 0, args);
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isNumeric(value) {
|
|
18
|
-
var str = String(value);
|
|
19
|
-
var num = Number(value);
|
|
20
|
-
var result = !isNaN(parseFloat(str)) && !isNaN(Number(value)) && isFinite(num);
|
|
21
|
-
return Boolean(result);
|
|
22
|
-
}
|
|
23
|
-
var isNotNumeric = bindNot(isNumeric);
|
|
24
|
-
|
|
25
|
-
function numberEquals(value, eq) {
|
|
26
|
-
return isNumeric(value) && isNumeric(eq) && Number(value) === Number(eq);
|
|
27
|
-
}
|
|
28
|
-
var numberNotEquals = bindNot(numberEquals);
|
|
29
|
-
|
|
30
|
-
function lengthEquals(value, arg1) {
|
|
31
|
-
return numberEquals(value.length, arg1);
|
|
32
|
-
}
|
|
33
|
-
var lengthNotEquals = bindNot(lengthEquals);
|
|
34
|
-
|
|
35
|
-
function greaterThan(value, gt) {
|
|
36
|
-
return isNumeric(value) && isNumeric(gt) && Number(value) > Number(gt);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function longerThan(value, arg1) {
|
|
40
|
-
return greaterThan(value.length, arg1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function isNull(value) {
|
|
44
|
-
return value === null;
|
|
45
|
-
}
|
|
46
|
-
var isNotNull = bindNot(isNull);
|
|
47
|
-
|
|
48
|
-
function isUndefined(value) {
|
|
49
|
-
return value === undefined;
|
|
50
|
-
}
|
|
51
|
-
var isNotUndefined = bindNot(isUndefined);
|
|
52
|
-
|
|
53
|
-
function isNullish(value) {
|
|
54
|
-
return isNull(value) || isUndefined(value);
|
|
55
|
-
}
|
|
56
|
-
var isNotNullish = bindNot(isNullish);
|
|
57
|
-
|
|
58
|
-
function isFunction(value) {
|
|
59
|
-
return typeof value === 'function';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function optionalFunctionValue(value) {
|
|
63
|
-
var args = [];
|
|
64
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
65
|
-
args[_i - 1] = arguments[_i];
|
|
66
|
-
}
|
|
67
|
-
return isFunction(value) ? value.apply(void 0, args) : value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function defaultTo(value, defaultValue) {
|
|
71
|
-
var _a;
|
|
72
|
-
return (_a = optionalFunctionValue(value)) !== null && _a !== void 0 ? _a : optionalFunctionValue(defaultValue);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// The module is named "isArrayValue" since it
|
|
76
|
-
// is conflicting with a nested npm dependency.
|
|
77
|
-
// We may need to revisit this in the future.
|
|
78
|
-
function isArray(value) {
|
|
79
|
-
return Boolean(Array.isArray(value));
|
|
80
|
-
}
|
|
81
|
-
var isNotArray = bindNot(isArray);
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* A safe hasOwnProperty access
|
|
85
|
-
*/
|
|
86
|
-
function hasOwnProperty(obj, key) {
|
|
87
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var assign = Object.assign;
|
|
91
|
-
|
|
92
|
-
function invariant(condition,
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
94
|
-
message) {
|
|
95
|
-
if (condition) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
// If message is a string object (rather than string literal)
|
|
99
|
-
// Throw the value directly as a string
|
|
100
|
-
// Alternatively, throw an error with the message
|
|
101
|
-
throw message instanceof String
|
|
102
|
-
? message.valueOf()
|
|
103
|
-
: new Error(message ? optionalFunctionValue(message) : message);
|
|
104
|
-
}
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
106
|
-
function StringObject(value) {
|
|
107
|
-
return new String(optionalFunctionValue(value));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function isStringValue(v) {
|
|
111
|
-
return String(v) === v;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function isBoolean(value) {
|
|
115
|
-
return !!value === value;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function mapFirst(array, callback) {
|
|
119
|
-
var broke = false;
|
|
120
|
-
var breakoutValue = null;
|
|
121
|
-
for (var i = 0; i < array.length; i++) {
|
|
122
|
-
callback(array[i], breakout, i);
|
|
123
|
-
if (broke) {
|
|
124
|
-
return breakoutValue;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function breakout(conditional, value) {
|
|
128
|
-
if (conditional) {
|
|
129
|
-
broke = true;
|
|
130
|
-
breakoutValue = value;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function isEmpty(value) {
|
|
136
|
-
if (!value) {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
else if (hasOwnProperty(value, 'length')) {
|
|
140
|
-
return lengthEquals(value, 0);
|
|
141
|
-
}
|
|
142
|
-
else if (typeof value === 'object') {
|
|
143
|
-
return lengthEquals(Object.keys(value), 0);
|
|
144
|
-
}
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
var isNotEmpty = bindNot(isEmpty);
|
|
148
|
-
|
|
149
|
-
function isPositive(value) {
|
|
150
|
-
return greaterThan(value, 0);
|
|
151
|
-
}
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest-utils'), require('context')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vest-utils', 'context'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.n4s = {}, global['vest-utils'], global.context));
|
|
5
|
+
}(this, (function (exports, vestUtils, context) { 'use strict';
|
|
152
6
|
|
|
153
7
|
function endsWith(value, arg1) {
|
|
154
|
-
return isStringValue(value) && isStringValue(arg1) && value.endsWith(arg1);
|
|
8
|
+
return vestUtils.isStringValue(value) && vestUtils.isStringValue(arg1) && value.endsWith(arg1);
|
|
155
9
|
}
|
|
156
|
-
var doesNotEndWith = bindNot(endsWith);
|
|
10
|
+
var doesNotEndWith = vestUtils.bindNot(endsWith);
|
|
157
11
|
|
|
158
12
|
function equals(value, arg1) {
|
|
159
13
|
return value === arg1;
|
|
160
14
|
}
|
|
161
|
-
var notEquals = bindNot(equals);
|
|
15
|
+
var notEquals = vestUtils.bindNot(equals);
|
|
162
16
|
|
|
163
17
|
function greaterThanOrEquals(value, gte) {
|
|
164
|
-
return numberEquals(value, gte) || greaterThan(value, gte);
|
|
18
|
+
return vestUtils.numberEquals(value, gte) || vestUtils.greaterThan(value, gte);
|
|
165
19
|
}
|
|
166
20
|
|
|
167
21
|
function inside(value, arg1) {
|
|
168
|
-
if (isArray(arg1)) {
|
|
22
|
+
if (vestUtils.isArray(arg1)) {
|
|
169
23
|
return arg1.indexOf(value) !== -1;
|
|
170
24
|
}
|
|
171
25
|
// both value and arg1 are strings
|
|
172
|
-
if (isStringValue(arg1) && isStringValue(value)) {
|
|
26
|
+
if (vestUtils.isStringValue(arg1) && vestUtils.isStringValue(value)) {
|
|
173
27
|
return arg1.indexOf(value) !== -1;
|
|
174
28
|
}
|
|
175
29
|
return false;
|
|
176
30
|
}
|
|
177
|
-
var notInside = bindNot(inside);
|
|
31
|
+
var notInside = vestUtils.bindNot(inside);
|
|
178
32
|
|
|
179
33
|
function lessThan(value, lt) {
|
|
180
|
-
return isNumeric(value) && isNumeric(lt) && Number(value) < Number(lt);
|
|
34
|
+
return vestUtils.isNumeric(value) && vestUtils.isNumeric(lt) && Number(value) < Number(lt);
|
|
181
35
|
}
|
|
182
36
|
|
|
183
37
|
function lessThanOrEquals(value, lte) {
|
|
184
|
-
return numberEquals(value, lte) || lessThan(value, lte);
|
|
38
|
+
return vestUtils.numberEquals(value, lte) || lessThan(value, lte);
|
|
185
39
|
}
|
|
186
40
|
|
|
187
41
|
function isBetween(value, min, max) {
|
|
188
42
|
return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
|
|
189
43
|
}
|
|
190
|
-
var isNotBetween = bindNot(isBetween);
|
|
44
|
+
var isNotBetween = vestUtils.bindNot(isBetween);
|
|
191
45
|
|
|
192
46
|
function isBlank(value) {
|
|
193
|
-
return isNullish(value) || (isStringValue(value) && !value.trim());
|
|
47
|
+
return vestUtils.isNullish(value) || (vestUtils.isStringValue(value) && !value.trim());
|
|
194
48
|
}
|
|
195
|
-
var isNotBlank = bindNot(isBlank);
|
|
49
|
+
var isNotBlank = vestUtils.bindNot(isBlank);
|
|
196
50
|
|
|
197
|
-
var isNotBoolean = bindNot(isBoolean);
|
|
51
|
+
var isNotBoolean = vestUtils.bindNot(vestUtils.isBoolean);
|
|
198
52
|
|
|
199
53
|
/**
|
|
200
54
|
* Validates that a given value is an even number
|
|
201
55
|
*/
|
|
202
56
|
var isEven = function (value) {
|
|
203
|
-
if (isNumeric(value)) {
|
|
57
|
+
if (vestUtils.isNumeric(value)) {
|
|
204
58
|
return value % 2 === 0;
|
|
205
59
|
}
|
|
206
60
|
return false;
|
|
@@ -209,12 +63,12 @@
|
|
|
209
63
|
function isKeyOf(key, obj) {
|
|
210
64
|
return key in obj;
|
|
211
65
|
}
|
|
212
|
-
var isNotKeyOf = bindNot(isKeyOf);
|
|
66
|
+
var isNotKeyOf = vestUtils.bindNot(isKeyOf);
|
|
213
67
|
|
|
214
|
-
function isNaN
|
|
68
|
+
function isNaN(value) {
|
|
215
69
|
return Number.isNaN(value);
|
|
216
70
|
}
|
|
217
|
-
var isNotNaN = bindNot(isNaN
|
|
71
|
+
var isNotNaN = vestUtils.bindNot(isNaN);
|
|
218
72
|
|
|
219
73
|
function isNegative(value) {
|
|
220
74
|
return lessThan(value, 0);
|
|
@@ -223,27 +77,27 @@
|
|
|
223
77
|
function isNumber(value) {
|
|
224
78
|
return Boolean(typeof value === 'number');
|
|
225
79
|
}
|
|
226
|
-
var isNotNumber = bindNot(isNumber);
|
|
80
|
+
var isNotNumber = vestUtils.bindNot(isNumber);
|
|
227
81
|
|
|
228
82
|
/**
|
|
229
83
|
* Validates that a given value is an odd number
|
|
230
84
|
*/
|
|
231
85
|
var isOdd = function (value) {
|
|
232
|
-
if (isNumeric(value)) {
|
|
86
|
+
if (vestUtils.isNumeric(value)) {
|
|
233
87
|
return value % 2 !== 0;
|
|
234
88
|
}
|
|
235
89
|
return false;
|
|
236
90
|
};
|
|
237
91
|
|
|
238
|
-
var isNotString = bindNot(isStringValue);
|
|
92
|
+
var isNotString = vestUtils.bindNot(vestUtils.isStringValue);
|
|
239
93
|
|
|
240
94
|
function isTruthy(value) {
|
|
241
95
|
return !!value;
|
|
242
96
|
}
|
|
243
|
-
var isFalsy = bindNot(isTruthy);
|
|
97
|
+
var isFalsy = vestUtils.bindNot(isTruthy);
|
|
244
98
|
|
|
245
99
|
function isValueOf(value, objectToCheck) {
|
|
246
|
-
if (isNullish(objectToCheck)) {
|
|
100
|
+
if (vestUtils.isNullish(objectToCheck)) {
|
|
247
101
|
return false;
|
|
248
102
|
}
|
|
249
103
|
for (var key in objectToCheck) {
|
|
@@ -253,7 +107,7 @@
|
|
|
253
107
|
}
|
|
254
108
|
return false;
|
|
255
109
|
}
|
|
256
|
-
var isNotValueOf = bindNot(isValueOf);
|
|
110
|
+
var isNotValueOf = vestUtils.bindNot(isValueOf);
|
|
257
111
|
|
|
258
112
|
function longerThanOrEquals(value, arg1) {
|
|
259
113
|
return greaterThanOrEquals(value.length, arg1);
|
|
@@ -263,14 +117,14 @@
|
|
|
263
117
|
if (regex instanceof RegExp) {
|
|
264
118
|
return regex.test(value);
|
|
265
119
|
}
|
|
266
|
-
else if (isStringValue(regex)) {
|
|
120
|
+
else if (vestUtils.isStringValue(regex)) {
|
|
267
121
|
return new RegExp(regex).test(value);
|
|
268
122
|
}
|
|
269
123
|
else {
|
|
270
124
|
return false;
|
|
271
125
|
}
|
|
272
126
|
}
|
|
273
|
-
var notMatches = bindNot(matches);
|
|
127
|
+
var notMatches = vestUtils.bindNot(matches);
|
|
274
128
|
|
|
275
129
|
function condition(value, callback) {
|
|
276
130
|
try {
|
|
@@ -290,9 +144,9 @@
|
|
|
290
144
|
}
|
|
291
145
|
|
|
292
146
|
function startsWith(value, arg1) {
|
|
293
|
-
return isStringValue(value) && isStringValue(arg1) && value.startsWith(arg1);
|
|
147
|
+
return vestUtils.isStringValue(value) && vestUtils.isStringValue(arg1) && value.startsWith(arg1);
|
|
294
148
|
}
|
|
295
|
-
var doesNotStartWith = bindNot(startsWith);
|
|
149
|
+
var doesNotStartWith = vestUtils.bindNot(startsWith);
|
|
296
150
|
|
|
297
151
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, max-lines-per-function
|
|
298
152
|
function rules() {
|
|
@@ -302,50 +156,50 @@
|
|
|
302
156
|
doesNotStartWith: doesNotStartWith,
|
|
303
157
|
endsWith: endsWith,
|
|
304
158
|
equals: equals,
|
|
305
|
-
greaterThan: greaterThan,
|
|
159
|
+
greaterThan: vestUtils.greaterThan,
|
|
306
160
|
greaterThanOrEquals: greaterThanOrEquals,
|
|
307
|
-
gt: greaterThan,
|
|
161
|
+
gt: vestUtils.greaterThan,
|
|
308
162
|
gte: greaterThanOrEquals,
|
|
309
163
|
inside: inside,
|
|
310
|
-
isArray: isArray,
|
|
164
|
+
isArray: vestUtils.isArray,
|
|
311
165
|
isBetween: isBetween,
|
|
312
166
|
isBlank: isBlank,
|
|
313
|
-
isBoolean: isBoolean,
|
|
314
|
-
isEmpty: isEmpty,
|
|
167
|
+
isBoolean: vestUtils.isBoolean,
|
|
168
|
+
isEmpty: vestUtils.isEmpty,
|
|
315
169
|
isEven: isEven,
|
|
316
170
|
isFalsy: isFalsy,
|
|
317
171
|
isKeyOf: isKeyOf,
|
|
318
|
-
isNaN: isNaN
|
|
172
|
+
isNaN: isNaN,
|
|
319
173
|
isNegative: isNegative,
|
|
320
|
-
isNotArray: isNotArray,
|
|
174
|
+
isNotArray: vestUtils.isNotArray,
|
|
321
175
|
isNotBetween: isNotBetween,
|
|
322
176
|
isNotBlank: isNotBlank,
|
|
323
177
|
isNotBoolean: isNotBoolean,
|
|
324
|
-
isNotEmpty: isNotEmpty,
|
|
178
|
+
isNotEmpty: vestUtils.isNotEmpty,
|
|
325
179
|
isNotKeyOf: isNotKeyOf,
|
|
326
180
|
isNotNaN: isNotNaN,
|
|
327
|
-
isNotNull: isNotNull,
|
|
328
|
-
isNotNullish: isNotNullish,
|
|
181
|
+
isNotNull: vestUtils.isNotNull,
|
|
182
|
+
isNotNullish: vestUtils.isNotNullish,
|
|
329
183
|
isNotNumber: isNotNumber,
|
|
330
|
-
isNotNumeric: isNotNumeric,
|
|
184
|
+
isNotNumeric: vestUtils.isNotNumeric,
|
|
331
185
|
isNotString: isNotString,
|
|
332
|
-
isNotUndefined: isNotUndefined,
|
|
186
|
+
isNotUndefined: vestUtils.isNotUndefined,
|
|
333
187
|
isNotValueOf: isNotValueOf,
|
|
334
|
-
isNull: isNull,
|
|
335
|
-
isNullish: isNullish,
|
|
188
|
+
isNull: vestUtils.isNull,
|
|
189
|
+
isNullish: vestUtils.isNullish,
|
|
336
190
|
isNumber: isNumber,
|
|
337
|
-
isNumeric: isNumeric,
|
|
191
|
+
isNumeric: vestUtils.isNumeric,
|
|
338
192
|
isOdd: isOdd,
|
|
339
|
-
isPositive: isPositive,
|
|
340
|
-
isString: isStringValue,
|
|
193
|
+
isPositive: vestUtils.isPositive,
|
|
194
|
+
isString: vestUtils.isStringValue,
|
|
341
195
|
isTruthy: isTruthy,
|
|
342
|
-
isUndefined: isUndefined,
|
|
196
|
+
isUndefined: vestUtils.isUndefined,
|
|
343
197
|
isValueOf: isValueOf,
|
|
344
|
-
lengthEquals: lengthEquals,
|
|
345
|
-
lengthNotEquals: lengthNotEquals,
|
|
198
|
+
lengthEquals: vestUtils.lengthEquals,
|
|
199
|
+
lengthNotEquals: vestUtils.lengthNotEquals,
|
|
346
200
|
lessThan: lessThan,
|
|
347
201
|
lessThanOrEquals: lessThanOrEquals,
|
|
348
|
-
longerThan: longerThan,
|
|
202
|
+
longerThan: vestUtils.longerThan,
|
|
349
203
|
longerThanOrEquals: longerThanOrEquals,
|
|
350
204
|
lt: lessThan,
|
|
351
205
|
lte: lessThanOrEquals,
|
|
@@ -353,8 +207,8 @@
|
|
|
353
207
|
notEquals: notEquals,
|
|
354
208
|
notInside: notInside,
|
|
355
209
|
notMatches: notMatches,
|
|
356
|
-
numberEquals: numberEquals,
|
|
357
|
-
numberNotEquals: numberNotEquals,
|
|
210
|
+
numberEquals: vestUtils.numberEquals,
|
|
211
|
+
numberNotEquals: vestUtils.numberNotEquals,
|
|
358
212
|
shorterThan: shorterThan,
|
|
359
213
|
shorterThanOrEquals: shorterThanOrEquals,
|
|
360
214
|
startsWith: startsWith
|
|
@@ -369,75 +223,24 @@
|
|
|
369
223
|
function eachEnforceRule(action) {
|
|
370
224
|
for (var ruleName in baseRules) {
|
|
371
225
|
var ruleFn = getRule(ruleName);
|
|
372
|
-
if (isFunction(ruleFn)) {
|
|
226
|
+
if (vestUtils.isFunction(ruleFn)) {
|
|
373
227
|
action(ruleName, ruleFn);
|
|
374
228
|
}
|
|
375
229
|
}
|
|
376
230
|
}
|
|
377
231
|
|
|
378
|
-
|
|
379
|
-
function createContext(init) {
|
|
380
|
-
var storage = { ancestry: [] };
|
|
381
|
-
return {
|
|
382
|
-
bind: bind,
|
|
383
|
-
run: run,
|
|
384
|
-
use: use,
|
|
385
|
-
useX: useX
|
|
386
|
-
};
|
|
387
|
-
function useX(errorMessage) {
|
|
388
|
-
var ctx = use();
|
|
389
|
-
invariant(ctx, defaultTo(errorMessage, 'Context was used after it was closed'));
|
|
390
|
-
return ctx;
|
|
391
|
-
}
|
|
392
|
-
function run(ctxRef, fn) {
|
|
393
|
-
var _a;
|
|
394
|
-
var parentContext = use();
|
|
395
|
-
var out = assign({}, parentContext ? parentContext : {}, (_a = optionalFunctionValue(init, ctxRef, parentContext)) !== null && _a !== void 0 ? _a : ctxRef);
|
|
396
|
-
var ctx = set(Object.freeze(out));
|
|
397
|
-
storage.ancestry.unshift(ctx);
|
|
398
|
-
var res = fn(ctx);
|
|
399
|
-
clear();
|
|
400
|
-
return res;
|
|
401
|
-
}
|
|
402
|
-
function bind(ctxRef, fn) {
|
|
403
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
404
|
-
// @ts-ignore - this one's pretty hard to get right
|
|
405
|
-
var returnedFn = function () {
|
|
406
|
-
var runTimeArgs = [];
|
|
407
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
408
|
-
runTimeArgs[_i] = arguments[_i];
|
|
409
|
-
}
|
|
410
|
-
return run(ctxRef, function () {
|
|
411
|
-
return fn.apply(void 0, runTimeArgs);
|
|
412
|
-
});
|
|
413
|
-
};
|
|
414
|
-
return returnedFn;
|
|
415
|
-
}
|
|
416
|
-
function use() {
|
|
417
|
-
return storage.ctx;
|
|
418
|
-
}
|
|
419
|
-
function set(value) {
|
|
420
|
-
return (storage.ctx = value);
|
|
421
|
-
}
|
|
422
|
-
function clear() {
|
|
423
|
-
var _a;
|
|
424
|
-
storage.ancestry.shift();
|
|
425
|
-
set((_a = storage.ancestry[0]) !== null && _a !== void 0 ? _a : null);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
var ctx = createContext(function (ctxRef, parentContext) {
|
|
232
|
+
var ctx = context.createCascade(function (ctxRef, parentContext) {
|
|
430
233
|
var base = {
|
|
431
234
|
value: ctxRef.value,
|
|
432
235
|
meta: ctxRef.meta || {}
|
|
433
236
|
};
|
|
434
237
|
if (!parentContext) {
|
|
435
|
-
return assign(base, {
|
|
238
|
+
return vestUtils.assign(base, {
|
|
436
239
|
parent: emptyParent
|
|
437
240
|
});
|
|
438
241
|
}
|
|
439
242
|
else if (ctxRef.set) {
|
|
440
|
-
return assign(base, {
|
|
243
|
+
return vestUtils.assign(base, {
|
|
441
244
|
parent: function () { return stripContext(parentContext); }
|
|
442
245
|
});
|
|
443
246
|
}
|
|
@@ -445,7 +248,7 @@
|
|
|
445
248
|
});
|
|
446
249
|
function stripContext(ctx) {
|
|
447
250
|
if (!ctx) {
|
|
448
|
-
return
|
|
251
|
+
return null;
|
|
449
252
|
}
|
|
450
253
|
return {
|
|
451
254
|
value: ctx.value,
|
|
@@ -484,7 +287,7 @@
|
|
|
484
287
|
|
|
485
288
|
function isProxySupported() {
|
|
486
289
|
try {
|
|
487
|
-
return isFunction(Proxy);
|
|
290
|
+
return vestUtils.isFunction(Proxy);
|
|
488
291
|
}
|
|
489
292
|
catch (_a) {
|
|
490
293
|
return false;
|
|
@@ -502,7 +305,7 @@
|
|
|
502
305
|
return ruleReturn(true);
|
|
503
306
|
}
|
|
504
307
|
function defaultToPassing(callback) {
|
|
505
|
-
return defaultTo(callback, passing());
|
|
308
|
+
return vestUtils.defaultTo(callback, passing());
|
|
506
309
|
}
|
|
507
310
|
|
|
508
311
|
/**
|
|
@@ -515,16 +318,16 @@
|
|
|
515
318
|
}
|
|
516
319
|
validateResult(result);
|
|
517
320
|
// if result is boolean
|
|
518
|
-
if (isBoolean(result)) {
|
|
321
|
+
if (vestUtils.isBoolean(result)) {
|
|
519
322
|
return ruleReturn(result);
|
|
520
323
|
}
|
|
521
324
|
else {
|
|
522
|
-
return ruleReturn(result.pass, optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args, false)));
|
|
325
|
+
return ruleReturn(result.pass, vestUtils.optionalFunctionValue.apply(void 0, __spreadArray([result.message, ruleName, value], args, false)));
|
|
523
326
|
}
|
|
524
327
|
}
|
|
525
328
|
function validateResult(result) {
|
|
526
329
|
// if result is boolean, or if result.pass is boolean
|
|
527
|
-
invariant(isBoolean(result) || (result && isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
|
|
330
|
+
vestUtils.invariant(vestUtils.isBoolean(result) || (result && vestUtils.isBoolean(result.pass)), 'Incorrect return value for rule: ' + JSON.stringify(result));
|
|
528
331
|
}
|
|
529
332
|
|
|
530
333
|
function enforceEager(value) {
|
|
@@ -570,9 +373,9 @@
|
|
|
570
373
|
});
|
|
571
374
|
// On rule failure (the result is false), we either throw an error
|
|
572
375
|
// or throw a string value if the rule has a message defined in it.
|
|
573
|
-
invariant(transformedResult.pass, isNullish(transformedResult.message)
|
|
376
|
+
vestUtils.invariant(transformedResult.pass, vestUtils.isNullish(transformedResult.message)
|
|
574
377
|
? "enforce/".concat(ruleName, " failed with ").concat(JSON.stringify(value))
|
|
575
|
-
: StringObject(transformedResult.message));
|
|
378
|
+
: vestUtils.StringObject(transformedResult.message));
|
|
576
379
|
return target;
|
|
577
380
|
};
|
|
578
381
|
}
|
|
@@ -597,10 +400,10 @@
|
|
|
597
400
|
});
|
|
598
401
|
var proxy = {
|
|
599
402
|
run: function (value) {
|
|
600
|
-
return defaultToPassing(mapFirst(registeredRules, function (rule, breakout) {
|
|
403
|
+
return defaultToPassing(vestUtils.mapFirst(registeredRules, function (rule, breakout) {
|
|
601
404
|
var _a;
|
|
602
405
|
var res = ctx.run({ value: value }, function () { return rule(value); });
|
|
603
|
-
breakout(!res.pass, ruleReturn(!!res.pass, (_a = optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
406
|
+
breakout(!res.pass, ruleReturn(!!res.pass, (_a = vestUtils.optionalFunctionValue(lazyMessage, value, res.message)) !== null && _a !== void 0 ? _a : res.message));
|
|
604
407
|
}));
|
|
605
408
|
},
|
|
606
409
|
test: function (value) { return proxy.run(value).pass; },
|
|
@@ -662,12 +465,12 @@
|
|
|
662
465
|
var target = {
|
|
663
466
|
context: function () { return ctx.useX(); },
|
|
664
467
|
extend: function (customRules) {
|
|
665
|
-
assign(baseRules, customRules);
|
|
468
|
+
vestUtils.assign(baseRules, customRules);
|
|
666
469
|
handleNoProxy(); // TODO: REMOVE when we stop supporting ES5
|
|
667
470
|
}
|
|
668
471
|
};
|
|
669
472
|
handleNoProxy();
|
|
670
|
-
return new Proxy(assign(enforceEager, target), {
|
|
473
|
+
return new Proxy(vestUtils.assign(enforceEager, target), {
|
|
671
474
|
get: function (target, key) {
|
|
672
475
|
if (key in target) {
|
|
673
476
|
return target[key];
|
|
@@ -685,7 +488,7 @@
|
|
|
685
488
|
// Only on the first rule access - start the chain of calls
|
|
686
489
|
target[ruleName] = genEnforceLazy(ruleName);
|
|
687
490
|
});
|
|
688
|
-
return assign(enforceEager, target);
|
|
491
|
+
return vestUtils.assign(enforceEager, target);
|
|
689
492
|
}
|
|
690
493
|
}
|
|
691
494
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).n4s={}
|
|
1
|
+
"use strict";!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vest-utils"),require("context")):"function"==typeof define&&define.amd?define(["exports","vest-utils","context"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).n4s={},n["vest-utils"],n.context)}(this,(function(n,t,e){function i(n,e){return t.isStringValue(n)&&t.isStringValue(e)&&n.endsWith(e)}function r(n,t){return n===t}function u(n,e){return t.numberEquals(n,e)||t.greaterThan(n,e)}function s(n,e){return!!(t.isArray(e)||t.isStringValue(e)&&t.isStringValue(n))&&-1!==e.indexOf(n)}function o(n,e){return t.isNumeric(n)&&t.isNumeric(e)&&Number(n)<Number(e)}function a(n,e){return t.numberEquals(n,e)||o(n,e)}function l(n,t,e){return u(n,t)&&a(n,e)}function c(n){return t.isNullish(n)||t.isStringValue(n)&&!n.trim()}function f(n,t){return n in t}function N(n){return Number.isNaN(n)}function g(n){return"number"==typeof n}function d(n){return!!n}function h(n,e){if(t.isNullish(e))return!1;for(var i in e)if(e[i]===n)return!0;return!1}function p(n,e){return e instanceof RegExp?e.test(n):!!t.isStringValue(e)&&new RegExp(e).test(n)}function m(n,e){return t.isStringValue(n)&&t.isStringValue(e)&&n.startsWith(e)}function v(n){for(var e in K){var i=K[e];t.isFunction(i)&&n(e,i)}}function y(){return null}function b(n,t,e){if(e||2===arguments.length)for(var i,r=0,u=t.length;r<u;r++)!i&&r in t||(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return n.concat(i||Array.prototype.slice.call(t))}function E(){try{return t.isFunction(Proxy)}catch(n){return!1}}function q(n,t){return n={pass:n},t&&(n.message=t),n}function x(n,e,i){for(var r=[],u=3;u<arguments.length;u++)r[u-3]=arguments[u];return t.invariant(t.isBoolean(n)||n&&t.isBoolean(n.pass),"Incorrect return value for rule: "+JSON.stringify(n)),t.isBoolean(n)?q(n):q(n.pass,t.optionalFunctionValue.apply(void 0,b([n.message,e,i],r,!1)))}function S(n){function e(e,i,r){return function(){for(var u=[],s=0;s<arguments.length;s++)u[s]=arguments[s];return s=M.run({value:n},(function(){return x.apply(void 0,b([i.apply(void 0,b([n],u,!1)),r,n],u,!1))})),t.invariant(s.pass,t.isNullish(s.message)?"enforce/".concat(r," failed with ").concat(JSON.stringify(n)):t.StringObject(s.message)),e}}var i={};if(!E())return v((function(n,t){i[n]=e(i,t,n)})),i;var r=new Proxy(i,{get:function(n,t){if(n=K[t])return e(r,n,t)}});return r}function T(n){var e,i=[];return function n(r){return function(){for(var u=[],s=0;s<arguments.length;s++)u[s]=arguments[s];var o=K[r];i.push((function(n){return x.apply(void 0,b([o.apply(void 0,b([n],u,!1)),r,n],u,!1))}));var a={run:function(n){return t.defaultTo(t.mapFirst(i,(function(i,r){var u,s=M.run({value:n},(function(){return i(n)}));r(!s.pass,q(!!s.pass,null!==(u=t.optionalFunctionValue(e,n,s.message))&&void 0!==u?u:s.message))})),q(!0))},test:function(n){return a.run(n).pass},message:function(n){return n&&(e=n),a}};return E()?a=new Proxy(a,{get:function(t,e){return K[e]?n(e):t[e]}}):(v((function(t){a[t]=n(t)})),a)}}(n)}var O=t.bindNot(i),V=t.bindNot(r),B=t.bindNot(s),w=t.bindNot(l),A=t.bindNot(c),P=t.bindNot(t.isBoolean),F=t.bindNot(f),W=t.bindNot(N),U=t.bindNot(g),j=t.bindNot(t.isStringValue),k=t.bindNot(d),I=t.bindNot(h),J=t.bindNot(p),K={condition:function(n,t){try{return t(n)}catch(n){return!1}},doesNotEndWith:O,doesNotStartWith:t.bindNot(m),endsWith:i,equals:r,greaterThan:t.greaterThan,greaterThanOrEquals:u,gt:t.greaterThan,gte:u,inside:s,isArray:t.isArray,isBetween:l,isBlank:c,isBoolean:t.isBoolean,isEmpty:t.isEmpty,isEven:function(n){return!!t.isNumeric(n)&&0==n%2},isFalsy:k,isKeyOf:f,isNaN:N,isNegative:function(n){return o(n,0)},isNotArray:t.isNotArray,isNotBetween:w,isNotBlank:A,isNotBoolean:P,isNotEmpty:t.isNotEmpty,isNotKeyOf:F,isNotNaN:W,isNotNull:t.isNotNull,isNotNullish:t.isNotNullish,isNotNumber:U,isNotNumeric:t.isNotNumeric,isNotString:j,isNotUndefined:t.isNotUndefined,isNotValueOf:I,isNull:t.isNull,isNullish:t.isNullish,isNumber:g,isNumeric:t.isNumeric,isOdd:function(n){return!!t.isNumeric(n)&&0!=n%2},isPositive:t.isPositive,isString:t.isStringValue,isTruthy:d,isUndefined:t.isUndefined,isValueOf:h,lengthEquals:t.lengthEquals,lengthNotEquals:t.lengthNotEquals,lessThan:o,lessThanOrEquals:a,longerThan:t.longerThan,longerThanOrEquals:function(n,t){return u(n.length,t)},lt:o,lte:a,matches:p,notEquals:V,notInside:B,notMatches:J,numberEquals:t.numberEquals,numberNotEquals:t.numberNotEquals,shorterThan:function(n,t){return o(n.length,t)},shorterThanOrEquals:function(n,t){return a(n.length,t)},startsWith:m},M=e.createCascade((function(n,e){var i={value:n.value,meta:n.meta||{}};return e?n.set?t.assign(i,{parent:function(){return e?{value:e.value,meta:e.meta,parent:e.parent}:null}}):e:t.assign(i,{parent:y})}));e=function(){function n(){if(!E())return v((function(n){e[n]=T(n)})),t.assign(S,e)}var e={context:function(){return M.useX()},extend:function(e){t.assign(K,e),n()}};return n(),new Proxy(t.assign(S,e),{get:function(n,t){return t in n?n[t]:K[t]?T(t):void 0}})}(),n.ctx=M,n.enforce=e,Object.defineProperty(n,"__esModule",{value:!0})}));
|