Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/georgesboris/validate-properties
quickly validates the properties of an object
https://github.com/georgesboris/validate-properties
Last synced: about 2 months ago
JSON representation
quickly validates the properties of an object
- Host: GitHub
- URL: https://github.com/georgesboris/validate-properties
- Owner: georgesboris
- License: bsd-2-clause
- Created: 2017-08-13T15:14:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-14T12:53:46.000Z (over 7 years ago)
- Last Synced: 2023-07-31T15:57:52.248Z (over 1 year ago)
- Language: JavaScript
- Size: 68.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# validate-properties
Validates the properties of a passed object using a minimalistic API.
```bash
yarn add validate-properties
```### Check if all properties are defined
```javascript
import validate from 'validate-properties'validate({ a: 1 }, ['a', 'b']) // false
```*A property is defined if it's value is not undefined and if it's not a blank string.*
### Any of the properties are defined
```javascript
validate({ a: 1 }, [['a', 'b']]) // true
```*Notice that we are defining this validation as an array within the properties array.*
### Custom validation
```javascript
validate({ a: 1, b: 1 }, [({a , b}) => a === b]) // true
```### Multiple validations
```javascript
validate({ a: 1, b: 2 }, [
'a', // true
['a', 'b'], // true
({ a, b }) => a === b // false
]) // -> false
```### Checking failed validations
Normally, we return a boolean containing the validation result.
But we can also return an array containing all the validations that have failed.
This can be useful for debugging and displaying form errors.```javascript
validate({ a: 1 }, ['a', 'b'], true) // [{ index: 1, validation: 'b' }]
```