@bedrockio/yada 1.4.2 → 1.5.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 +9 -0
- package/dist/cjs/date.js +4 -8
- package/dist/cjs/string.js +21 -0
- package/package.json +1 -1
- package/src/date.js +13 -13
- package/src/string.js +21 -0
- package/types/date.d.ts +1 -4
- package/types/date.d.ts.map +1 -1
- package/types/string.d.ts +13 -0
- package/types/string.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
package/dist/cjs/date.js
CHANGED
|
@@ -95,14 +95,10 @@ class DateSchema extends _Schema.default {
|
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @param {"date" | "date-time"} format
|
|
101
|
-
*/
|
|
102
|
-
iso(format = 'date-time') {
|
|
98
|
+
iso() {
|
|
103
99
|
return this.clone({
|
|
104
|
-
format
|
|
105
|
-
}).assert('format', (
|
|
100
|
+
format: 'date-time'
|
|
101
|
+
}).assert('format', (date, options) => {
|
|
106
102
|
const {
|
|
107
103
|
original
|
|
108
104
|
} = options;
|
|
@@ -111,7 +107,7 @@ class DateSchema extends _Schema.default {
|
|
|
111
107
|
throw new _errors.LocalizedError('Must be a string.');
|
|
112
108
|
}
|
|
113
109
|
} else if (!_validator.default.isISO8601(original)) {
|
|
114
|
-
throw new _errors.LocalizedError('Must be in ISO
|
|
110
|
+
throw new _errors.LocalizedError('Must be in ISO-8601 format.');
|
|
115
111
|
}
|
|
116
112
|
});
|
|
117
113
|
}
|
package/dist/cjs/string.js
CHANGED
|
@@ -12,6 +12,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
12
12
|
const SLUG_REG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
13
13
|
const PHONE_REG = /^\+\d{1,3}\d{3,14}$/;
|
|
14
14
|
const NANP_REG = /^\+1[2-9]\d{2}[2-9]\d{6}$/;
|
|
15
|
+
const DATE_REG = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[01])$/;
|
|
15
16
|
const E164_DESCRIPTION = 'A phone number in [E.164](https://en.wikipedia.org/wiki/E.164) format.';
|
|
16
17
|
const NANP_DESCRIPTION = 'A phone number in [NANP](https://en.wikipedia.org/wiki/North_American_Numbering_Plan) format.';
|
|
17
18
|
class StringSchema extends _TypeSchema.default {
|
|
@@ -386,6 +387,26 @@ class StringSchema extends _TypeSchema.default {
|
|
|
386
387
|
}
|
|
387
388
|
});
|
|
388
389
|
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Validates a calendar date in extended ISO-8601 format:
|
|
393
|
+
*
|
|
394
|
+
* 1. Must exactly match `YYYY-MM-DD`.
|
|
395
|
+
* 2. Year may not be negative.
|
|
396
|
+
* 3. Month must be 1-12.
|
|
397
|
+
* 4. Date must be 1-31.
|
|
398
|
+
*
|
|
399
|
+
* Note that only individual components are validated so impossible
|
|
400
|
+
* dates like "2020-02-30" are still considered valid.
|
|
401
|
+
*
|
|
402
|
+
*/
|
|
403
|
+
calendar() {
|
|
404
|
+
return this.format('date', str => {
|
|
405
|
+
if (!DATE_REG.test(str)) {
|
|
406
|
+
throw new _errors.LocalizedError('Must be an ISO-8601 calendar date.');
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}
|
|
389
410
|
format(name, fn) {
|
|
390
411
|
return this.clone({
|
|
391
412
|
format: name
|
package/package.json
CHANGED
package/src/date.js
CHANGED
|
@@ -90,20 +90,20 @@ class DateSchema extends Schema {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
iso() {
|
|
94
|
+
return this.clone({ format: 'date-time' }).assert(
|
|
95
|
+
'format',
|
|
96
|
+
(date, options) => {
|
|
97
|
+
const { original } = options;
|
|
98
|
+
if (typeof original !== 'string') {
|
|
99
|
+
if (!options.default) {
|
|
100
|
+
throw new LocalizedError('Must be a string.');
|
|
101
|
+
}
|
|
102
|
+
} else if (!validator.isISO8601(original)) {
|
|
103
|
+
throw new LocalizedError('Must be in ISO-8601 format.');
|
|
102
104
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
});
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
timestamp() {
|
package/src/string.js
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
const SLUG_REG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
15
15
|
const PHONE_REG = /^\+\d{1,3}\d{3,14}$/;
|
|
16
16
|
const NANP_REG = /^\+1[2-9]\d{2}[2-9]\d{6}$/;
|
|
17
|
+
const DATE_REG = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[01])$/;
|
|
17
18
|
|
|
18
19
|
const E164_DESCRIPTION =
|
|
19
20
|
'A phone number in [E.164](https://en.wikipedia.org/wiki/E.164) format.';
|
|
@@ -404,6 +405,26 @@ class StringSchema extends TypeSchema {
|
|
|
404
405
|
});
|
|
405
406
|
}
|
|
406
407
|
|
|
408
|
+
/**
|
|
409
|
+
* Validates a calendar date in extended ISO-8601 format:
|
|
410
|
+
*
|
|
411
|
+
* 1. Must exactly match `YYYY-MM-DD`.
|
|
412
|
+
* 2. Year may not be negative.
|
|
413
|
+
* 3. Month must be 1-12.
|
|
414
|
+
* 4. Date must be 1-31.
|
|
415
|
+
*
|
|
416
|
+
* Note that only individual components are validated so impossible
|
|
417
|
+
* dates like "2020-02-30" are still considered valid.
|
|
418
|
+
*
|
|
419
|
+
*/
|
|
420
|
+
calendar() {
|
|
421
|
+
return this.format('date', (str) => {
|
|
422
|
+
if (!DATE_REG.test(str)) {
|
|
423
|
+
throw new LocalizedError('Must be an ISO-8601 calendar date.');
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
407
428
|
format(name, fn) {
|
|
408
429
|
return this.clone({ format: name }).assert(
|
|
409
430
|
'format',
|
package/types/date.d.ts
CHANGED
|
@@ -22,10 +22,7 @@ declare class DateSchema extends Schema {
|
|
|
22
22
|
after(min: string | number | Date): this;
|
|
23
23
|
past(): this;
|
|
24
24
|
future(): this;
|
|
25
|
-
|
|
26
|
-
* @param {"date" | "date-time"} format
|
|
27
|
-
*/
|
|
28
|
-
iso(format?: "date" | "date-time"): this;
|
|
25
|
+
iso(): this;
|
|
29
26
|
timestamp(): this;
|
|
30
27
|
unix(): this;
|
|
31
28
|
}
|
package/types/date.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.js"],"names":[],"mappings":"AAgKA;;GAEG;AACH,+CAEC;AAhKD;IACE,cAUC;IAED;;OAEG;IACH,SAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED;;OAEG;IACH,SAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED;;OAEG;IACH,YAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED;;OAEG;IACH,WAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED,aAOC;IAED,eAOC;IAED
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.js"],"names":[],"mappings":"AAgKA;;GAEG;AACH,+CAEC;AAhKD;IACE,cAUC;IAED;;OAEG;IACH,SAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED;;OAEG;IACH,SAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED;;OAEG;IACH,YAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED;;OAEG;IACH,WAFW,MAAM,GAAC,MAAM,GAAC,IAAI,QAW5B;IAED,aAOC;IAED,eAOC;IAED,YAcC;IAED,kBAUC;IAED,aAcC;CAwBF;mBA5JkB,UAAU"}
|
package/types/string.d.ts
CHANGED
|
@@ -121,6 +121,19 @@ declare class StringSchema extends TypeSchema {
|
|
|
121
121
|
eth(): this;
|
|
122
122
|
swift(): this;
|
|
123
123
|
mongo(): this;
|
|
124
|
+
/**
|
|
125
|
+
* Validates a calendar date in extended ISO-8601 format:
|
|
126
|
+
*
|
|
127
|
+
* 1. Must exactly match `YYYY-MM-DD`.
|
|
128
|
+
* 2. Year may not be negative.
|
|
129
|
+
* 3. Month must be 1-12.
|
|
130
|
+
* 4. Date must be 1-31.
|
|
131
|
+
*
|
|
132
|
+
* Note that only individual components are validated so impossible
|
|
133
|
+
* dates like "2020-02-30" are still considered valid.
|
|
134
|
+
*
|
|
135
|
+
*/
|
|
136
|
+
calendar(): this;
|
|
124
137
|
format(name: any, fn: any): this;
|
|
125
138
|
}
|
|
126
139
|
import TypeSchema from './TypeSchema';
|
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":"AAwcA;;GAEG;AACH,iDAEC;AArbD;IACE,cAoBC;IAED;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;OAEG;IACH,eAFW,MAAM,QAUhB;IAED;;OAEG;IACH,YAFW,MAAM,QAUhB;IAED;;OAEG;IACH,YAFW,MAAM,QAUhB;IAED,aAIC;IAED;;OAEG;IACH,mBAFW,OAAO,QAYjB;IAED;;OAEG;IACH,mBAFW,OAAO,QAYjB;IAED;;OAEG;IACH,WAFW,MAAM,QAahB;IAED,cAMC;IAED,uBASC;IAED,YAMC;IAED,YAMC;IAED,aAMC;IAED,cAMC;IAED;;;OAGG;IACH,iBAFG;QAA0B,OAAO,GAAzB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