https://github.com/harmos274/record-validator
A simple runtime type validator for JS and TS.
https://github.com/harmos274/record-validator
data-validation javascript nodejs type-validation typescript typescript-library validator
Last synced: 10 months ago
JSON representation
A simple runtime type validator for JS and TS.
- Host: GitHub
- URL: https://github.com/harmos274/record-validator
- Owner: Harmos274
- Created: 2022-06-10T21:57:25.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-13T12:28:39.000Z (over 3 years ago)
- Last Synced: 2025-04-22T23:51:14.698Z (11 months ago)
- Topics: data-validation, javascript, nodejs, type-validation, typescript, typescript-library, validator
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/record-validator
- Size: 52.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Record Validator
Record validator is a NodeJS package that allows you to do a runtime check of a given Record.
## How to use it
```typescript
import { TypeValidator } from "record-validator"
interface ISimpleTest {
id: number,
name: string,
}
const validator = new TypeValidator({
id: {
required: true,
type: "number"
},
name: {
required: true,
type: "string"
}
})
const value = {
id: 12,
name: "toto"
}
validator.test(value)
// Returns null on success and a string explaining the error on failure.
```
**You should check the [unit tests](https://github.com/Harmos274/type-validator/blob/master/tests/unit.test.ts)
to know more about this package, including how to implement custom validators for your types and nested fields.**