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,1949 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _extends() {
|
|
4
|
-
_extends = Object.assign || function (target) {
|
|
5
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
6
|
-
var source = arguments[i];
|
|
7
|
-
|
|
8
|
-
for (var key in source) {
|
|
9
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
10
|
-
target[key] = source[key];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return target;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return _extends.apply(this, arguments);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function throwError(message) {
|
|
22
|
-
throw new Error(`[${"enforceExtended"}]: ${message}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const isRule = (rulesObject, name) => {
|
|
26
|
-
const ruleExists = Object.prototype.hasOwnProperty.call(rulesObject, name) && typeof rulesObject[name] === 'function';
|
|
27
|
-
|
|
28
|
-
if (!ruleExists) {
|
|
29
|
-
throwError(`Rule "${name}" was not found in rules object. Make sure you typed it correctly.`);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return ruleExists;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const GLOBAL_OBJECT = Function('return this')();
|
|
36
|
-
|
|
37
|
-
const proxySupported = () => typeof GLOBAL_OBJECT.Proxy === 'function';
|
|
38
|
-
|
|
39
|
-
function bindNot(fn) {
|
|
40
|
-
return function () {
|
|
41
|
-
return !fn.apply(this, arguments);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function endsWith(value, arg1) {
|
|
46
|
-
return typeof value === 'string' && typeof arg1 === 'string' && value.endsWith(arg1);
|
|
47
|
-
}
|
|
48
|
-
const doesNotEndWith = bindNot(endsWith);
|
|
49
|
-
|
|
50
|
-
function equals(value, arg1) {
|
|
51
|
-
return value === arg1;
|
|
52
|
-
}
|
|
53
|
-
const notEquals = bindNot(equals);
|
|
54
|
-
|
|
55
|
-
function isNumeric(value) {
|
|
56
|
-
const result = !isNaN(parseFloat(value)) && !isNaN(Number(value)) && isFinite(value);
|
|
57
|
-
return Boolean(result);
|
|
58
|
-
}
|
|
59
|
-
const isNotNumeric = bindNot(isNumeric);
|
|
60
|
-
|
|
61
|
-
function greaterThan(value, arg1) {
|
|
62
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) > Number(arg1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function greaterThanOrEquals(value, arg1) {
|
|
66
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) >= Number(arg1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function inside(value, arg1) {
|
|
70
|
-
if (Array.isArray(arg1) && ['string', 'number', 'boolean'].indexOf(typeof value) !== -1) {
|
|
71
|
-
return arg1.indexOf(value) !== -1;
|
|
72
|
-
} // both value and arg1 are strings
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (typeof arg1 === 'string' && typeof value === 'string') {
|
|
76
|
-
return arg1.indexOf(value) !== -1;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const notInside = bindNot(inside);
|
|
82
|
-
|
|
83
|
-
function isArray(value) {
|
|
84
|
-
return Boolean(Array.isArray(value));
|
|
85
|
-
}
|
|
86
|
-
const isNotArray = bindNot(isArray);
|
|
87
|
-
|
|
88
|
-
function lessThanOrEquals(value, arg1) {
|
|
89
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) <= Number(arg1);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function isBetween(value, min, max) {
|
|
93
|
-
return greaterThanOrEquals(value, min) && lessThanOrEquals(value, max);
|
|
94
|
-
}
|
|
95
|
-
const isNotBetween = bindNot(isBetween);
|
|
96
|
-
|
|
97
|
-
function isEmpty(value) {
|
|
98
|
-
if (!value) {
|
|
99
|
-
return true;
|
|
100
|
-
} else if (isNumeric(value)) {
|
|
101
|
-
return value === 0;
|
|
102
|
-
} else if (Object.prototype.hasOwnProperty.call(value, 'length')) {
|
|
103
|
-
return value.length === 0;
|
|
104
|
-
} else if (typeof value === 'object') {
|
|
105
|
-
return Object.keys(value).length === 0;
|
|
106
|
-
} else {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const isNotEmpty = bindNot(isEmpty);
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Validates that a given value is an even number
|
|
114
|
-
* @param {Number|String} value Value to be validated
|
|
115
|
-
* @return {Boolean}
|
|
116
|
-
*/
|
|
117
|
-
|
|
118
|
-
const isEven = value => {
|
|
119
|
-
if (!isNumeric(value)) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return value % 2 === 0;
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
function isNaN$1(value) {
|
|
127
|
-
return Number.isNaN(value);
|
|
128
|
-
}
|
|
129
|
-
const isNotNaN = bindNot(isNaN$1);
|
|
130
|
-
|
|
131
|
-
function isNegative(value) {
|
|
132
|
-
if (isNumeric(value)) {
|
|
133
|
-
return Number(value) < 0;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
|
-
const isPositive = bindNot(isNegative);
|
|
139
|
-
|
|
140
|
-
function isNull(value) {
|
|
141
|
-
return value === null;
|
|
142
|
-
}
|
|
143
|
-
const isNotNull = bindNot(isNull);
|
|
144
|
-
|
|
145
|
-
function isNumber(value) {
|
|
146
|
-
return Boolean(typeof value === 'number');
|
|
147
|
-
}
|
|
148
|
-
const isNotNumber = bindNot(isNumber);
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Validates that a given value is an odd number
|
|
152
|
-
* @param {Number|String} value Value to be validated
|
|
153
|
-
* @return {Boolean}
|
|
154
|
-
*/
|
|
155
|
-
|
|
156
|
-
const isOdd = value => {
|
|
157
|
-
if (!isNumeric(value)) {
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return value % 2 !== 0;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
function isString(value) {
|
|
165
|
-
return Boolean(typeof value === 'string');
|
|
166
|
-
}
|
|
167
|
-
const isNotString = bindNot(isString);
|
|
168
|
-
|
|
169
|
-
function isTruthy(value) {
|
|
170
|
-
return !!value;
|
|
171
|
-
}
|
|
172
|
-
const isFalsy = bindNot(isTruthy);
|
|
173
|
-
|
|
174
|
-
function isUndefined(value) {
|
|
175
|
-
return value === undefined;
|
|
176
|
-
}
|
|
177
|
-
const isNotUndefined = bindNot(isUndefined);
|
|
178
|
-
|
|
179
|
-
function lengthEquals(value, arg1) {
|
|
180
|
-
return value.length === arg1;
|
|
181
|
-
}
|
|
182
|
-
const lengthNotEquals = bindNot(lengthEquals);
|
|
183
|
-
|
|
184
|
-
function lessThan(value, arg1) {
|
|
185
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) < Number(arg1);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function longerThan(value, arg1) {
|
|
189
|
-
return value.length > arg1;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function longerThanOrEquals(value, arg1) {
|
|
193
|
-
return value.length >= arg1;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function matches(value, regex) {
|
|
197
|
-
if (regex instanceof RegExp) {
|
|
198
|
-
return regex.test(value);
|
|
199
|
-
} else if (typeof regex === 'string') {
|
|
200
|
-
return new RegExp(regex).test(value);
|
|
201
|
-
} else {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
const notMatches = bindNot(matches);
|
|
206
|
-
|
|
207
|
-
function numberEquals(value, arg1) {
|
|
208
|
-
return isNumeric(value) && isNumeric(arg1) && Number(value) === Number(arg1);
|
|
209
|
-
}
|
|
210
|
-
const numberNotEquals = bindNot(numberEquals);
|
|
211
|
-
|
|
212
|
-
function shorterThan(value, arg1) {
|
|
213
|
-
return value.length < arg1;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function shorterThanOrEquals(value, arg1) {
|
|
217
|
-
return value.length <= arg1;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function startsWith(value, arg1) {
|
|
221
|
-
return typeof value === 'string' && typeof arg1 === 'string' && value.startsWith(arg1);
|
|
222
|
-
}
|
|
223
|
-
const doesNotStartWith = bindNot(startsWith);
|
|
224
|
-
|
|
225
|
-
var rules = {
|
|
226
|
-
doesNotEndWith,
|
|
227
|
-
doesNotStartWith,
|
|
228
|
-
endsWith,
|
|
229
|
-
equals,
|
|
230
|
-
greaterThan,
|
|
231
|
-
greaterThanOrEquals,
|
|
232
|
-
gt: greaterThan,
|
|
233
|
-
gte: greaterThanOrEquals,
|
|
234
|
-
inside,
|
|
235
|
-
isArray,
|
|
236
|
-
isBetween,
|
|
237
|
-
isEmpty,
|
|
238
|
-
isEven,
|
|
239
|
-
isFalsy,
|
|
240
|
-
isNaN: isNaN$1,
|
|
241
|
-
isNegative,
|
|
242
|
-
isNotArray,
|
|
243
|
-
isNotBetween,
|
|
244
|
-
isNotEmpty,
|
|
245
|
-
isNotNaN,
|
|
246
|
-
isNotNull,
|
|
247
|
-
isNotNumber,
|
|
248
|
-
isNotNumeric,
|
|
249
|
-
isNotString,
|
|
250
|
-
isNotUndefined,
|
|
251
|
-
isNull,
|
|
252
|
-
isNumber,
|
|
253
|
-
isNumeric,
|
|
254
|
-
isOdd,
|
|
255
|
-
isPositive,
|
|
256
|
-
isString,
|
|
257
|
-
isTruthy,
|
|
258
|
-
isUndefined,
|
|
259
|
-
lengthEquals,
|
|
260
|
-
lengthNotEquals,
|
|
261
|
-
lessThan,
|
|
262
|
-
lessThanOrEquals,
|
|
263
|
-
longerThan,
|
|
264
|
-
longerThanOrEquals,
|
|
265
|
-
lt: lessThan,
|
|
266
|
-
lte: lessThanOrEquals,
|
|
267
|
-
matches,
|
|
268
|
-
notEquals,
|
|
269
|
-
notInside,
|
|
270
|
-
notMatches,
|
|
271
|
-
numberEquals,
|
|
272
|
-
numberNotEquals,
|
|
273
|
-
shorterThan,
|
|
274
|
-
shorterThanOrEquals,
|
|
275
|
-
startsWith
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
function validateResult(result, rule) {
|
|
279
|
-
if (typeof result !== 'boolean' && (!result || typeof result.pass !== 'boolean')) {
|
|
280
|
-
throwError(`${rule.name} wrong return value for the rule please check that the return is valid`);
|
|
281
|
-
}
|
|
282
|
-
} // for easier testing and mocking
|
|
283
|
-
|
|
284
|
-
function getDefaultResult(value, rule) {
|
|
285
|
-
return {
|
|
286
|
-
message: formatResultMessage(rule, `invalid ${typeof value} value`)
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function formatResultMessage(rule, msg) {
|
|
290
|
-
return `[${"enforceExtended"}]/${rule.name} ${msg}`;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Transform the result of a rule into a standard format
|
|
294
|
-
* @param {string} interfaceName to be used in the messages
|
|
295
|
-
* @param {*} result of the rule
|
|
296
|
-
* @param {Object} options
|
|
297
|
-
* @param {function} options.rule
|
|
298
|
-
* @param {*} options.value
|
|
299
|
-
* @returns {Object} result
|
|
300
|
-
* @returns {string} result.message
|
|
301
|
-
* @returns {boolean} result.pass indicates if the test passes or not
|
|
302
|
-
*/
|
|
303
|
-
|
|
304
|
-
function transformResult(result, {
|
|
305
|
-
rule,
|
|
306
|
-
value
|
|
307
|
-
}) {
|
|
308
|
-
const defaultResult = getDefaultResult(value, rule);
|
|
309
|
-
validateResult(result, rule);
|
|
310
|
-
|
|
311
|
-
if (typeof result === 'boolean') {
|
|
312
|
-
return _extends({}, defaultResult, {
|
|
313
|
-
pass: result
|
|
314
|
-
});
|
|
315
|
-
} else {
|
|
316
|
-
const formattedResult = {
|
|
317
|
-
pass: result.pass
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
if (result.message) {
|
|
321
|
-
formattedResult.message = formatResultMessage(rule, typeof result.message === 'function' ? result.message() : result.message);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
return _extends({}, defaultResult, formattedResult);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Run a single rule against enforced value (e.g. `isNumber()`)
|
|
330
|
-
*
|
|
331
|
-
* @param {Function} rule - rule to run
|
|
332
|
-
* @param {Any} value
|
|
333
|
-
* @param {Array} args list of arguments sent from consumer
|
|
334
|
-
* @throws
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
|
-
function runner(rule, value, ...args) {
|
|
338
|
-
if (typeof rule !== 'function') {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const ruleResult = rule(value, ...args);
|
|
343
|
-
const result = transformResult(ruleResult, {
|
|
344
|
-
rule,
|
|
345
|
-
value
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
if (!result.pass) {
|
|
349
|
-
throw new Error(result.message);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const rulesObject = _extends({}, rules);
|
|
354
|
-
|
|
355
|
-
let enforce, rulesList;
|
|
356
|
-
|
|
357
|
-
if (proxySupported()) {
|
|
358
|
-
enforce = value => {
|
|
359
|
-
const proxy = new Proxy(rulesObject, {
|
|
360
|
-
get: (rules, fnName) => {
|
|
361
|
-
if (!isRule(rules, fnName)) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return (...args) => {
|
|
366
|
-
runner(rules[fnName], value, ...args);
|
|
367
|
-
return proxy;
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
return proxy;
|
|
372
|
-
};
|
|
373
|
-
} else {
|
|
374
|
-
rulesList = Object.keys(rulesObject);
|
|
375
|
-
|
|
376
|
-
enforce = value => rulesList.reduce((allRules, fnName) => Object.assign(allRules, _extends({}, isRule(rulesObject, fnName) && {
|
|
377
|
-
[fnName]: (...args) => {
|
|
378
|
-
runner(rulesObject[fnName], value, ...args);
|
|
379
|
-
return allRules;
|
|
380
|
-
}
|
|
381
|
-
})), {});
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
enforce.extend = customRules => {
|
|
385
|
-
Object.assign(rulesObject, customRules);
|
|
386
|
-
|
|
387
|
-
if (!proxySupported()) {
|
|
388
|
-
rulesList = Object.keys(rulesObject);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
return enforce;
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
var enforce$1 = enforce;
|
|
395
|
-
|
|
396
|
-
function _typeof(obj) {
|
|
397
|
-
"@babel/helpers - typeof";
|
|
398
|
-
|
|
399
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
400
|
-
_typeof = function _typeof(obj) {
|
|
401
|
-
return typeof obj;
|
|
402
|
-
};
|
|
403
|
-
} else {
|
|
404
|
-
_typeof = function _typeof(obj) {
|
|
405
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return _typeof(obj);
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
function assertString(input) {
|
|
413
|
-
var isString = typeof input === 'string' || input instanceof String;
|
|
414
|
-
|
|
415
|
-
if (!isString) {
|
|
416
|
-
var invalidType;
|
|
417
|
-
|
|
418
|
-
if (input === null) {
|
|
419
|
-
invalidType = 'null';
|
|
420
|
-
} else {
|
|
421
|
-
invalidType = _typeof(input);
|
|
422
|
-
|
|
423
|
-
if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) {
|
|
424
|
-
invalidType = input.constructor.name;
|
|
425
|
-
} else {
|
|
426
|
-
invalidType = "a ".concat(invalidType);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
throw new TypeError("Expected string but received ".concat(invalidType, "."));
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
var alphanumeric = {
|
|
435
|
-
'en-US': /^[0-9A-Z]+$/i,
|
|
436
|
-
'bg-BG': /^[0-9А-Я]+$/i,
|
|
437
|
-
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i,
|
|
438
|
-
'da-DK': /^[0-9A-ZÆØÅ]+$/i,
|
|
439
|
-
'de-DE': /^[0-9A-ZÄÖÜß]+$/i,
|
|
440
|
-
'el-GR': /^[0-9Α-ω]+$/i,
|
|
441
|
-
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i,
|
|
442
|
-
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i,
|
|
443
|
-
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i,
|
|
444
|
-
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i,
|
|
445
|
-
'nb-NO': /^[0-9A-ZÆØÅ]+$/i,
|
|
446
|
-
'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i,
|
|
447
|
-
'nn-NO': /^[0-9A-ZÆØÅ]+$/i,
|
|
448
|
-
'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i,
|
|
449
|
-
'pt-PT': /^[0-9A-ZÃÁÀÂÄÇÉÊËÍÏÕÓÔÖÚÜ]+$/i,
|
|
450
|
-
'ru-RU': /^[0-9А-ЯЁ]+$/i,
|
|
451
|
-
'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i,
|
|
452
|
-
'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i,
|
|
453
|
-
'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i,
|
|
454
|
-
'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i,
|
|
455
|
-
'sv-SE': /^[0-9A-ZÅÄÖ]+$/i,
|
|
456
|
-
'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i,
|
|
457
|
-
'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i,
|
|
458
|
-
'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i,
|
|
459
|
-
'vi-VN': /^[0-9A-ZÀÁẠẢÃÂẦẤẬẨẪĂẰẮẶẲẴĐÈÉẸẺẼÊỀẾỆỂỄÌÍỊỈĨÒÓỌỎÕÔỒỐỘỔỖƠỜỚỢỞỠÙÚỤỦŨƯỪỨỰỬỮỲÝỴỶỸ]+$/i,
|
|
460
|
-
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
|
|
461
|
-
he: /^[0-9א-ת]+$/,
|
|
462
|
-
fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i
|
|
463
|
-
};
|
|
464
|
-
var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM'];
|
|
465
|
-
|
|
466
|
-
for (var locale, i = 0; i < englishLocales.length; i++) {
|
|
467
|
-
locale = "en-".concat(englishLocales[i]);
|
|
468
|
-
alphanumeric[locale] = alphanumeric['en-US'];
|
|
469
|
-
} // Source: http://www.localeplanet.com/java/
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE'];
|
|
473
|
-
|
|
474
|
-
for (var _locale, _i = 0; _i < arabicLocales.length; _i++) {
|
|
475
|
-
_locale = "ar-".concat(arabicLocales[_i]);
|
|
476
|
-
alphanumeric[_locale] = alphanumeric.ar;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
var farsiLocales = ['IR', 'AF'];
|
|
480
|
-
|
|
481
|
-
for (var _locale2, _i2 = 0; _i2 < farsiLocales.length; _i2++) {
|
|
482
|
-
_locale2 = "fa-".concat(farsiLocales[_i2]);
|
|
483
|
-
alphanumeric[_locale2] = alphanumeric.fa;
|
|
484
|
-
} // Source: https://en.wikipedia.org/wiki/Decimal_mark
|
|
485
|
-
alphanumeric['pt-BR'] = alphanumeric['pt-PT'];
|
|
486
|
-
alphanumeric['pl-Pl'] = alphanumeric['pl-PL'];
|
|
487
|
-
|
|
488
|
-
function isAlphanumeric(str) {
|
|
489
|
-
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US';
|
|
490
|
-
assertString(str);
|
|
491
|
-
|
|
492
|
-
if (locale in alphanumeric) {
|
|
493
|
-
return alphanumeric[locale].test(str);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
throw new Error("Invalid locale '".concat(locale, "'"));
|
|
497
|
-
}
|
|
498
|
-
var locales = Object.keys(alphanumeric);
|
|
499
|
-
|
|
500
|
-
/* eslint-disable max-len */
|
|
501
|
-
|
|
502
|
-
var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;
|
|
503
|
-
/* eslint-enable max-len */
|
|
504
|
-
|
|
505
|
-
function isCreditCard(str) {
|
|
506
|
-
assertString(str);
|
|
507
|
-
var sanitized = str.replace(/[- ]+/g, '');
|
|
508
|
-
|
|
509
|
-
if (!creditCard.test(sanitized)) {
|
|
510
|
-
return false;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
var sum = 0;
|
|
514
|
-
var digit;
|
|
515
|
-
var tmpNum;
|
|
516
|
-
var shouldDouble;
|
|
517
|
-
|
|
518
|
-
for (var i = sanitized.length - 1; i >= 0; i--) {
|
|
519
|
-
digit = sanitized.substring(i, i + 1);
|
|
520
|
-
tmpNum = parseInt(digit, 10);
|
|
521
|
-
|
|
522
|
-
if (shouldDouble) {
|
|
523
|
-
tmpNum *= 2;
|
|
524
|
-
|
|
525
|
-
if (tmpNum >= 10) {
|
|
526
|
-
sum += tmpNum % 10 + 1;
|
|
527
|
-
} else {
|
|
528
|
-
sum += tmpNum;
|
|
529
|
-
}
|
|
530
|
-
} else {
|
|
531
|
-
sum += tmpNum;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
shouldDouble = !shouldDouble;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
return !!(sum % 10 === 0 ? sanitized : false);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
function merge() {
|
|
541
|
-
var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
542
|
-
var defaults = arguments.length > 1 ? arguments[1] : undefined;
|
|
543
|
-
|
|
544
|
-
for (var key in defaults) {
|
|
545
|
-
if (typeof obj[key] === 'undefined') {
|
|
546
|
-
obj[key] = defaults[key];
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
return obj;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function currencyRegex(options) {
|
|
554
|
-
var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}");
|
|
555
|
-
options.digits_after_decimal.forEach(function (digit, index) {
|
|
556
|
-
if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}");
|
|
557
|
-
});
|
|
558
|
-
var symbol = "(".concat(options.symbol.replace(/\W/, function (m) {
|
|
559
|
-
return "\\".concat(m);
|
|
560
|
-
}), ")").concat(options.require_symbol ? '' : '?'),
|
|
561
|
-
negative = '-?',
|
|
562
|
-
whole_dollar_amount_without_sep = '[1-9]\\d*',
|
|
563
|
-
whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"),
|
|
564
|
-
valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep],
|
|
565
|
-
whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"),
|
|
566
|
-
decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?');
|
|
567
|
-
var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : ''); // default is negative sign before symbol, but there are two other options (besides parens)
|
|
568
|
-
|
|
569
|
-
if (options.allow_negatives && !options.parens_for_negatives) {
|
|
570
|
-
if (options.negative_sign_after_digits) {
|
|
571
|
-
pattern += negative;
|
|
572
|
-
} else if (options.negative_sign_before_digits) {
|
|
573
|
-
pattern = negative + pattern;
|
|
574
|
-
}
|
|
575
|
-
} // South African Rand, for example, uses R 123 (space) and R-123 (no space)
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
if (options.allow_negative_sign_placeholder) {
|
|
579
|
-
pattern = "( (?!\\-))?".concat(pattern);
|
|
580
|
-
} else if (options.allow_space_after_symbol) {
|
|
581
|
-
pattern = " ?".concat(pattern);
|
|
582
|
-
} else if (options.allow_space_after_digits) {
|
|
583
|
-
pattern += '( (?!$))?';
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
if (options.symbol_after_digits) {
|
|
587
|
-
pattern += symbol;
|
|
588
|
-
} else {
|
|
589
|
-
pattern = symbol + pattern;
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
if (options.allow_negatives) {
|
|
593
|
-
if (options.parens_for_negatives) {
|
|
594
|
-
pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")");
|
|
595
|
-
} else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) {
|
|
596
|
-
pattern = negative + pattern;
|
|
597
|
-
}
|
|
598
|
-
} // ensure there's a dollar and/or decimal amount, and that
|
|
599
|
-
// it doesn't start with a space or a negative sign followed by a space
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$"));
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
var default_currency_options = {
|
|
606
|
-
symbol: '$',
|
|
607
|
-
require_symbol: false,
|
|
608
|
-
allow_space_after_symbol: false,
|
|
609
|
-
symbol_after_digits: false,
|
|
610
|
-
allow_negatives: true,
|
|
611
|
-
parens_for_negatives: false,
|
|
612
|
-
negative_sign_before_digits: false,
|
|
613
|
-
negative_sign_after_digits: false,
|
|
614
|
-
allow_negative_sign_placeholder: false,
|
|
615
|
-
thousands_separator: ',',
|
|
616
|
-
decimal_separator: '.',
|
|
617
|
-
allow_decimal: true,
|
|
618
|
-
require_decimal: false,
|
|
619
|
-
digits_after_decimal: [2],
|
|
620
|
-
allow_space_after_digits: false
|
|
621
|
-
};
|
|
622
|
-
function isCurrency(str, options) {
|
|
623
|
-
assertString(str);
|
|
624
|
-
options = merge(options, default_currency_options);
|
|
625
|
-
return currencyRegex(options).test(str);
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
function _typeof$1(obj) {
|
|
629
|
-
"@babel/helpers - typeof";
|
|
630
|
-
|
|
631
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
632
|
-
_typeof$1 = function _typeof(obj) {
|
|
633
|
-
return typeof obj;
|
|
634
|
-
};
|
|
635
|
-
} else {
|
|
636
|
-
_typeof$1 = function _typeof(obj) {
|
|
637
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return _typeof$1(obj);
|
|
642
|
-
}
|
|
643
|
-
/* eslint-disable prefer-rest-params */
|
|
644
|
-
|
|
645
|
-
function isByteLength(str, options) {
|
|
646
|
-
assertString(str);
|
|
647
|
-
var min;
|
|
648
|
-
var max;
|
|
649
|
-
|
|
650
|
-
if (_typeof$1(options) === 'object') {
|
|
651
|
-
min = options.min || 0;
|
|
652
|
-
max = options.max;
|
|
653
|
-
} else {
|
|
654
|
-
// backwards compatibility: isByteLength(str, min [, max])
|
|
655
|
-
min = arguments[1];
|
|
656
|
-
max = arguments[2];
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
var len = encodeURI(str).split(/%..|./).length - 1;
|
|
660
|
-
return len >= min && (typeof max === 'undefined' || len <= max);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
var default_fqdn_options = {
|
|
664
|
-
require_tld: true,
|
|
665
|
-
allow_underscores: false,
|
|
666
|
-
allow_trailing_dot: false
|
|
667
|
-
};
|
|
668
|
-
function isFQDN(str, options) {
|
|
669
|
-
assertString(str);
|
|
670
|
-
options = merge(options, default_fqdn_options);
|
|
671
|
-
/* Remove the optional trailing dot before checking validity */
|
|
672
|
-
|
|
673
|
-
if (options.allow_trailing_dot && str[str.length - 1] === '.') {
|
|
674
|
-
str = str.substring(0, str.length - 1);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
var parts = str.split('.');
|
|
678
|
-
|
|
679
|
-
for (var i = 0; i < parts.length; i++) {
|
|
680
|
-
if (parts[i].length > 63) {
|
|
681
|
-
return false;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
if (options.require_tld) {
|
|
686
|
-
var tld = parts.pop();
|
|
687
|
-
|
|
688
|
-
if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
|
|
689
|
-
return false;
|
|
690
|
-
} // disallow spaces && special characers
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20\u00A9\uFFFD]/.test(tld)) {
|
|
694
|
-
return false;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
for (var part, _i = 0; _i < parts.length; _i++) {
|
|
699
|
-
part = parts[_i];
|
|
700
|
-
|
|
701
|
-
if (options.allow_underscores) {
|
|
702
|
-
part = part.replace(/_/g, '');
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) {
|
|
706
|
-
return false;
|
|
707
|
-
} // disallow full-width chars
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
if (/[\uff01-\uff5e]/.test(part)) {
|
|
711
|
-
return false;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
if (part[0] === '-' || part[part.length - 1] === '-') {
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
return true;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
/**
|
|
723
|
-
11.3. Examples
|
|
724
|
-
|
|
725
|
-
The following addresses
|
|
726
|
-
|
|
727
|
-
fe80::1234 (on the 1st link of the node)
|
|
728
|
-
ff02::5678 (on the 5th link of the node)
|
|
729
|
-
ff08::9abc (on the 10th organization of the node)
|
|
730
|
-
|
|
731
|
-
would be represented as follows:
|
|
732
|
-
|
|
733
|
-
fe80::1234%1
|
|
734
|
-
ff02::5678%5
|
|
735
|
-
ff08::9abc%10
|
|
736
|
-
|
|
737
|
-
(Here we assume a natural translation from a zone index to the
|
|
738
|
-
<zone_id> part, where the Nth zone of any scope is translated into
|
|
739
|
-
"N".)
|
|
740
|
-
|
|
741
|
-
If we use interface names as <zone_id>, those addresses could also be
|
|
742
|
-
represented as follows:
|
|
743
|
-
|
|
744
|
-
fe80::1234%ne0
|
|
745
|
-
ff02::5678%pvc1.3
|
|
746
|
-
ff08::9abc%interface10
|
|
747
|
-
|
|
748
|
-
where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs
|
|
749
|
-
to the 5th link, and "interface10" belongs to the 10th organization.
|
|
750
|
-
* * */
|
|
751
|
-
|
|
752
|
-
var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
|
|
753
|
-
var ipv6Block = /^[0-9A-F]{1,4}$/i;
|
|
754
|
-
function isIP(str) {
|
|
755
|
-
var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
756
|
-
assertString(str);
|
|
757
|
-
version = String(version);
|
|
758
|
-
|
|
759
|
-
if (!version) {
|
|
760
|
-
return isIP(str, 4) || isIP(str, 6);
|
|
761
|
-
} else if (version === '4') {
|
|
762
|
-
if (!ipv4Maybe.test(str)) {
|
|
763
|
-
return false;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
var parts = str.split('.').sort(function (a, b) {
|
|
767
|
-
return a - b;
|
|
768
|
-
});
|
|
769
|
-
return parts[3] <= 255;
|
|
770
|
-
} else if (version === '6') {
|
|
771
|
-
var addressAndZone = [str]; // ipv6 addresses could have scoped architecture
|
|
772
|
-
// according to https://tools.ietf.org/html/rfc4007#section-11
|
|
773
|
-
|
|
774
|
-
if (str.includes('%')) {
|
|
775
|
-
addressAndZone = str.split('%');
|
|
776
|
-
|
|
777
|
-
if (addressAndZone.length !== 2) {
|
|
778
|
-
// it must be just two parts
|
|
779
|
-
return false;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
if (!addressAndZone[0].includes(':')) {
|
|
783
|
-
// the first part must be the address
|
|
784
|
-
return false;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
if (addressAndZone[1] === '') {
|
|
788
|
-
// the second part must not be empty
|
|
789
|
-
return false;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
var blocks = addressAndZone[0].split(':');
|
|
794
|
-
var foundOmissionBlock = false; // marker to indicate ::
|
|
795
|
-
// At least some OS accept the last 32 bits of an IPv6 address
|
|
796
|
-
// (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says
|
|
797
|
-
// that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses,
|
|
798
|
-
// and '::a.b.c.d' is deprecated, but also valid.
|
|
799
|
-
|
|
800
|
-
var foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4);
|
|
801
|
-
var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8;
|
|
802
|
-
|
|
803
|
-
if (blocks.length > expectedNumberOfBlocks) {
|
|
804
|
-
return false;
|
|
805
|
-
} // initial or final ::
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
if (str === '::') {
|
|
809
|
-
return true;
|
|
810
|
-
} else if (str.substr(0, 2) === '::') {
|
|
811
|
-
blocks.shift();
|
|
812
|
-
blocks.shift();
|
|
813
|
-
foundOmissionBlock = true;
|
|
814
|
-
} else if (str.substr(str.length - 2) === '::') {
|
|
815
|
-
blocks.pop();
|
|
816
|
-
blocks.pop();
|
|
817
|
-
foundOmissionBlock = true;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
for (var i = 0; i < blocks.length; ++i) {
|
|
821
|
-
// test for a :: which can not be at the string start/end
|
|
822
|
-
// since those cases have been handled above
|
|
823
|
-
if (blocks[i] === '' && i > 0 && i < blocks.length - 1) {
|
|
824
|
-
if (foundOmissionBlock) {
|
|
825
|
-
return false; // multiple :: in address
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
foundOmissionBlock = true;
|
|
829
|
-
} else if (foundIPv4TransitionBlock && i === blocks.length - 1) ; else if (!ipv6Block.test(blocks[i])) {
|
|
830
|
-
return false;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
if (foundOmissionBlock) {
|
|
835
|
-
return blocks.length >= 1;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
return blocks.length === expectedNumberOfBlocks;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
return false;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
function _slicedToArray(arr, i) {
|
|
845
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
function _nonIterableRest() {
|
|
849
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
853
|
-
if (!o) return;
|
|
854
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
855
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
856
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
857
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
858
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
function _arrayLikeToArray(arr, len) {
|
|
862
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
863
|
-
|
|
864
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) {
|
|
865
|
-
arr2[i] = arr[i];
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
return arr2;
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
function _iterableToArrayLimit(arr, i) {
|
|
872
|
-
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
|
873
|
-
var _arr = [];
|
|
874
|
-
var _n = true;
|
|
875
|
-
var _d = false;
|
|
876
|
-
var _e = undefined;
|
|
877
|
-
|
|
878
|
-
try {
|
|
879
|
-
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
880
|
-
_arr.push(_s.value);
|
|
881
|
-
|
|
882
|
-
if (i && _arr.length === i) break;
|
|
883
|
-
}
|
|
884
|
-
} catch (err) {
|
|
885
|
-
_d = true;
|
|
886
|
-
_e = err;
|
|
887
|
-
} finally {
|
|
888
|
-
try {
|
|
889
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
890
|
-
} finally {
|
|
891
|
-
if (_d) throw _e;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
return _arr;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
function _arrayWithHoles(arr) {
|
|
899
|
-
if (Array.isArray(arr)) return arr;
|
|
900
|
-
}
|
|
901
|
-
var default_email_options = {
|
|
902
|
-
allow_display_name: false,
|
|
903
|
-
require_display_name: false,
|
|
904
|
-
allow_utf8_local_part: true,
|
|
905
|
-
require_tld: true
|
|
906
|
-
};
|
|
907
|
-
/* eslint-disable max-len */
|
|
908
|
-
|
|
909
|
-
/* eslint-disable no-control-regex */
|
|
910
|
-
|
|
911
|
-
var splitNameAddress = /^([^\x00-\x1F\x7F-\x9F\cX]+)<(.+)>$/i;
|
|
912
|
-
var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i;
|
|
913
|
-
var gmailUserPart = /^[a-z\d]+$/;
|
|
914
|
-
var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i;
|
|
915
|
-
var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i;
|
|
916
|
-
var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;
|
|
917
|
-
var defaultMaxEmailLength = 254;
|
|
918
|
-
/* eslint-enable max-len */
|
|
919
|
-
|
|
920
|
-
/* eslint-enable no-control-regex */
|
|
921
|
-
|
|
922
|
-
/**
|
|
923
|
-
* Validate display name according to the RFC2822: https://tools.ietf.org/html/rfc2822#appendix-A.1.2
|
|
924
|
-
* @param {String} display_name
|
|
925
|
-
*/
|
|
926
|
-
|
|
927
|
-
function validateDisplayName(display_name) {
|
|
928
|
-
var trim_quotes = display_name.match(/^"(.+)"$/i);
|
|
929
|
-
var display_name_without_quotes = trim_quotes ? trim_quotes[1] : display_name; // display name with only spaces is not valid
|
|
930
|
-
|
|
931
|
-
if (!display_name_without_quotes.trim()) {
|
|
932
|
-
return false;
|
|
933
|
-
} // check whether display name contains illegal character
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
var contains_illegal = /[\.";<>]/.test(display_name_without_quotes);
|
|
937
|
-
|
|
938
|
-
if (contains_illegal) {
|
|
939
|
-
// if contains illegal characters,
|
|
940
|
-
// must to be enclosed in double-quotes, otherwise it's not a valid display name
|
|
941
|
-
if (!trim_quotes) {
|
|
942
|
-
return false;
|
|
943
|
-
} // the quotes in display name must start with character symbol \
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
var all_start_with_back_slash = display_name_without_quotes.split('"').length === display_name_without_quotes.split('\\"').length;
|
|
947
|
-
|
|
948
|
-
if (!all_start_with_back_slash) {
|
|
949
|
-
return false;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
return true;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
function isEmail(str, options) {
|
|
957
|
-
assertString(str);
|
|
958
|
-
options = merge(options, default_email_options);
|
|
959
|
-
|
|
960
|
-
if (options.require_display_name || options.allow_display_name) {
|
|
961
|
-
var display_email = str.match(splitNameAddress);
|
|
962
|
-
|
|
963
|
-
if (display_email) {
|
|
964
|
-
var display_name;
|
|
965
|
-
|
|
966
|
-
var _display_email = _slicedToArray(display_email, 3);
|
|
967
|
-
|
|
968
|
-
display_name = _display_email[1];
|
|
969
|
-
str = _display_email[2]; // sometimes need to trim the last space to get the display name
|
|
970
|
-
// because there may be a space between display name and email address
|
|
971
|
-
// eg. myname <address@gmail.com>
|
|
972
|
-
// the display name is `myname` instead of `myname `, so need to trim the last space
|
|
973
|
-
|
|
974
|
-
if (display_name.endsWith(' ')) {
|
|
975
|
-
display_name = display_name.substr(0, display_name.length - 1);
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
if (!validateDisplayName(display_name)) {
|
|
979
|
-
return false;
|
|
980
|
-
}
|
|
981
|
-
} else if (options.require_display_name) {
|
|
982
|
-
return false;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
if (!options.ignore_max_length && str.length > defaultMaxEmailLength) {
|
|
987
|
-
return false;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
var parts = str.split('@');
|
|
991
|
-
var domain = parts.pop();
|
|
992
|
-
var user = parts.join('@');
|
|
993
|
-
var lower_domain = domain.toLowerCase();
|
|
994
|
-
|
|
995
|
-
if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) {
|
|
996
|
-
/*
|
|
997
|
-
Previously we removed dots for gmail addresses before validating.
|
|
998
|
-
This was removed because it allows `multiple..dots@gmail.com`
|
|
999
|
-
to be reported as valid, but it is not.
|
|
1000
|
-
Gmail only normalizes single dots, removing them from here is pointless,
|
|
1001
|
-
should be done in normalizeEmail
|
|
1002
|
-
*/
|
|
1003
|
-
user = user.toLowerCase(); // Removing sub-address from username before gmail validation
|
|
1004
|
-
|
|
1005
|
-
var username = user.split('+')[0]; // Dots are not included in gmail length restriction
|
|
1006
|
-
|
|
1007
|
-
if (!isByteLength(username.replace('.', ''), {
|
|
1008
|
-
min: 6,
|
|
1009
|
-
max: 30
|
|
1010
|
-
})) {
|
|
1011
|
-
return false;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
var _user_parts = username.split('.');
|
|
1015
|
-
|
|
1016
|
-
for (var i = 0; i < _user_parts.length; i++) {
|
|
1017
|
-
if (!gmailUserPart.test(_user_parts[i])) {
|
|
1018
|
-
return false;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
if (!isByteLength(user, {
|
|
1024
|
-
max: 64
|
|
1025
|
-
}) || !isByteLength(domain, {
|
|
1026
|
-
max: 254
|
|
1027
|
-
})) {
|
|
1028
|
-
return false;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
if (!isFQDN(domain, {
|
|
1032
|
-
require_tld: options.require_tld
|
|
1033
|
-
})) {
|
|
1034
|
-
if (!options.allow_ip_domain) {
|
|
1035
|
-
return false;
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
if (!isIP(domain)) {
|
|
1039
|
-
if (!domain.startsWith('[') || !domain.endsWith(']')) {
|
|
1040
|
-
return false;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
var noBracketdomain = domain.substr(1, domain.length - 2);
|
|
1044
|
-
|
|
1045
|
-
if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) {
|
|
1046
|
-
return false;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
if (user[0] === '"') {
|
|
1052
|
-
user = user.slice(1, user.length - 1);
|
|
1053
|
-
return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user);
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart;
|
|
1057
|
-
var user_parts = user.split('.');
|
|
1058
|
-
|
|
1059
|
-
for (var _i2 = 0; _i2 < user_parts.length; _i2++) {
|
|
1060
|
-
if (!pattern.test(user_parts[_i2])) {
|
|
1061
|
-
return false;
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
return true;
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
var validators = {
|
|
1069
|
-
ES: function ES(str) {
|
|
1070
|
-
assertString(str);
|
|
1071
|
-
var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/;
|
|
1072
|
-
var charsValue = {
|
|
1073
|
-
X: 0,
|
|
1074
|
-
Y: 1,
|
|
1075
|
-
Z: 2
|
|
1076
|
-
};
|
|
1077
|
-
var controlDigits = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E']; // sanitize user input
|
|
1078
|
-
|
|
1079
|
-
var sanitized = str.trim().toUpperCase(); // validate the data structure
|
|
1080
|
-
|
|
1081
|
-
if (!DNI.test(sanitized)) {
|
|
1082
|
-
return false;
|
|
1083
|
-
} // validate the control digit
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) {
|
|
1087
|
-
return charsValue[_char];
|
|
1088
|
-
});
|
|
1089
|
-
return sanitized.endsWith(controlDigits[number % 23]);
|
|
1090
|
-
},
|
|
1091
|
-
IN: function IN(str) {
|
|
1092
|
-
var DNI = /^[1-9]\d{3}\s?\d{4}\s?\d{4}$/; // multiplication table
|
|
1093
|
-
|
|
1094
|
-
var d = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]]; // permutation table
|
|
1095
|
-
|
|
1096
|
-
var p = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]]; // sanitize user input
|
|
1097
|
-
|
|
1098
|
-
var sanitized = str.trim(); // validate the data structure
|
|
1099
|
-
|
|
1100
|
-
if (!DNI.test(sanitized)) {
|
|
1101
|
-
return false;
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
var c = 0;
|
|
1105
|
-
var invertedArray = sanitized.replace(/\s/g, '').split('').map(Number).reverse();
|
|
1106
|
-
invertedArray.forEach(function (val, i) {
|
|
1107
|
-
c = d[c][p[i % 8][val]];
|
|
1108
|
-
});
|
|
1109
|
-
return c === 0;
|
|
1110
|
-
},
|
|
1111
|
-
IT: function IT(str) {
|
|
1112
|
-
if (str.length !== 9) return false;
|
|
1113
|
-
if (str === 'CA00000AA') return false; // https://it.wikipedia.org/wiki/Carta_d%27identit%C3%A0_elettronica_italiana
|
|
1114
|
-
|
|
1115
|
-
return str.search(/C[A-Z][0-9]{5}[A-Z]{2}/i) > -1;
|
|
1116
|
-
},
|
|
1117
|
-
NO: function NO(str) {
|
|
1118
|
-
var sanitized = str.trim();
|
|
1119
|
-
if (isNaN(Number(sanitized))) return false;
|
|
1120
|
-
if (sanitized.length !== 11) return false;
|
|
1121
|
-
if (sanitized === '00000000000') return false; // https://no.wikipedia.org/wiki/F%C3%B8dselsnummer
|
|
1122
|
-
|
|
1123
|
-
var f = sanitized.split('').map(Number);
|
|
1124
|
-
var k1 = (11 - (3 * f[0] + 7 * f[1] + 6 * f[2] + 1 * f[3] + 8 * f[4] + 9 * f[5] + 4 * f[6] + 5 * f[7] + 2 * f[8]) % 11) % 11;
|
|
1125
|
-
var k2 = (11 - (5 * f[0] + 4 * f[1] + 3 * f[2] + 2 * f[3] + 7 * f[4] + 6 * f[5] + 5 * f[6] + 4 * f[7] + 3 * f[8] + 2 * k1) % 11) % 11;
|
|
1126
|
-
if (k1 !== f[9] || k2 !== f[10]) return false;
|
|
1127
|
-
return true;
|
|
1128
|
-
},
|
|
1129
|
-
'he-IL': function heIL(str) {
|
|
1130
|
-
var DNI = /^\d{9}$/; // sanitize user input
|
|
1131
|
-
|
|
1132
|
-
var sanitized = str.trim(); // validate the data structure
|
|
1133
|
-
|
|
1134
|
-
if (!DNI.test(sanitized)) {
|
|
1135
|
-
return false;
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
var id = sanitized;
|
|
1139
|
-
var sum = 0,
|
|
1140
|
-
incNum;
|
|
1141
|
-
|
|
1142
|
-
for (var i = 0; i < id.length; i++) {
|
|
1143
|
-
incNum = Number(id[i]) * (i % 2 + 1); // Multiply number by 1 or 2
|
|
1144
|
-
|
|
1145
|
-
sum += incNum > 9 ? incNum - 9 : incNum; // Sum the digits up and add to total
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
return sum % 10 === 0;
|
|
1149
|
-
},
|
|
1150
|
-
'ar-TN': function arTN(str) {
|
|
1151
|
-
var DNI = /^\d{8}$/; // sanitize user input
|
|
1152
|
-
|
|
1153
|
-
var sanitized = str.trim(); // validate the data structure
|
|
1154
|
-
|
|
1155
|
-
if (!DNI.test(sanitized)) {
|
|
1156
|
-
return false;
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
return true;
|
|
1160
|
-
},
|
|
1161
|
-
'zh-CN': function zhCN(str) {
|
|
1162
|
-
var provincesAndCities = ['11', // 北京
|
|
1163
|
-
'12', // 天津
|
|
1164
|
-
'13', // 河北
|
|
1165
|
-
'14', // 山西
|
|
1166
|
-
'15', // 内蒙古
|
|
1167
|
-
'21', // 辽宁
|
|
1168
|
-
'22', // 吉林
|
|
1169
|
-
'23', // 黑龙江
|
|
1170
|
-
'31', // 上海
|
|
1171
|
-
'32', // 江苏
|
|
1172
|
-
'33', // 浙江
|
|
1173
|
-
'34', // 安徽
|
|
1174
|
-
'35', // 福建
|
|
1175
|
-
'36', // 江西
|
|
1176
|
-
'37', // 山东
|
|
1177
|
-
'41', // 河南
|
|
1178
|
-
'42', // 湖北
|
|
1179
|
-
'43', // 湖南
|
|
1180
|
-
'44', // 广东
|
|
1181
|
-
'45', // 广西
|
|
1182
|
-
'46', // 海南
|
|
1183
|
-
'50', // 重庆
|
|
1184
|
-
'51', // 四川
|
|
1185
|
-
'52', // 贵州
|
|
1186
|
-
'53', // 云南
|
|
1187
|
-
'54', // 西藏
|
|
1188
|
-
'61', // 陕西
|
|
1189
|
-
'62', // 甘肃
|
|
1190
|
-
'63', // 青海
|
|
1191
|
-
'64', // 宁夏
|
|
1192
|
-
'65', // 新疆
|
|
1193
|
-
'71', // 台湾
|
|
1194
|
-
'81', // 香港
|
|
1195
|
-
'82', // 澳门
|
|
1196
|
-
'91' // 国外
|
|
1197
|
-
];
|
|
1198
|
-
var powers = ['7', '9', '10', '5', '8', '4', '2', '1', '6', '3', '7', '9', '10', '5', '8', '4', '2'];
|
|
1199
|
-
var parityBit = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
|
|
1200
|
-
|
|
1201
|
-
var checkAddressCode = function checkAddressCode(addressCode) {
|
|
1202
|
-
return provincesAndCities.includes(addressCode);
|
|
1203
|
-
};
|
|
1204
|
-
|
|
1205
|
-
var checkBirthDayCode = function checkBirthDayCode(birDayCode) {
|
|
1206
|
-
var yyyy = parseInt(birDayCode.substring(0, 4), 10);
|
|
1207
|
-
var mm = parseInt(birDayCode.substring(4, 6), 10);
|
|
1208
|
-
var dd = parseInt(birDayCode.substring(6), 10);
|
|
1209
|
-
var xdata = new Date(yyyy, mm - 1, dd);
|
|
1210
|
-
|
|
1211
|
-
if (xdata > new Date()) {
|
|
1212
|
-
return false; // eslint-disable-next-line max-len
|
|
1213
|
-
} else if (xdata.getFullYear() === yyyy && xdata.getMonth() === mm - 1 && xdata.getDate() === dd) {
|
|
1214
|
-
return true;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
return false;
|
|
1218
|
-
};
|
|
1219
|
-
|
|
1220
|
-
var getParityBit = function getParityBit(idCardNo) {
|
|
1221
|
-
var id17 = idCardNo.substring(0, 17);
|
|
1222
|
-
var power = 0;
|
|
1223
|
-
|
|
1224
|
-
for (var i = 0; i < 17; i++) {
|
|
1225
|
-
power += parseInt(id17.charAt(i), 10) * parseInt(powers[i], 10);
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
var mod = power % 11;
|
|
1229
|
-
return parityBit[mod];
|
|
1230
|
-
};
|
|
1231
|
-
|
|
1232
|
-
var checkParityBit = function checkParityBit(idCardNo) {
|
|
1233
|
-
return getParityBit(idCardNo) === idCardNo.charAt(17).toUpperCase();
|
|
1234
|
-
};
|
|
1235
|
-
|
|
1236
|
-
var check15IdCardNo = function check15IdCardNo(idCardNo) {
|
|
1237
|
-
var check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo);
|
|
1238
|
-
if (!check) return false;
|
|
1239
|
-
var addressCode = idCardNo.substring(0, 2);
|
|
1240
|
-
check = checkAddressCode(addressCode);
|
|
1241
|
-
if (!check) return false;
|
|
1242
|
-
var birDayCode = "19".concat(idCardNo.substring(6, 12));
|
|
1243
|
-
check = checkBirthDayCode(birDayCode);
|
|
1244
|
-
if (!check) return false;
|
|
1245
|
-
return true;
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
|
-
var check18IdCardNo = function check18IdCardNo(idCardNo) {
|
|
1249
|
-
var check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo);
|
|
1250
|
-
if (!check) return false;
|
|
1251
|
-
var addressCode = idCardNo.substring(0, 2);
|
|
1252
|
-
check = checkAddressCode(addressCode);
|
|
1253
|
-
if (!check) return false;
|
|
1254
|
-
var birDayCode = idCardNo.substring(6, 14);
|
|
1255
|
-
check = checkBirthDayCode(birDayCode);
|
|
1256
|
-
if (!check) return false;
|
|
1257
|
-
return checkParityBit(idCardNo);
|
|
1258
|
-
};
|
|
1259
|
-
|
|
1260
|
-
var checkIdCardNo = function checkIdCardNo(idCardNo) {
|
|
1261
|
-
var check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo);
|
|
1262
|
-
if (!check) return false;
|
|
1263
|
-
|
|
1264
|
-
if (idCardNo.length === 15) {
|
|
1265
|
-
return check15IdCardNo(idCardNo);
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
return check18IdCardNo(idCardNo);
|
|
1269
|
-
};
|
|
1270
|
-
|
|
1271
|
-
return checkIdCardNo(str);
|
|
1272
|
-
},
|
|
1273
|
-
'zh-TW': function zhTW(str) {
|
|
1274
|
-
var ALPHABET_CODES = {
|
|
1275
|
-
A: 10,
|
|
1276
|
-
B: 11,
|
|
1277
|
-
C: 12,
|
|
1278
|
-
D: 13,
|
|
1279
|
-
E: 14,
|
|
1280
|
-
F: 15,
|
|
1281
|
-
G: 16,
|
|
1282
|
-
H: 17,
|
|
1283
|
-
I: 34,
|
|
1284
|
-
J: 18,
|
|
1285
|
-
K: 19,
|
|
1286
|
-
L: 20,
|
|
1287
|
-
M: 21,
|
|
1288
|
-
N: 22,
|
|
1289
|
-
O: 35,
|
|
1290
|
-
P: 23,
|
|
1291
|
-
Q: 24,
|
|
1292
|
-
R: 25,
|
|
1293
|
-
S: 26,
|
|
1294
|
-
T: 27,
|
|
1295
|
-
U: 28,
|
|
1296
|
-
V: 29,
|
|
1297
|
-
W: 32,
|
|
1298
|
-
X: 30,
|
|
1299
|
-
Y: 31,
|
|
1300
|
-
Z: 33
|
|
1301
|
-
};
|
|
1302
|
-
var sanitized = str.trim().toUpperCase();
|
|
1303
|
-
if (!/^[A-Z][0-9]{9}$/.test(sanitized)) return false;
|
|
1304
|
-
return Array.from(sanitized).reduce(function (sum, number, index) {
|
|
1305
|
-
if (index === 0) {
|
|
1306
|
-
var code = ALPHABET_CODES[number];
|
|
1307
|
-
return code % 10 * 9 + Math.floor(code / 10);
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
if (index === 9) {
|
|
1311
|
-
return (10 - sum % 10 - Number(number)) % 10 === 0;
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
return sum + Number(number) * (9 - index);
|
|
1315
|
-
}, 0);
|
|
1316
|
-
}
|
|
1317
|
-
};
|
|
1318
|
-
function isIdentityCard(str, locale) {
|
|
1319
|
-
assertString(str);
|
|
1320
|
-
|
|
1321
|
-
if (locale in validators) {
|
|
1322
|
-
return validators[locale](str);
|
|
1323
|
-
} else if (locale === 'any') {
|
|
1324
|
-
for (var key in validators) {
|
|
1325
|
-
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
|
|
1326
|
-
// istanbul ignore else
|
|
1327
|
-
if (validators.hasOwnProperty(key)) {
|
|
1328
|
-
var validator = validators[key];
|
|
1329
|
-
|
|
1330
|
-
if (validator(str)) {
|
|
1331
|
-
return true;
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
return false;
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
throw new Error("Invalid locale '".concat(locale, "'"));
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
function _typeof$2(obj) {
|
|
1343
|
-
"@babel/helpers - typeof";
|
|
1344
|
-
|
|
1345
|
-
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
1346
|
-
_typeof$2 = function _typeof(obj) {
|
|
1347
|
-
return typeof obj;
|
|
1348
|
-
};
|
|
1349
|
-
} else {
|
|
1350
|
-
_typeof$2 = function _typeof(obj) {
|
|
1351
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
1352
|
-
};
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
return _typeof$2(obj);
|
|
1356
|
-
}
|
|
1357
|
-
var default_json_options = {
|
|
1358
|
-
allow_primitives: false
|
|
1359
|
-
};
|
|
1360
|
-
function isJSON(str, options) {
|
|
1361
|
-
assertString(str);
|
|
1362
|
-
|
|
1363
|
-
try {
|
|
1364
|
-
options = merge(options, default_json_options);
|
|
1365
|
-
var primitives = [];
|
|
1366
|
-
|
|
1367
|
-
if (options.allow_primitives) {
|
|
1368
|
-
primitives = [null, false, true];
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
var obj = JSON.parse(str);
|
|
1372
|
-
return primitives.includes(obj) || !!obj && _typeof$2(obj) === 'object';
|
|
1373
|
-
} catch (e) {
|
|
1374
|
-
/* ignore */
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
return false;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
var localeReg = /^[A-z]{2,4}([_-]([A-z]{4}|[\d]{3}))?([_-]([A-z]{2}|[\d]{3}))?$/;
|
|
1381
|
-
function isLocale(str) {
|
|
1382
|
-
assertString(str);
|
|
1383
|
-
|
|
1384
|
-
if (str === 'en_US_POSIX' || str === 'ca_ES_VALENCIA') {
|
|
1385
|
-
return true;
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
return localeReg.test(str);
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
/*
|
|
1392
|
-
Checks if the provided string matches to a correct Media type format (MIME type)
|
|
1393
|
-
|
|
1394
|
-
This function only checks is the string format follows the
|
|
1395
|
-
etablished rules by the according RFC specifications.
|
|
1396
|
-
This function supports 'charset' in textual media types
|
|
1397
|
-
(https://tools.ietf.org/html/rfc6657).
|
|
1398
|
-
|
|
1399
|
-
This function does not check against all the media types listed
|
|
1400
|
-
by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml)
|
|
1401
|
-
because of lightness purposes : it would require to include
|
|
1402
|
-
all these MIME types in this librairy, which would weigh it
|
|
1403
|
-
significantly. This kind of effort maybe is not worth for the use that
|
|
1404
|
-
this function has in this entire librairy.
|
|
1405
|
-
|
|
1406
|
-
More informations in the RFC specifications :
|
|
1407
|
-
- https://tools.ietf.org/html/rfc2045
|
|
1408
|
-
- https://tools.ietf.org/html/rfc2046
|
|
1409
|
-
- https://tools.ietf.org/html/rfc7231#section-3.1.1.1
|
|
1410
|
-
- https://tools.ietf.org/html/rfc7231#section-3.1.1.5
|
|
1411
|
-
*/
|
|
1412
|
-
// Match simple MIME types
|
|
1413
|
-
// NB :
|
|
1414
|
-
// Subtype length must not exceed 100 characters.
|
|
1415
|
-
// This rule does not comply to the RFC specs (what is the max length ?).
|
|
1416
|
-
|
|
1417
|
-
var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i; // eslint-disable-line max-len
|
|
1418
|
-
// Handle "charset" in "text/*"
|
|
1419
|
-
|
|
1420
|
-
var mimeTypeText = /^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i; // eslint-disable-line max-len
|
|
1421
|
-
// Handle "boundary" in "multipart/*"
|
|
1422
|
-
|
|
1423
|
-
var mimeTypeMultipart = /^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i; // eslint-disable-line max-len
|
|
1424
|
-
|
|
1425
|
-
function isMimeType(str) {
|
|
1426
|
-
assertString(str);
|
|
1427
|
-
return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str);
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
/* eslint-disable max-len */
|
|
1431
|
-
|
|
1432
|
-
var phones = {
|
|
1433
|
-
'am-AM': /^(\+?374|0)((10|[9|7][0-9])\d{6}$|[2-4]\d{7}$)/,
|
|
1434
|
-
'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/,
|
|
1435
|
-
'ar-BH': /^(\+?973)?(3|6)\d{7}$/,
|
|
1436
|
-
'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/,
|
|
1437
|
-
'ar-EG': /^((\+?20)|0)?1[0125]\d{8}$/,
|
|
1438
|
-
'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/,
|
|
1439
|
-
'ar-JO': /^(\+?962|0)?7[789]\d{7}$/,
|
|
1440
|
-
'ar-KW': /^(\+?965)[569]\d{7}$/,
|
|
1441
|
-
'ar-LY': /^((\+?218)|0)?(9[1-6]\d{7}|[1-8]\d{7,9})$/,
|
|
1442
|
-
'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/,
|
|
1443
|
-
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
|
|
1444
|
-
'ar-TN': /^(\+?216)?[2459]\d{7}$/,
|
|
1445
|
-
'az-AZ': /^(\+994|0)(5[015]|7[07]|99)\d{7}$/,
|
|
1446
|
-
'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
|
|
1447
|
-
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
|
|
1448
|
-
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
|
|
1449
|
-
'bn-BD': /^(\+?880|0)1[13456789][0-9]{8}$/,
|
|
1450
|
-
'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
|
|
1451
|
-
'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,
|
|
1452
|
-
'de-DE': /^(\+49)?0?[1|3]([0|5][0-45-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,
|
|
1453
|
-
'de-AT': /^(\+43|0)\d{1,4}\d{3,12}$/,
|
|
1454
|
-
'de-CH': /^(\+41|0)(7[5-9])\d{1,7}$/,
|
|
1455
|
-
'el-GR': /^(\+?30|0)?(69\d{8})$/,
|
|
1456
|
-
'en-AU': /^(\+?61|0)4\d{8}$/,
|
|
1457
|
-
'en-GB': /^(\+?44|0)7\d{9}$/,
|
|
1458
|
-
'en-GG': /^(\+?44|0)1481\d{6}$/,
|
|
1459
|
-
'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,
|
|
1460
|
-
'en-HK': /^(\+?852[-\s]?)?[456789]\d{3}[-\s]?\d{4}$/,
|
|
1461
|
-
'en-MO': /^(\+?853[-\s]?)?[6]\d{3}[-\s]?\d{4}$/,
|
|
1462
|
-
'en-IE': /^(\+?353|0)8[356789]\d{7}$/,
|
|
1463
|
-
'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
|
|
1464
|
-
'en-KE': /^(\+?254|0)(7|1)\d{8}$/,
|
|
1465
|
-
'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/,
|
|
1466
|
-
'en-MU': /^(\+?230|0)?\d{8}$/,
|
|
1467
|
-
'en-NG': /^(\+?234|0)?[789]\d{9}$/,
|
|
1468
|
-
'en-NZ': /^(\+?64|0)[28]\d{7,9}$/,
|
|
1469
|
-
'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,
|
|
1470
|
-
'en-PH': /^(09|\+639)\d{9}$/,
|
|
1471
|
-
'en-RW': /^(\+?250|0)?[7]\d{8}$/,
|
|
1472
|
-
'en-SG': /^(\+65)?[689]\d{7}$/,
|
|
1473
|
-
'en-SL': /^(?:0|94|\+94)?(7(0|1|2|5|6|7|8)( |-)?\d)\d{6}$/,
|
|
1474
|
-
'en-TZ': /^(\+?255|0)?[67]\d{8}$/,
|
|
1475
|
-
'en-UG': /^(\+?256|0)?[7]\d{8}$/,
|
|
1476
|
-
'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,
|
|
1477
|
-
'en-ZA': /^(\+?27|0)\d{9}$/,
|
|
1478
|
-
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
|
|
1479
|
-
'en-ZW': /^(\+263)[0-9]{9}$/,
|
|
1480
|
-
'es-CO': /^(\+?57)?([1-8]{1}|3[0-9]{2})?[2-9]{1}\d{6}$/,
|
|
1481
|
-
'es-CL': /^(\+?56|0)[2-9]\d{1}\d{7}$/,
|
|
1482
|
-
'es-CR': /^(\+506)?[2-8]\d{7}$/,
|
|
1483
|
-
'es-EC': /^(\+?593|0)([2-7]|9[2-9])\d{7}$/,
|
|
1484
|
-
'es-ES': /^(\+?34)?[6|7]\d{8}$/,
|
|
1485
|
-
'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/,
|
|
1486
|
-
'es-PA': /^(\+?507)\d{7,8}$/,
|
|
1487
|
-
'es-PY': /^(\+?595|0)9[9876]\d{7}$/,
|
|
1488
|
-
'es-UY': /^(\+598|0)9[1-9][\d]{6}$/,
|
|
1489
|
-
'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,
|
|
1490
|
-
'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
|
|
1491
|
-
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,
|
|
1492
|
-
'fj-FJ': /^(\+?679)?\s?\d{3}\s?\d{4}$/,
|
|
1493
|
-
'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
|
|
1494
|
-
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
|
|
1495
|
-
'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/,
|
|
1496
|
-
'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/,
|
|
1497
|
-
'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/,
|
|
1498
|
-
'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/,
|
|
1499
|
-
'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,
|
|
1500
|
-
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
|
|
1501
|
-
'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,
|
|
1502
|
-
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
|
|
1503
|
-
'ja-JP': /^(\+81[ \-]?(\(0\))?|0)[6789]0[ \-]?\d{4}[ \-]?\d{4}$/,
|
|
1504
|
-
'kk-KZ': /^(\+?7|8)?7\d{9}$/,
|
|
1505
|
-
'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,
|
|
1506
|
-
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
|
|
1507
|
-
'lt-LT': /^(\+370|8)\d{8}$/,
|
|
1508
|
-
'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
|
|
1509
|
-
'nb-NO': /^(\+?47)?[49]\d{7}$/,
|
|
1510
|
-
'ne-NP': /^(\+?977)?9[78]\d{8}$/,
|
|
1511
|
-
'nl-BE': /^(\+?32|0)4?\d{8}$/,
|
|
1512
|
-
'nl-NL': /^(((\+|00)?31\(0\))|((\+|00)?31)|0)6{1}\d{8}$/,
|
|
1513
|
-
'nn-NO': /^(\+?47)?[49]\d{7}$/,
|
|
1514
|
-
'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,
|
|
1515
|
-
'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,
|
|
1516
|
-
'pt-PT': /^(\+?351)?9[1236]\d{7}$/,
|
|
1517
|
-
'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,
|
|
1518
|
-
'ru-RU': /^(\+?7|8)?9\d{9}$/,
|
|
1519
|
-
'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,
|
|
1520
|
-
'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,
|
|
1521
|
-
'sr-RS': /^(\+3816|06)[- \d]{5,9}$/,
|
|
1522
|
-
'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,
|
|
1523
|
-
'th-TH': /^(\+66|66|0)\d{9}$/,
|
|
1524
|
-
'tr-TR': /^(\+?90|0)?5\d{9}$/,
|
|
1525
|
-
'uk-UA': /^(\+?38|8)?0\d{9}$/,
|
|
1526
|
-
'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/,
|
|
1527
|
-
'vi-VN': /^(\+?84|0)((3([2-9]))|(5([2689]))|(7([0|6-9]))|(8([1-6|89]))|(9([0-9])))([0-9]{7})$/,
|
|
1528
|
-
'zh-CN': /^((\+|00)86)?1([3568][0-9]|4[579]|6[67]|7[01235678]|9[012356789])[0-9]{8}$/,
|
|
1529
|
-
'zh-TW': /^(\+?886\-?|0)?9\d{8}$/
|
|
1530
|
-
};
|
|
1531
|
-
/* eslint-enable max-len */
|
|
1532
|
-
// aliases
|
|
1533
|
-
|
|
1534
|
-
phones['en-CA'] = phones['en-US'];
|
|
1535
|
-
phones['fr-BE'] = phones['nl-BE'];
|
|
1536
|
-
phones['zh-HK'] = phones['en-HK'];
|
|
1537
|
-
phones['zh-MO'] = phones['en-MO'];
|
|
1538
|
-
function isMobilePhone(str, locale, options) {
|
|
1539
|
-
assertString(str);
|
|
1540
|
-
|
|
1541
|
-
if (options && options.strictMode && !str.startsWith('+')) {
|
|
1542
|
-
return false;
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
if (Array.isArray(locale)) {
|
|
1546
|
-
return locale.some(function (key) {
|
|
1547
|
-
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
|
|
1548
|
-
// istanbul ignore else
|
|
1549
|
-
if (phones.hasOwnProperty(key)) {
|
|
1550
|
-
var phone = phones[key];
|
|
1551
|
-
|
|
1552
|
-
if (phone.test(str)) {
|
|
1553
|
-
return true;
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
return false;
|
|
1558
|
-
});
|
|
1559
|
-
} else if (locale in phones) {
|
|
1560
|
-
return phones[locale].test(str); // alias falsey locale as 'any'
|
|
1561
|
-
} else if (!locale || locale === 'any') {
|
|
1562
|
-
for (var key in phones) {
|
|
1563
|
-
// istanbul ignore else
|
|
1564
|
-
if (phones.hasOwnProperty(key)) {
|
|
1565
|
-
var phone = phones[key];
|
|
1566
|
-
|
|
1567
|
-
if (phone.test(str)) {
|
|
1568
|
-
return true;
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
return false;
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
throw new Error("Invalid locale '".concat(locale, "'"));
|
|
1577
|
-
}
|
|
1578
|
-
var locales$1 = Object.keys(phones);
|
|
1579
|
-
|
|
1580
|
-
/**
|
|
1581
|
-
* Reference:
|
|
1582
|
-
* https://en.wikipedia.org/ -- Wikipedia
|
|
1583
|
-
* https://docs.microsoft.com/en-us/microsoft-365/compliance/eu-passport-number -- EU Passport Number
|
|
1584
|
-
* https://countrycode.org/ -- Country Codes
|
|
1585
|
-
*/
|
|
1586
|
-
|
|
1587
|
-
var passportRegexByCountryCode = {
|
|
1588
|
-
AM: /^[A-Z]{2}\d{7}$/,
|
|
1589
|
-
// ARMENIA
|
|
1590
|
-
AR: /^[A-Z]{3}\d{6}$/,
|
|
1591
|
-
// ARGENTINA
|
|
1592
|
-
AT: /^[A-Z]\d{7}$/,
|
|
1593
|
-
// AUSTRIA
|
|
1594
|
-
AU: /^[A-Z]\d{7}$/,
|
|
1595
|
-
// AUSTRALIA
|
|
1596
|
-
BE: /^[A-Z]{2}\d{6}$/,
|
|
1597
|
-
// BELGIUM
|
|
1598
|
-
BG: /^\d{9}$/,
|
|
1599
|
-
// BULGARIA
|
|
1600
|
-
CA: /^[A-Z]{2}\d{6}$/,
|
|
1601
|
-
// CANADA
|
|
1602
|
-
CH: /^[A-Z]\d{7}$/,
|
|
1603
|
-
// SWITZERLAND
|
|
1604
|
-
CN: /^[GE]\d{8}$/,
|
|
1605
|
-
// CHINA [G=Ordinary, E=Electronic] followed by 8-digits
|
|
1606
|
-
CY: /^[A-Z](\d{6}|\d{8})$/,
|
|
1607
|
-
// CYPRUS
|
|
1608
|
-
CZ: /^\d{8}$/,
|
|
1609
|
-
// CZECH REPUBLIC
|
|
1610
|
-
DE: /^[CFGHJKLMNPRTVWXYZ0-9]{9}$/,
|
|
1611
|
-
// GERMANY
|
|
1612
|
-
DK: /^\d{9}$/,
|
|
1613
|
-
// DENMARK
|
|
1614
|
-
DZ: /^\d{9}$/,
|
|
1615
|
-
// ALGERIA
|
|
1616
|
-
EE: /^([A-Z]\d{7}|[A-Z]{2}\d{7})$/,
|
|
1617
|
-
// ESTONIA (K followed by 7-digits), e-passports have 2 UPPERCASE followed by 7 digits
|
|
1618
|
-
ES: /^[A-Z0-9]{2}([A-Z0-9]?)\d{6}$/,
|
|
1619
|
-
// SPAIN
|
|
1620
|
-
FI: /^[A-Z]{2}\d{7}$/,
|
|
1621
|
-
// FINLAND
|
|
1622
|
-
FR: /^\d{2}[A-Z]{2}\d{5}$/,
|
|
1623
|
-
// FRANCE
|
|
1624
|
-
GB: /^\d{9}$/,
|
|
1625
|
-
// UNITED KINGDOM
|
|
1626
|
-
GR: /^[A-Z]{2}\d{7}$/,
|
|
1627
|
-
// GREECE
|
|
1628
|
-
HR: /^\d{9}$/,
|
|
1629
|
-
// CROATIA
|
|
1630
|
-
HU: /^[A-Z]{2}(\d{6}|\d{7})$/,
|
|
1631
|
-
// HUNGARY
|
|
1632
|
-
IE: /^[A-Z0-9]{2}\d{7}$/,
|
|
1633
|
-
// IRELAND
|
|
1634
|
-
IN: /^[A-Z]{1}-?\d{7}$/,
|
|
1635
|
-
// INDIA
|
|
1636
|
-
IS: /^(A)\d{7}$/,
|
|
1637
|
-
// ICELAND
|
|
1638
|
-
IT: /^[A-Z0-9]{2}\d{7}$/,
|
|
1639
|
-
// ITALY
|
|
1640
|
-
JP: /^[A-Z]{2}\d{7}$/,
|
|
1641
|
-
// JAPAN
|
|
1642
|
-
KR: /^[MS]\d{8}$/,
|
|
1643
|
-
// SOUTH KOREA, REPUBLIC OF KOREA, [S=PS Passports, M=PM Passports]
|
|
1644
|
-
LT: /^[A-Z0-9]{8}$/,
|
|
1645
|
-
// LITHUANIA
|
|
1646
|
-
LU: /^[A-Z0-9]{8}$/,
|
|
1647
|
-
// LUXEMBURG
|
|
1648
|
-
LV: /^[A-Z0-9]{2}\d{7}$/,
|
|
1649
|
-
// LATVIA
|
|
1650
|
-
MT: /^\d{7}$/,
|
|
1651
|
-
// MALTA
|
|
1652
|
-
NL: /^[A-Z]{2}[A-Z0-9]{6}\d$/,
|
|
1653
|
-
// NETHERLANDS
|
|
1654
|
-
PO: /^[A-Z]{2}\d{7}$/,
|
|
1655
|
-
// POLAND
|
|
1656
|
-
PT: /^[A-Z]\d{6}$/,
|
|
1657
|
-
// PORTUGAL
|
|
1658
|
-
RO: /^\d{8,9}$/,
|
|
1659
|
-
// ROMANIA
|
|
1660
|
-
SE: /^\d{8}$/,
|
|
1661
|
-
// SWEDEN
|
|
1662
|
-
SL: /^(P)[A-Z]\d{7}$/,
|
|
1663
|
-
// SLOVANIA
|
|
1664
|
-
SK: /^[0-9A-Z]\d{7}$/,
|
|
1665
|
-
// SLOVAKIA
|
|
1666
|
-
TR: /^[A-Z]\d{8}$/,
|
|
1667
|
-
// TURKEY
|
|
1668
|
-
UA: /^[A-Z]{2}\d{6}$/,
|
|
1669
|
-
// UKRAINE
|
|
1670
|
-
US: /^\d{9}$/ // UNITED STATES
|
|
1671
|
-
|
|
1672
|
-
};
|
|
1673
|
-
/**
|
|
1674
|
-
* Check if str is a valid passport number
|
|
1675
|
-
* relative to provided ISO Country Code.
|
|
1676
|
-
*
|
|
1677
|
-
* @param {string} str
|
|
1678
|
-
* @param {string} countryCode
|
|
1679
|
-
* @return {boolean}
|
|
1680
|
-
*/
|
|
1681
|
-
|
|
1682
|
-
function isPassportNumber(str, countryCode) {
|
|
1683
|
-
assertString(str);
|
|
1684
|
-
/** Remove All Whitespaces, Convert to UPPERCASE */
|
|
1685
|
-
|
|
1686
|
-
var normalizedStr = str.replace(/\s/g, '').toUpperCase();
|
|
1687
|
-
return countryCode.toUpperCase() in passportRegexByCountryCode && passportRegexByCountryCode[countryCode].test(normalizedStr);
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
var threeDigit = /^\d{3}$/;
|
|
1691
|
-
var fourDigit = /^\d{4}$/;
|
|
1692
|
-
var fiveDigit = /^\d{5}$/;
|
|
1693
|
-
var sixDigit = /^\d{6}$/;
|
|
1694
|
-
var patterns = {
|
|
1695
|
-
AD: /^AD\d{3}$/,
|
|
1696
|
-
AT: fourDigit,
|
|
1697
|
-
AU: fourDigit,
|
|
1698
|
-
AZ: /^AZ\d{4}$/,
|
|
1699
|
-
BE: fourDigit,
|
|
1700
|
-
BG: fourDigit,
|
|
1701
|
-
BR: /^\d{5}-\d{3}$/,
|
|
1702
|
-
CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
1703
|
-
CH: fourDigit,
|
|
1704
|
-
CZ: /^\d{3}\s?\d{2}$/,
|
|
1705
|
-
DE: fiveDigit,
|
|
1706
|
-
DK: fourDigit,
|
|
1707
|
-
DZ: fiveDigit,
|
|
1708
|
-
EE: fiveDigit,
|
|
1709
|
-
ES: /^(5[0-2]{1}|[0-4]{1}\d{1})\d{3}$/,
|
|
1710
|
-
FI: fiveDigit,
|
|
1711
|
-
FR: /^\d{2}\s?\d{3}$/,
|
|
1712
|
-
GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,
|
|
1713
|
-
GR: /^\d{3}\s?\d{2}$/,
|
|
1714
|
-
HR: /^([1-5]\d{4}$)/,
|
|
1715
|
-
HU: fourDigit,
|
|
1716
|
-
ID: fiveDigit,
|
|
1717
|
-
IE: /^(?!.*(?:o))[A-z]\d[\dw]\s\w{4}$/i,
|
|
1718
|
-
IL: /^(\d{5}|\d{7})$/,
|
|
1719
|
-
IN: /^((?!10|29|35|54|55|65|66|86|87|88|89)[1-9][0-9]{5})$/,
|
|
1720
|
-
IS: threeDigit,
|
|
1721
|
-
IT: fiveDigit,
|
|
1722
|
-
JP: /^\d{3}\-\d{4}$/,
|
|
1723
|
-
KE: fiveDigit,
|
|
1724
|
-
LI: /^(948[5-9]|949[0-7])$/,
|
|
1725
|
-
LT: /^LT\-\d{5}$/,
|
|
1726
|
-
LU: fourDigit,
|
|
1727
|
-
LV: /^LV\-\d{4}$/,
|
|
1728
|
-
MX: fiveDigit,
|
|
1729
|
-
MT: /^[A-Za-z]{3}\s{0,1}\d{4}$/,
|
|
1730
|
-
NL: /^\d{4}\s?[a-z]{2}$/i,
|
|
1731
|
-
NO: fourDigit,
|
|
1732
|
-
NP: /^(10|21|22|32|33|34|44|45|56|57)\d{3}$|^(977)$/i,
|
|
1733
|
-
NZ: fourDigit,
|
|
1734
|
-
PL: /^\d{2}\-\d{3}$/,
|
|
1735
|
-
PR: /^00[679]\d{2}([ -]\d{4})?$/,
|
|
1736
|
-
PT: /^\d{4}\-\d{3}?$/,
|
|
1737
|
-
RO: sixDigit,
|
|
1738
|
-
RU: sixDigit,
|
|
1739
|
-
SA: fiveDigit,
|
|
1740
|
-
SE: /^[1-9]\d{2}\s?\d{2}$/,
|
|
1741
|
-
SI: fourDigit,
|
|
1742
|
-
SK: /^\d{3}\s?\d{2}$/,
|
|
1743
|
-
TN: fourDigit,
|
|
1744
|
-
TW: /^\d{3}(\d{2})?$/,
|
|
1745
|
-
UA: fiveDigit,
|
|
1746
|
-
US: /^\d{5}(-\d{4})?$/,
|
|
1747
|
-
ZA: fourDigit,
|
|
1748
|
-
ZM: fiveDigit
|
|
1749
|
-
};
|
|
1750
|
-
var locales$2 = Object.keys(patterns);
|
|
1751
|
-
function isPostalCode(str, locale) {
|
|
1752
|
-
assertString(str);
|
|
1753
|
-
|
|
1754
|
-
if (locale in patterns) {
|
|
1755
|
-
return patterns[locale].test(str);
|
|
1756
|
-
} else if (locale === 'any') {
|
|
1757
|
-
for (var key in patterns) {
|
|
1758
|
-
// https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md#ignoring-code-for-coverage-purposes
|
|
1759
|
-
// istanbul ignore else
|
|
1760
|
-
if (patterns.hasOwnProperty(key)) {
|
|
1761
|
-
var pattern = patterns[key];
|
|
1762
|
-
|
|
1763
|
-
if (pattern.test(str)) {
|
|
1764
|
-
return true;
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
|
|
1769
|
-
return false;
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
throw new Error("Invalid locale '".concat(locale, "'"));
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
/*
|
|
1776
|
-
options for isURL method
|
|
1777
|
-
|
|
1778
|
-
require_protocol - if set as true isURL will return false if protocol is not present in the URL
|
|
1779
|
-
require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option
|
|
1780
|
-
protocols - valid protocols can be modified with this option
|
|
1781
|
-
require_host - if set as false isURL will not check if host is present in the URL
|
|
1782
|
-
allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed
|
|
1783
|
-
validate_length - if set as false isURL will skip string length validation (IE maximum is 2083)
|
|
1784
|
-
|
|
1785
|
-
*/
|
|
1786
|
-
|
|
1787
|
-
var default_url_options = {
|
|
1788
|
-
protocols: ['http', 'https', 'ftp'],
|
|
1789
|
-
require_tld: true,
|
|
1790
|
-
require_protocol: false,
|
|
1791
|
-
require_host: true,
|
|
1792
|
-
require_valid_protocol: true,
|
|
1793
|
-
allow_underscores: false,
|
|
1794
|
-
allow_trailing_dot: false,
|
|
1795
|
-
allow_protocol_relative_urls: false,
|
|
1796
|
-
validate_length: true
|
|
1797
|
-
};
|
|
1798
|
-
var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/;
|
|
1799
|
-
|
|
1800
|
-
function isRegExp(obj) {
|
|
1801
|
-
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
function checkHost(host, matches) {
|
|
1805
|
-
for (var i = 0; i < matches.length; i++) {
|
|
1806
|
-
var match = matches[i];
|
|
1807
|
-
|
|
1808
|
-
if (host === match || isRegExp(match) && match.test(host)) {
|
|
1809
|
-
return true;
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
|
|
1813
|
-
return false;
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
function isURL(url, options) {
|
|
1817
|
-
assertString(url);
|
|
1818
|
-
|
|
1819
|
-
if (!url || /[\s<>]/.test(url)) {
|
|
1820
|
-
return false;
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
if (url.indexOf('mailto:') === 0) {
|
|
1824
|
-
return false;
|
|
1825
|
-
}
|
|
1826
|
-
|
|
1827
|
-
options = merge(options, default_url_options);
|
|
1828
|
-
|
|
1829
|
-
if (options.validate_length && url.length >= 2083) {
|
|
1830
|
-
return false;
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
var protocol, auth, host, hostname, port, port_str, split, ipv6;
|
|
1834
|
-
split = url.split('#');
|
|
1835
|
-
url = split.shift();
|
|
1836
|
-
split = url.split('?');
|
|
1837
|
-
url = split.shift();
|
|
1838
|
-
split = url.split('://');
|
|
1839
|
-
|
|
1840
|
-
if (split.length > 1) {
|
|
1841
|
-
protocol = split.shift().toLowerCase();
|
|
1842
|
-
|
|
1843
|
-
if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) {
|
|
1844
|
-
return false;
|
|
1845
|
-
}
|
|
1846
|
-
} else if (options.require_protocol) {
|
|
1847
|
-
return false;
|
|
1848
|
-
} else if (url.substr(0, 2) === '//') {
|
|
1849
|
-
if (!options.allow_protocol_relative_urls) {
|
|
1850
|
-
return false;
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
split[0] = url.substr(2);
|
|
1854
|
-
}
|
|
1855
|
-
|
|
1856
|
-
url = split.join('://');
|
|
1857
|
-
|
|
1858
|
-
if (url === '') {
|
|
1859
|
-
return false;
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
split = url.split('/');
|
|
1863
|
-
url = split.shift();
|
|
1864
|
-
|
|
1865
|
-
if (url === '' && !options.require_host) {
|
|
1866
|
-
return true;
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
split = url.split('@');
|
|
1870
|
-
|
|
1871
|
-
if (split.length > 1) {
|
|
1872
|
-
if (options.disallow_auth) {
|
|
1873
|
-
return false;
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
auth = split.shift();
|
|
1877
|
-
|
|
1878
|
-
if (auth.indexOf(':') === -1 || auth.indexOf(':') >= 0 && auth.split(':').length > 2) {
|
|
1879
|
-
return false;
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
hostname = split.join('@');
|
|
1884
|
-
port_str = null;
|
|
1885
|
-
ipv6 = null;
|
|
1886
|
-
var ipv6_match = hostname.match(wrapped_ipv6);
|
|
1887
|
-
|
|
1888
|
-
if (ipv6_match) {
|
|
1889
|
-
host = '';
|
|
1890
|
-
ipv6 = ipv6_match[1];
|
|
1891
|
-
port_str = ipv6_match[2] || null;
|
|
1892
|
-
} else {
|
|
1893
|
-
split = hostname.split(':');
|
|
1894
|
-
host = split.shift();
|
|
1895
|
-
|
|
1896
|
-
if (split.length) {
|
|
1897
|
-
port_str = split.join(':');
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
|
|
1901
|
-
if (port_str !== null) {
|
|
1902
|
-
port = parseInt(port_str, 10);
|
|
1903
|
-
|
|
1904
|
-
if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) {
|
|
1905
|
-
return false;
|
|
1906
|
-
}
|
|
1907
|
-
}
|
|
1908
|
-
|
|
1909
|
-
if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) {
|
|
1910
|
-
return false;
|
|
1911
|
-
}
|
|
1912
|
-
|
|
1913
|
-
host = host || ipv6;
|
|
1914
|
-
|
|
1915
|
-
if (options.host_whitelist && !checkHost(host, options.host_whitelist)) {
|
|
1916
|
-
return false;
|
|
1917
|
-
}
|
|
1918
|
-
|
|
1919
|
-
if (options.host_blacklist && checkHost(host, options.host_blacklist)) {
|
|
1920
|
-
return false;
|
|
1921
|
-
}
|
|
1922
|
-
|
|
1923
|
-
return true;
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
var rules$1 = {
|
|
1927
|
-
isAlphanumeric,
|
|
1928
|
-
isCreditCard,
|
|
1929
|
-
isCurrency,
|
|
1930
|
-
isEmail,
|
|
1931
|
-
isIP,
|
|
1932
|
-
isIdentityCard,
|
|
1933
|
-
isJSON,
|
|
1934
|
-
isLocale,
|
|
1935
|
-
isMimeType,
|
|
1936
|
-
isMobilePhone,
|
|
1937
|
-
isPassportNumber,
|
|
1938
|
-
isPostalCode,
|
|
1939
|
-
isURL
|
|
1940
|
-
};
|
|
1941
|
-
|
|
1942
|
-
enforce$1.extend(rules$1);
|
|
1943
|
-
var index = Object.assign(enforce$1, {
|
|
1944
|
-
isAlphanumericLocales: locales,
|
|
1945
|
-
isMobilePhoneLocales: locales$1,
|
|
1946
|
-
isPostalCodeLocales: locales$2
|
|
1947
|
-
});
|
|
1948
|
-
|
|
1949
|
-
module.exports = index;
|