n4s 2.2.0-rc.1 → 4.0.0-dev-e266d9
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 +129 -0
- package/LICENSE +1 -2
- package/README.md +10 -4
- package/compose/package.json +7 -0
- package/compounds/package.json +7 -0
- package/dist/cjs/compose.development.js +139 -0
- package/dist/cjs/compose.js +7 -0
- package/dist/cjs/compose.production.js +1 -0
- package/dist/cjs/compounds.development.js +132 -0
- package/dist/cjs/compounds.js +7 -0
- package/dist/cjs/compounds.production.js +1 -0
- package/dist/cjs/n4s.development.js +602 -0
- package/dist/cjs/n4s.js +7 -0
- package/dist/cjs/n4s.production.js +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/schema.development.js +144 -0
- package/dist/cjs/schema.js +7 -0
- package/dist/cjs/schema.production.js +1 -0
- package/dist/es/compose.development.js +137 -0
- package/dist/es/compose.production.js +1 -0
- package/dist/es/compounds.development.js +130 -0
- package/dist/es/compounds.production.js +1 -0
- package/dist/es/n4s.development.js +597 -0
- package/dist/es/n4s.production.js +1 -0
- package/dist/es/package.json +1 -0
- package/dist/es/schema.development.js +140 -0
- package/dist/es/schema.production.js +1 -0
- package/dist/umd/compose.development.js +143 -0
- package/dist/umd/compose.production.js +1 -0
- package/dist/umd/compounds.development.js +136 -0
- package/dist/umd/compounds.production.js +1 -0
- package/dist/umd/n4s.development.js +606 -0
- package/dist/umd/n4s.production.js +1 -0
- package/dist/umd/schema.development.js +148 -0
- package/dist/umd/schema.production.js +1 -0
- package/docs/README.md +10 -4
- package/docs/_sidebar.md +2 -2
- package/docs/external.md +27 -0
- package/docs/rules.md +74 -0
- package/package.json +126 -67
- package/schema/package.json +7 -0
- package/tsconfig.json +8 -0
- package/types/compose.d.ts +134 -0
- package/types/compounds.d.ts +146 -0
- package/types/n4s.d.ts +167 -0
- package/types/schema.d.ts +151 -0
- package/config/rollup/enforce.js +0 -13
- package/config/rollup/enforceExtended.js +0 -10
- package/config/rollup/ensure.js +0 -10
- package/config/rollup/rollup.config.js +0 -5
- package/docs/business_rules.md +0 -80
- package/docs/custom.md +0 -54
- package/docs/ensure.md +0 -40
- package/enforceExtended.cjs.development.js +0 -1949
- package/enforceExtended.cjs.production.js +0 -1949
- package/enforceExtended.cjs.production.min.js +0 -1
- package/enforceExtended.umd.development.js +0 -1955
- package/enforceExtended.umd.production.js +0 -1972
- package/enforceExtended.umd.production.min.js +0 -1
- package/ensure.cjs.development.js +0 -418
- package/ensure.cjs.production.js +0 -418
- package/ensure.cjs.production.min.js +0 -1
- package/ensure.umd.development.js +0 -424
- package/ensure.umd.production.js +0 -444
- package/ensure.umd.production.min.js +0 -1
- package/esm/enforceExtended.mjs.development.js +0 -1947
- package/esm/enforceExtended.mjs.production.js +0 -1947
- package/esm/enforceExtended.mjs.production.min.js +0 -1
- package/esm/ensure.mjs.development.js +0 -416
- package/esm/ensure.mjs.production.js +0 -416
- package/esm/ensure.mjs.production.min.js +0 -1
- package/esm/n4s.mjs.development.js +0 -394
- package/esm/n4s.mjs.production.js +0 -394
- package/esm/n4s.mjs.production.min.js +0 -1
- package/esm/package.json +0 -1
- package/jest.config.js +0 -3
- package/n4s.cjs.development.js +0 -396
- package/n4s.cjs.production.js +0 -396
- package/n4s.cjs.production.min.js +0 -1
- package/n4s.umd.development.js +0 -402
- package/n4s.umd.index.js +0 -7
- package/n4s.umd.production.js +0 -419
- package/n4s.umd.production.min.js +0 -1
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function (target) {
|
|
3
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
|
|
6
|
-
for (var key in source) {
|
|
7
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
|
-
target[key] = source[key];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return target;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
return _extends.apply(this, arguments);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function throwError(message) {
|
|
20
|
-
throw new Error(`[${"ensure"}]: ${message}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const isRule = (rulesObject, name) => {
|
|
24
|
-
const ruleExists = Object.prototype.hasOwnProperty.call(rulesObject, name) && typeof rulesObject[name] === 'function';
|
|
25
|
-
|
|
26
|
-
if (!ruleExists) {
|
|
27
|
-
throwError(`Rule "${name}" was not found in rules object. Make sure you typed it correctly.`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return ruleExists;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const GLOBAL_OBJECT = Function('return this')();
|
|
34
|
-
|
|
35
|
-
const proxySupported = () => typeof GLOBAL_OBJECT.Proxy === 'function';
|
|
36
|
-
|
|
37
|
-
function bindNot(fn) {
|
|
38
|
-
return function () {
|
|
39
|
-
return !fn.apply(this, arguments);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function endsWith(value, arg1) {
|
|
44
|
-
return typeof value === 'string' && typeof arg1 === 'string' && value.endsWith(arg1);
|
|
45
|
-
}
|
|
46
|
-
const doesNotEndWith = bindNot(endsWith);
|
|
47
|
-
|
|
48
|
-
function equals(value, arg1) {
|
|
49
|
-
return value === arg1;
|
|
50
|
-
}
|
|
51
|
-
const notEquals = bindNot(equals);
|
|
52
|
-
|
|
53
|
-
function isNumeric(value) {
|
|
54
|
-
const result = !isNaN(parseFloat(value)) && !isNaN(Number(value)) && isFinite(value);
|
|
55
|
-
return Boolean(result);
|
|
56
|
-
}
|
|
57
|
-
const isNotNumeric = bindNot(isNumeric);
|
|
58
|
-
|
|
59
|
-
function greaterThan(value, arg1) {
|
|
60
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) > Number(arg1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function greaterThanOrEquals(value, arg1) {
|
|
64
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) >= Number(arg1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function inside(value, arg1) {
|
|
68
|
-
if (Array.isArray(arg1) && ['string', 'number', 'boolean'].indexOf(typeof value) !== -1) {
|
|
69
|
-
return arg1.indexOf(value) !== -1;
|
|
70
|
-
} // both value and arg1 are strings
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (typeof arg1 === 'string' && typeof value === 'string') {
|
|
74
|
-
return arg1.indexOf(value) !== -1;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
const notInside = bindNot(inside);
|
|
80
|
-
|
|
81
|
-
function isArray(value) {
|
|
82
|
-
return Boolean(Array.isArray(value));
|
|
83
|
-
}
|
|
84
|
-
const isNotArray = bindNot(isArray);
|
|
85
|
-
|
|
86
|
-
function lessThanOrEquals(value, arg1) {
|
|
87
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) <= Number(arg1);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function isBetween(value, min, max) {
|
|
91
|
-
return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
|
|
92
|
-
}
|
|
93
|
-
const isNotBetween = bindNot(isBetween);
|
|
94
|
-
|
|
95
|
-
function isEmpty(value) {
|
|
96
|
-
if (!value) {
|
|
97
|
-
return true;
|
|
98
|
-
} else if (isNumeric(value)) {
|
|
99
|
-
return value === 0;
|
|
100
|
-
} else if (Object.prototype.hasOwnProperty.call(value, 'length')) {
|
|
101
|
-
return value.length === 0;
|
|
102
|
-
} else if (typeof value === 'object') {
|
|
103
|
-
return Object.keys(value).length === 0;
|
|
104
|
-
} else {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const isNotEmpty = bindNot(isEmpty);
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Validates that a given value is an even number
|
|
112
|
-
* @param {Number|String} value Value to be validated
|
|
113
|
-
* @return {Boolean}
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
const isEven = value => {
|
|
117
|
-
if (!isNumeric(value)) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return value % 2 === 0;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
function isNaN$1(value) {
|
|
125
|
-
return Number.isNaN(value);
|
|
126
|
-
}
|
|
127
|
-
const isNotNaN = bindNot(isNaN$1);
|
|
128
|
-
|
|
129
|
-
function isNegative(value) {
|
|
130
|
-
if (isNumeric(value)) {
|
|
131
|
-
return Number(value) < 0;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
const isPositive = bindNot(isNegative);
|
|
137
|
-
|
|
138
|
-
function isNull(value) {
|
|
139
|
-
return value === null;
|
|
140
|
-
}
|
|
141
|
-
const isNotNull = bindNot(isNull);
|
|
142
|
-
|
|
143
|
-
function isNumber(value) {
|
|
144
|
-
return Boolean(typeof value === 'number');
|
|
145
|
-
}
|
|
146
|
-
const isNotNumber = bindNot(isNumber);
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Validates that a given value is an odd number
|
|
150
|
-
* @param {Number|String} value Value to be validated
|
|
151
|
-
* @return {Boolean}
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
const isOdd = value => {
|
|
155
|
-
if (!isNumeric(value)) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return value % 2 !== 0;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
function isString(value) {
|
|
163
|
-
return Boolean(typeof value === 'string');
|
|
164
|
-
}
|
|
165
|
-
const isNotString = bindNot(isString);
|
|
166
|
-
|
|
167
|
-
function isTruthy(value) {
|
|
168
|
-
return !!value;
|
|
169
|
-
}
|
|
170
|
-
const isFalsy = bindNot(isTruthy);
|
|
171
|
-
|
|
172
|
-
function isUndefined(value) {
|
|
173
|
-
return value === undefined;
|
|
174
|
-
}
|
|
175
|
-
const isNotUndefined = bindNot(isUndefined);
|
|
176
|
-
|
|
177
|
-
function lengthEquals(value, arg1) {
|
|
178
|
-
return value.length === arg1;
|
|
179
|
-
}
|
|
180
|
-
const lengthNotEquals = bindNot(lengthEquals);
|
|
181
|
-
|
|
182
|
-
function lessThan(value, arg1) {
|
|
183
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) < Number(arg1);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function longerThan(value, arg1) {
|
|
187
|
-
return value.length > arg1;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function longerThanOrEquals(value, arg1) {
|
|
191
|
-
return value.length >= arg1;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function matches(value, regex) {
|
|
195
|
-
if (regex instanceof RegExp) {
|
|
196
|
-
return regex.test(value);
|
|
197
|
-
} else if (typeof regex === 'string') {
|
|
198
|
-
return new RegExp(regex).test(value);
|
|
199
|
-
} else {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
const notMatches = bindNot(matches);
|
|
204
|
-
|
|
205
|
-
function numberEquals(value, arg1) {
|
|
206
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) === Number(arg1);
|
|
207
|
-
}
|
|
208
|
-
const numberNotEquals = bindNot(numberEquals);
|
|
209
|
-
|
|
210
|
-
function shorterThan(value, arg1) {
|
|
211
|
-
return value.length < arg1;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function shorterThanOrEquals(value, arg1) {
|
|
215
|
-
return value.length <= arg1;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function startsWith(value, arg1) {
|
|
219
|
-
return typeof value === 'string' && typeof arg1 === 'string' && value.startsWith(arg1);
|
|
220
|
-
}
|
|
221
|
-
const doesNotStartWith = bindNot(startsWith);
|
|
222
|
-
|
|
223
|
-
var rules = {
|
|
224
|
-
doesNotEndWith,
|
|
225
|
-
doesNotStartWith,
|
|
226
|
-
endsWith,
|
|
227
|
-
equals,
|
|
228
|
-
greaterThan,
|
|
229
|
-
greaterThanOrEquals,
|
|
230
|
-
gt: greaterThan,
|
|
231
|
-
gte: greaterThanOrEquals,
|
|
232
|
-
inside,
|
|
233
|
-
isArray,
|
|
234
|
-
isBetween,
|
|
235
|
-
isEmpty,
|
|
236
|
-
isEven,
|
|
237
|
-
isFalsy,
|
|
238
|
-
isNaN: isNaN$1,
|
|
239
|
-
isNegative,
|
|
240
|
-
isNotArray,
|
|
241
|
-
isNotBetween,
|
|
242
|
-
isNotEmpty,
|
|
243
|
-
isNotNaN,
|
|
244
|
-
isNotNull,
|
|
245
|
-
isNotNumber,
|
|
246
|
-
isNotNumeric,
|
|
247
|
-
isNotString,
|
|
248
|
-
isNotUndefined,
|
|
249
|
-
isNull,
|
|
250
|
-
isNumber,
|
|
251
|
-
isNumeric,
|
|
252
|
-
isOdd,
|
|
253
|
-
isPositive,
|
|
254
|
-
isString,
|
|
255
|
-
isTruthy,
|
|
256
|
-
isUndefined,
|
|
257
|
-
lengthEquals,
|
|
258
|
-
lengthNotEquals,
|
|
259
|
-
lessThan,
|
|
260
|
-
lessThanOrEquals,
|
|
261
|
-
longerThan,
|
|
262
|
-
longerThanOrEquals,
|
|
263
|
-
lt: lessThan,
|
|
264
|
-
lte: lessThanOrEquals,
|
|
265
|
-
matches,
|
|
266
|
-
notEquals,
|
|
267
|
-
notInside,
|
|
268
|
-
notMatches,
|
|
269
|
-
numberEquals,
|
|
270
|
-
numberNotEquals,
|
|
271
|
-
shorterThan,
|
|
272
|
-
shorterThanOrEquals,
|
|
273
|
-
startsWith
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
function validateResult(result, rule) {
|
|
277
|
-
if (typeof result !== 'boolean' && (!result || typeof result.pass !== 'boolean')) {
|
|
278
|
-
throwError(`${rule.name} wrong return value for the rule please check that the return is valid`);
|
|
279
|
-
}
|
|
280
|
-
} // for easier testing and mocking
|
|
281
|
-
|
|
282
|
-
function getDefaultResult(value, rule) {
|
|
283
|
-
return {
|
|
284
|
-
message: formatResultMessage(rule, `invalid ${typeof value} value`)
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
function formatResultMessage(rule, msg) {
|
|
288
|
-
return `[${"ensure"}]/${rule.name} ${msg}`;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Transform the result of a rule into a standard format
|
|
292
|
-
* @param {string} interfaceName to be used in the messages
|
|
293
|
-
* @param {*} result of the rule
|
|
294
|
-
* @param {Object} options
|
|
295
|
-
* @param {function} options.rule
|
|
296
|
-
* @param {*} options.value
|
|
297
|
-
* @returns {Object} result
|
|
298
|
-
* @returns {string} result.message
|
|
299
|
-
* @returns {boolean} result.pass indicates if the test passes or not
|
|
300
|
-
*/
|
|
301
|
-
|
|
302
|
-
function transformResult(result, {
|
|
303
|
-
rule,
|
|
304
|
-
value
|
|
305
|
-
}) {
|
|
306
|
-
const defaultResult = getDefaultResult(value, rule);
|
|
307
|
-
validateResult(result, rule);
|
|
308
|
-
|
|
309
|
-
if (typeof result === 'boolean') {
|
|
310
|
-
return _extends({}, defaultResult, {
|
|
311
|
-
pass: result
|
|
312
|
-
});
|
|
313
|
-
} else {
|
|
314
|
-
const formattedResult = {
|
|
315
|
-
pass: result.pass
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
if (result.message) {
|
|
319
|
-
formattedResult.message = formatResultMessage(rule, typeof result.message === 'function' ? result.message() : result.message);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return _extends({}, defaultResult, formattedResult);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Run a single rule against ensured value (e.g. `isNumber()`)
|
|
328
|
-
* @param {Function} rule - rule to run
|
|
329
|
-
* @param {Any} value
|
|
330
|
-
* @param {Array} args list of arguments sent from consumer
|
|
331
|
-
* @return {Boolean}
|
|
332
|
-
*/
|
|
333
|
-
|
|
334
|
-
function runner(rule, value, ...args) {
|
|
335
|
-
try {
|
|
336
|
-
const result = rule(value, ...args);
|
|
337
|
-
return transformResult(result, {
|
|
338
|
-
rule,
|
|
339
|
-
value
|
|
340
|
-
}).pass;
|
|
341
|
-
} catch (err) {
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Accepts list of registered rules and returns a test function
|
|
348
|
-
* That runs against them to return a boolean
|
|
349
|
-
*
|
|
350
|
-
* @param {Array} registeredRules
|
|
351
|
-
* @return {Function} test function
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
const createTestFn = registeredRules => value => registeredRules.every(({
|
|
355
|
-
name,
|
|
356
|
-
args
|
|
357
|
-
}) => runner(rulesObject[name], value, ...args));
|
|
358
|
-
|
|
359
|
-
let ensure, rulesList;
|
|
360
|
-
|
|
361
|
-
const rulesObject = _extends({}, rules);
|
|
362
|
-
|
|
363
|
-
if (proxySupported()) {
|
|
364
|
-
ensure = () => {
|
|
365
|
-
const registeredRules = [];
|
|
366
|
-
const proxy = new Proxy(rulesObject, {
|
|
367
|
-
get: (rules, ruleName) => {
|
|
368
|
-
if (ruleName === 'test') {
|
|
369
|
-
return createTestFn(registeredRules);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (!isRule(rulesObject, ruleName)) {
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return (...args) => {
|
|
377
|
-
registeredRules.push({
|
|
378
|
-
name: ruleName,
|
|
379
|
-
args
|
|
380
|
-
});
|
|
381
|
-
return proxy;
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
return proxy;
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
rulesList = Object.keys(rulesObject);
|
|
390
|
-
|
|
391
|
-
ensure = () => {
|
|
392
|
-
const registeredRules = [];
|
|
393
|
-
return rulesList.reduce((allRules, ruleName) => Object.assign(allRules, _extends({}, isRule(rulesObject, ruleName) && {
|
|
394
|
-
[ruleName]: (...args) => {
|
|
395
|
-
registeredRules.push({
|
|
396
|
-
name: ruleName,
|
|
397
|
-
args
|
|
398
|
-
});
|
|
399
|
-
return allRules;
|
|
400
|
-
}
|
|
401
|
-
})), {
|
|
402
|
-
test: createTestFn(registeredRules)
|
|
403
|
-
});
|
|
404
|
-
};
|
|
405
|
-
|
|
406
|
-
ensure.extend = customRules => {
|
|
407
|
-
Object.assign(rulesObject, customRules);
|
|
408
|
-
|
|
409
|
-
if (proxySupported()) {
|
|
410
|
-
rulesList = Object.keys(rulesObject);
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
var ensure$1 = ensure;
|
|
415
|
-
|
|
416
|
-
export default ensure$1;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n,r=arguments[t];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function t(e){throw Error("[ensure]: "+e)}let n=(e,n)=>((e=Object.prototype.hasOwnProperty.call(e,n)&&"function"==typeof e[n])||t(`Rule "${n}" was not found in rules object. Make sure you typed it correctly.`),e),r=Function("return this")();function u(e){return function(){return!e.apply(this,arguments)}}function s(e,t){return"string"==typeof e&&"string"==typeof t&&e.endsWith(t)}let o=u(s);function i(e,t){return e===t}let a=u(i);function l(e){return!(isNaN(parseFloat(e))||isNaN(Number(e))||!isFinite(e))}let f=u(l);function c(e,t){return l(e)&&l(t)&&Number(e)>Number(t)}function y(e,t){return l(e)&&l(t)&&Number(e)>=Number(t)}function p(e,t){return!!(Array.isArray(t)&&-1!==["string","number","boolean"].indexOf(typeof e)||"string"==typeof t&&"string"==typeof e)&&-1!==t.indexOf(e)}let g=u(p);function h(e){return!!Array.isArray(e)}let N=u(h);function m(e,t){return l(e)&&l(t)&&Number(e)<=Number(t)}function b(e,t,n){return y(e,t)&&m(e,n)}let d=u(b);function O(e){return!e||(l(e)?0===e:Object.prototype.hasOwnProperty.call(e,"length")?0===e.length:"object"!=typeof e||0===Object.keys(e).length)}let E=u(O);function v(e){return Number.isNaN(e)}let j=u(v);function q(e){return!!l(e)&&0>Number(e)}let w=u(q);function x(e){return null===e}let T=u(x);function P(e){return"number"==typeof e}let A=u(P);function W(e){return"string"==typeof e}let k=u(W);function $(e){return!!e}let F=u($);function R(e){return void 0===e}let S=u(R);function B(e,t){return e.length===t}let M=u(B);function U(e,t){return l(e)&&l(t)&&Number(e)<Number(t)}function I(e,t){return t instanceof RegExp?t.test(e):"string"==typeof t&&new RegExp(t).test(e)}let z=u(I);function C(e,t){return l(e)&&l(t)&&Number(e)===Number(t)}let D=u(C);function G(e,t){return"string"==typeof e&&"string"==typeof t&&e.startsWith(t)}let H=u(G);function J(n,r,...u){try{return function(n,{rule:r,value:u}){if(u={message:`[ensure]/${r.name} invalid ${typeof u} value`},"boolean"==typeof n||n&&"boolean"==typeof n.pass||t(r.name+" wrong return value for the rule please check that the return is valid"),"boolean"==typeof n)return e({},u,{pass:n});{let t={pass:n.pass};return n.message&&(n="function"==typeof n.message?n.message():n.message,t.message=`[ensure]/${r.name} ${n}`),e({},u,t)}}(n(r,...u),{rule:n,value:r}).pass}catch(e){return!1}}let K,L,Q=e=>t=>e.every((({name:e,args:n})=>J(V[e],t,...n))),V=e({},{doesNotEndWith:o,doesNotStartWith:H,endsWith:s,equals:i,greaterThan:c,greaterThanOrEquals:y,gt:c,gte:y,inside:p,isArray:h,isBetween:b,isEmpty:O,isEven:e=>!!l(e)&&0==e%2,isFalsy:F,isNaN:v,isNegative:q,isNotArray:N,isNotBetween:d,isNotEmpty:E,isNotNaN:j,isNotNull:T,isNotNumber:A,isNotNumeric:f,isNotString:k,isNotUndefined:S,isNull:x,isNumber:P,isNumeric:l,isOdd:e=>!!l(e)&&0!=e%2,isPositive:w,isString:W,isTruthy:$,isUndefined:R,lengthEquals:B,lengthNotEquals:M,lessThan:U,lessThanOrEquals:m,longerThan:function(e,t){return e.length>t},longerThanOrEquals:function(e,t){return e.length>=t},lt:U,lte:m,matches:I,notEquals:a,notInside:g,notMatches:z,numberEquals:C,numberNotEquals:D,shorterThan:function(e,t){return e.length<t},shorterThanOrEquals:function(e,t){return e.length<=t},startsWith:G});"function"==typeof r.Proxy&&(K=()=>{let e=[],t=new Proxy(V,{get:(r,u)=>"test"===u?Q(e):n(V,u)?(...n)=>(e.push({name:u,args:n}),t):void 0});return t}),L=Object.keys(V),K=()=>{let t=[];return L.reduce(((r,u)=>Object.assign(r,e({},n(V,u)&&{[u]:(...e)=>(t.push({name:u,args:e}),r)}))),{test:Q(t)})},K.extend=e=>{Object.assign(V,e),"function"==typeof r.Proxy&&(L=Object.keys(V))};export default K;
|