@jswork/next-defaults-validate
v1.0.2
Published
Get defaults by validate function.
Downloads
62
Maintainers
Readme
next-defaults-validate
Get defaults by validate function.
installation
yarn add @jswork/next-defaults-validate
usage
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 : '[email protected]',
'nested.company.address': (value) => value ? null : 'unknown'
});
// output:
/*
{
username: 'xiaoming',
email: '[email protected]',
other: 'value',
nested: {
company: {
address: 'unknown'
}
}
}
*/
license
Code released under the MIT license.