@bedrockio/yada 1.8.3 → 1.9.0
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 +5 -1
- package/dist/cjs/string.js +16 -1
- package/package.json +2 -2
- package/src/string.js +17 -1
- package/types/string.d.ts +4 -0
- package/types/string.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/string.js
CHANGED
|
@@ -14,6 +14,8 @@ const SLUG_REG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
|
14
14
|
const PHONE_REG = /^\+\d{1,3}\d{3,14}$/;
|
|
15
15
|
const NANP_REG = /^\+1[2-9]\d{2}[2-9]\d{6}$/;
|
|
16
16
|
const DATE_REG = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[01])$/;
|
|
17
|
+
const LOCALE_REG = /^[a-z]{2,3}(-[A-Z][a-z]{3})?(-[A-Z]{2})?$/;
|
|
18
|
+
const TIME_REG = /^(?:[0-2][0-9])(?::[0-5][0-9])?(?::[0-5][0-9])?(?:\.\d{3})?(?:Z|(?:[+-]0[0-9]|-1[0-2]|\+1[0-4]):[0-5][0-9])?$/;
|
|
17
19
|
const E164_DESCRIPTION = 'A phone number in [E.164](https://en.wikipedia.org/wiki/E.164) format.';
|
|
18
20
|
const NANP_DESCRIPTION = 'A phone number in [NANP](https://en.wikipedia.org/wiki/North_American_Numbering_Plan) format.';
|
|
19
21
|
class StringSchema extends _TypeSchema.default {
|
|
@@ -227,7 +229,9 @@ class StringSchema extends _TypeSchema.default {
|
|
|
227
229
|
}
|
|
228
230
|
locale() {
|
|
229
231
|
return this.format('locale', str => {
|
|
230
|
-
|
|
232
|
+
// Switch to simple regex while this bug is being fixed:
|
|
233
|
+
// https://github.com/validatorjs/validator.js/issues/2342
|
|
234
|
+
if (!LOCALE_REG.test(str)) {
|
|
231
235
|
throw new _errors.LocalizedError('Must be a valid locale code.');
|
|
232
236
|
}
|
|
233
237
|
});
|
|
@@ -404,6 +408,17 @@ class StringSchema extends _TypeSchema.default {
|
|
|
404
408
|
}
|
|
405
409
|
});
|
|
406
410
|
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Validates times in ISO-8601 format.
|
|
414
|
+
*/
|
|
415
|
+
time() {
|
|
416
|
+
return this.format('time', str => {
|
|
417
|
+
if (!TIME_REG.test(str)) {
|
|
418
|
+
throw new _errors.LocalizedError('Must be an ISO-8601 time.');
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
}
|
|
407
422
|
format(name, fn) {
|
|
408
423
|
return this.clone({
|
|
409
424
|
format: name
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrockio/yada",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Validation library inspired by Joi.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
|
-
"validator": "^13.
|
|
21
|
+
"validator": "^13.15.20"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@babel/cli": "^7.20.7",
|
package/src/string.js
CHANGED
|
@@ -18,6 +18,9 @@ const SLUG_REG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
|
18
18
|
const PHONE_REG = /^\+\d{1,3}\d{3,14}$/;
|
|
19
19
|
const NANP_REG = /^\+1[2-9]\d{2}[2-9]\d{6}$/;
|
|
20
20
|
const DATE_REG = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[01])$/;
|
|
21
|
+
const LOCALE_REG = /^[a-z]{2,3}(-[A-Z][a-z]{3})?(-[A-Z]{2})?$/;
|
|
22
|
+
const TIME_REG =
|
|
23
|
+
/^(?:[0-2][0-9])(?::[0-5][0-9])?(?::[0-5][0-9])?(?:\.\d{3})?(?:Z|(?:[+-]0[0-9]|-1[0-2]|\+1[0-4]):[0-5][0-9])?$/;
|
|
21
24
|
|
|
22
25
|
const E164_DESCRIPTION =
|
|
23
26
|
'A phone number in [E.164](https://en.wikipedia.org/wiki/E.164) format.';
|
|
@@ -238,7 +241,9 @@ class StringSchema extends TypeSchema {
|
|
|
238
241
|
|
|
239
242
|
locale() {
|
|
240
243
|
return this.format('locale', (str) => {
|
|
241
|
-
|
|
244
|
+
// Switch to simple regex while this bug is being fixed:
|
|
245
|
+
// https://github.com/validatorjs/validator.js/issues/2342
|
|
246
|
+
if (!LOCALE_REG.test(str)) {
|
|
242
247
|
throw new LocalizedError('Must be a valid locale code.');
|
|
243
248
|
}
|
|
244
249
|
});
|
|
@@ -427,6 +432,17 @@ class StringSchema extends TypeSchema {
|
|
|
427
432
|
});
|
|
428
433
|
}
|
|
429
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Validates times in ISO-8601 format.
|
|
437
|
+
*/
|
|
438
|
+
time() {
|
|
439
|
+
return this.format('time', (str) => {
|
|
440
|
+
if (!TIME_REG.test(str)) {
|
|
441
|
+
throw new LocalizedError('Must be an ISO-8601 time.');
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
|
|
430
446
|
format(name, fn) {
|
|
431
447
|
return this.clone({ format: name }).assert(
|
|
432
448
|
'format',
|
package/types/string.d.ts
CHANGED
package/types/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.js"],"names":[],"mappings":"AAydA;;GAEG;AACH,iDAEC;AAhcD;IACE,cAmBC;IAED;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;OAEG;IACH,eAFW,MAAM,QAUhB;IAED;;O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