Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/himanoa/schemaless-validator
https://github.com/himanoa/schemaless-validator
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/himanoa/schemaless-validator
- Owner: himanoa
- License: mit
- Created: 2021-04-22T21:14:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-04-28T21:42:11.000Z (over 3 years ago)
- Last Synced: 2024-12-08T21:41:53.203Z (25 days ago)
- Language: TypeScript
- Homepage:
- Size: 80.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# schemaless-validator
A library for quickly and freedom creating validation
```typescript
import { validate } from '@himanoa/schemaless-validator'const input = 12
validate((assert) => {
assert(input > 13, "input must be more than 13")
assert(input.toString().length > 13, "input must be at least 13 characters")
}).catch(errors => {
console.dir(errors)
/*
* console.dir
* [
* 'input must be more than 13',
* 'input must be at least 13 characters'
* ]
*
*/
})
```## Install
```
npm install @himanoa/schemaless-validator
```or
```
yarn add @himanoa/schemaless-validator
```## API
### `validate(validator: (assert: (cond: boolean, exceptMessage: string)) => void): Promise`
Execute validator function.
Return the `Promise.resolve` if error array is empty when after execute `validator` and return the `Promise.resolve(exceptMessageArray)` when error is not empty
See. [test case](https://github.com/himanoa/schemaless-validator/blob/master/src/lib.test.ts#L17-L22)
## LICENSE
MIT