Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/goenning/guard-me
next-generation validation library for node.js
https://github.com/goenning/guard-me
Last synced: 13 days ago
JSON representation
next-generation validation library for node.js
- Host: GitHub
- URL: https://github.com/goenning/guard-me
- Owner: goenning
- License: gpl-2.0
- Created: 2016-01-11T20:07:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-27T19:57:45.000Z (almost 9 years ago)
- Last Synced: 2024-11-02T19:41:38.602Z (2 months ago)
- Language: TypeScript
- Size: 185 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/goenning/guard-me.svg?branch=master)](https://travis-ci.org/goenning/guard-me)
[![npm version](https://badge.fury.io/js/guard-me.svg)](https://badge.fury.io/js/guard-me)# guard-me
`guard-me` is a next-generation validation library for node.js. It is highly inspired on [JeremySkinner/FluentValidation](https://github.com/JeremySkinner/FluentValidation) for .NET.
> Decouple now your validation from the rest of the code!
## Example
```javascript
var ensure = require('guard-me').ensurevar guard = ensure.that((check, object) => {
check(object.title).required().length(1, 20)
check(object.slug).required().message("Slug is mandatory! It's currently empty")
check(object.tags).length(1, 3)
})//Example A
var request = {
title: 'Garmin Swim',
slug: 'garmin-swim',
tags: ['watch', 'garmin', 'sports']
}guard.check(request).then((result) => {
console.log(result.valid); //output: true
})//Example B
var request = {
title: 'Garmin Swim',
slug: '',
tags: []
}guard.check(request).then((result) => {
console.log(result.valid); //output: falseconsole.log(result.errors[0].property); //output: slug
console.log(result.errors[0].messages[0]); //output: Slug is mandatory! It's currently emptyconsole.log(result.errors[1].property); //output: tags
console.log(result.errors[1].messages[0]); //output: Tags must have between 1 and 3 elements
})
```It is written in TypeScript. This means `Definition Files (.d.ts)` files are bundled within the package.
Built-in validators:
- equal
- not equal
- required
- is in (...)
- matches a RegExp
- greater than or equal to
- less than or equal to
- length (min, max)
- Do anything you want with `must` validation! Supports Sync and Async validations using Promises### Work is still in progress. And i need you!
Version `1.0.0` is planned to be the first stable release. There is no due date by now.
Please share with us your suggestions, feature request, bug report, code review, better docs, start a discussion, anything.
Feel free to submit a new issue for any matter.