https://github.com/kriasoft/validator-fluent
Validation library for JavaScript/TypeScript with a strongly typed fluent API
https://github.com/kriasoft/validator-fluent
javascript nodejs sanitization sanitizer typescript validation validator
Last synced: about 2 months ago
JSON representation
Validation library for JavaScript/TypeScript with a strongly typed fluent API
- Host: GitHub
- URL: https://github.com/kriasoft/validator-fluent
- Owner: kriasoft
- License: mit
- Created: 2021-03-22T13:26:54.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-24T11:58:26.000Z (over 4 years ago)
- Last Synced: 2025-08-04T21:49:44.108Z (2 months ago)
- Topics: javascript, nodejs, sanitization, sanitizer, typescript, validation, validator
- Language: TypeScript
- Homepage:
- Size: 681 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# validator.js — fluent edition 🎉
[](https://www.npmjs.com/package/validator-fluent)
[](https://www.npmjs.com/package/validator-fluent)
[](http://www.typescriptlang.org/)
[](http://patreon.com/koistya)
[](https://discord.gg/gx5pdvZ7Za)Validation library based on [validator.js](https://github.com/validatorjs/validator.js) (✭17k)
that provides a strongly typed (TypeScript) fluent API for user input validation and sanitization.## Getting Started
```bash
$ npm install validator validator-fluent
``````js
import { validate, ValidationError } from "validator-fluent";
``````js
const input = {
givenName: "John",
familyName: "Doe",
email: "john@example.com",
phone: "(555) 555-55-55",
age: "18",
};// Do not validate empty fields (validation only)
const dryRun = true;const [data, errors] = validate(input, (value) => ({
given_name: value("givenName")
.notEmpty({ if: !dryRun })
.isLength({ min: 3, max: 25 }),family_name: value("familyName")
.notEmpty({ if: !dryRun })
.isLength({ min: 1, max: 25 }),email: value("email").notEmpty().isEmail(),
phone: value("phone").isMobilePhone({ locale: "en-US" }),
age: value("age").toNumber(),
}));if (Object.keys(errors).length > 0)) {
throw new ValidationError(errors);
}if (!dryRun) {
await db.table("customer").insert(data);
}
```For the full list of available validation rules please refer to:
https://github.com/validatorjs/validator.js#validators
## Related Projects
- [GraphQL API Starter Kit](https://github.com/kriasoft/graphql-starter) — project template, pre-configured with TypeScript, GraphQL.js, React, and Relay.
## How to Contribute
Please create a [PR](https://docs.github.com/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) or send me a message on [Discord](https://discord.gg/gx5pdvZ7Za).
## License
Copyright © 2021-present Kriasoft. This source code is licensed under the MIT license found in the
[LICENSE](https://github.com/kriasoft/validator-fluent/blob/main/LICENSE) file.---
Made with ♥ by Konstantin Tarkus ([@koistya](https://twitter.com/koistya), [blog](https://medium.com/@koistya))
and [contributors](https://github.com/kriasoft/graphql-starter/graphs/contributors).