https://github.com/geraintluff/tv4-coerce
Coercive validation based on tv4
https://github.com/geraintluff/tv4-coerce
Last synced: about 1 year ago
JSON representation
Coercive validation based on tv4
- Host: GitHub
- URL: https://github.com/geraintluff/tv4-coerce
- Owner: geraintluff
- Created: 2014-04-10T17:41:06.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2017-07-20T08:21:34.000Z (almost 9 years ago)
- Last Synced: 2025-03-26T16:05:32.568Z (about 1 year ago)
- Language: JavaScript
- Size: 156 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
tv4-coerce
==========
Coercive validation based on tv4
## Usage
```javascript
var tv4coerce = require('tv4-coerce');
tv4coerce.coerce(data, schema);
```
## Adding new fixes
This module works by an iterative fix-and-recheck loop.
To add a new fix, register a function for the corresponding error code:
```javascript
api.addFix(api.errorCodes.INVALID_TYPE, function (value, type, error, baseSchema) {
// If you can fix it
return newValue;
// If you can't, let it return undefined
});
```
You can register as many fixes for a given error code as you like. They will be attempted in the order in which they are registered.
Some standard fixes are in `coerce-standard.js`, and can be used as examples.