Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scniro/scniro-validator
https://github.com/scniro/scniro-validator
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/scniro/scniro-validator
- Owner: scniro
- License: mit
- Created: 2016-09-05T17:46:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-05T20:43:55.000Z (about 8 years ago)
- Last Synced: 2024-04-14T12:48:33.771Z (7 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
> a small, dependency-free email validator with configurable rules and suggested corrections
### Install
```
npm install scniro-validator --save
```### Sample usage
```javascript
var v = require('scniro-validator');var result = v.validate('[email protected]');
// {valid: true}
```### Configuration
validation may be influenced by calling optional `.init` with a configuration object
```javascript
var rules = {
tld: {
allowed: ['com']
sdl: {
allowed: ['bar']
}
}var result = v.validate('[email protected]');
// {valid: false}
```### Corrections
validation will include a suggested correction base on `corrections` defined via `tld` and `sld` supplied `match` objects ([top-level domain](https://en.wikipedia.org/wiki/Top-level_domain) and [second-level domain](https://en.wikipedia.org/wiki/Second-level_domain), respectively). Specify this via `tryCorrect`.
```javascript
var rules = {
tld: {
allowed: ['com'],
corrections: [
{match: 'con.au', correct: 'com'}
]
}
}var result = v.validate('[email protected]', {tryCorrect: true});
// {valid: false, correction: '[email protected]'}
```or a _really_ barged example
```javascript
var rules = {
tld: {
allowed: ['com'],
corrections: [
{match: 'con.au', correct: 'com'}
]
},
sdl: {
allowed: ['bar']
}
}var result = v.validate('foo.bar.con.au', {tryCorrect: true});
// {valid: false, correction: '[email protected]'}
```### Note
e-mail validation is a [rabbit hole]( http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/), and this tool does not aim to be a silver bullet. The capability of this tool is influenced from the [w3c `type="email"`](https://www.w3.org/TR/html-markup/input.email.html#input.email.attrs.value.multiple) validation, ships with some extensibility specific to a business defined problem, and is pessimistic in nature. For a less problem-specific validation tool, check out the awesome [mailcheck.js](https://github.com/mailcheck/mailcheck)