https://github.com/afeiship/next-defaults-validate
Get defaults by validate function.
https://github.com/afeiship/next-defaults-validate
defaults next validate validator
Last synced: about 1 month ago
JSON representation
Get defaults by validate function.
- Host: GitHub
- URL: https://github.com/afeiship/next-defaults-validate
- Owner: afeiship
- License: mit
- Created: 2018-03-14T02:06:55.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-07-29T05:34:15.000Z (almost 2 years ago)
- Last Synced: 2025-09-04T07:31:23.557Z (10 months ago)
- Topics: defaults, next, validate, validator
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# next-defaults-validate
> Get defaults by validate function.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]
## installation
```bash
yarn add @jswork/next-defaults-validate
```
## usage
```js
import '@jswork/next-defaults-validate';
const target = {
username: 'xiaoming',
email: 'abc',
other: 'value',
nested: {
company: {
address: null
}
}
};
nx.defaultsValidate(target, {
username: (value) => value.length > 3 ? null : 'anonymous',
email: (value) => value.includes('@') ? null : 'example@email.com',
'nested.company.address': (value) => value ? null : 'unknown'
});
// output:
/*
{
username: 'xiaoming',
email: 'example@email.com',
other: 'value',
nested: {
company: {
address: 'unknown'
}
}
}
*/
```
## license
Code released under [the MIT license](https://github.com/afeiship/next-defaults-validate/blob/master/LICENSE.txt).
[version-image]: https://img.shields.io/npm/v/@jswork/next-defaults-validate
[version-url]: https://npmjs.org/package/@jswork/next-defaults-validate
[license-image]: https://img.shields.io/npm/l/@jswork/next-defaults-validate
[license-url]: https://github.com/afeiship/next-defaults-validate/blob/master/LICENSE.txt
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-defaults-validate
[size-url]: https://github.com/afeiship/next-defaults-validate/blob/master/dist/next-defaults-validate.min.js
[download-image]: https://img.shields.io/npm/dm/@jswork/next-defaults-validate
[download-url]: https://www.npmjs.com/package/@jswork/next-defaults-validate