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