@bedrockio/yada 1.0.29 → 1.0.30
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/README.md +7 -0
- package/dist/cjs/Schema.js +4 -3
- package/package.json +2 -2
- package/src/Schema.js +4 -3
- package/types/Schema.d.ts +1 -1
- package/types/Schema.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -527,6 +527,13 @@ console.log(await schema.validate()); // "hi!"
|
|
|
527
527
|
console.log(await schema.validate('hello!')); // "hello!"
|
|
528
528
|
```
|
|
529
529
|
|
|
530
|
+
Note that the argument passed to default may also be a function:
|
|
531
|
+
|
|
532
|
+
```js
|
|
533
|
+
const schema = yd.string().default(Date.now);
|
|
534
|
+
console.log(await schema.validate()); // Returns current timestamp
|
|
535
|
+
```
|
|
536
|
+
|
|
530
537
|
### Strip
|
|
531
538
|
|
|
532
539
|
The `strip` method serves as a way to conditionally exclude fields when the
|
package/dist/cjs/Schema.js
CHANGED
|
@@ -39,12 +39,13 @@ class Schema {
|
|
|
39
39
|
* Sets the schema default. [Link](https://github.com/bedrockio/yada#default)
|
|
40
40
|
* @returns {this}
|
|
41
41
|
*/
|
|
42
|
-
default(
|
|
42
|
+
default(arg) {
|
|
43
|
+
const getDefaultValue = typeof arg === 'function' ? arg : () => arg;
|
|
43
44
|
return this.clone({
|
|
44
|
-
default:
|
|
45
|
+
default: arg
|
|
45
46
|
}).assert('default', val => {
|
|
46
47
|
if (val === undefined) {
|
|
47
|
-
return
|
|
48
|
+
return getDefaultValue();
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrockio/yada",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "Validation library inspired by Joi.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"babel-plugin-add-module-exports": "^1.0.4",
|
|
28
28
|
"eslint": "^8.26.0",
|
|
29
29
|
"eslint-plugin-bedrock": "^1.0.24",
|
|
30
|
-
"jest": "^29.
|
|
30
|
+
"jest": "^29.6.2",
|
|
31
31
|
"prettier": "^2.7.1",
|
|
32
32
|
"prettier-eslint": "^15.0.1",
|
|
33
33
|
"typescript": "^4.9.5"
|
package/src/Schema.js
CHANGED
|
@@ -37,10 +37,11 @@ export default class Schema {
|
|
|
37
37
|
* Sets the schema default. [Link](https://github.com/bedrockio/yada#default)
|
|
38
38
|
* @returns {this}
|
|
39
39
|
*/
|
|
40
|
-
default(
|
|
41
|
-
|
|
40
|
+
default(arg) {
|
|
41
|
+
const getDefaultValue = typeof arg === 'function' ? arg : () => arg;
|
|
42
|
+
return this.clone({ default: arg }).assert('default', (val) => {
|
|
42
43
|
if (val === undefined) {
|
|
43
|
-
return
|
|
44
|
+
return getDefaultValue();
|
|
44
45
|
}
|
|
45
46
|
});
|
|
46
47
|
}
|
package/types/Schema.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export default class Schema {
|
|
|
14
14
|
* Sets the schema default. [Link](https://github.com/bedrockio/yada#default)
|
|
15
15
|
* @returns {this}
|
|
16
16
|
*/
|
|
17
|
-
default(
|
|
17
|
+
default(arg: any): this;
|
|
18
18
|
/**
|
|
19
19
|
* Validate by a custom function. [Link](https://github.com/bedrockio/yada#custom)
|
|
20
20
|
* @param {CustomSignature} args
|
package/types/Schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAuVA,4CAEC;AA7UD;;GAEG;AAEH;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,gBAHW,eAAe,GACb,IAAI,CAmBhB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAqCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,IAAI,CAMhB;IAED,2BAUC;IAED,kBAEC;IAED,4BAMC;IAID;;OAEG;IACH,kCAFa,IAAI,CAmChB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAUC;IAED;;;;;;;;MAoCC;CACF;8BAxUY,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC"}
|