Skip to content

Commit

Permalink
Merge pull request #496 from forabi/modules
Browse files Browse the repository at this point in the history
Migrate to ES6
  • Loading branch information
chriso committed Feb 21, 2016
2 parents b96a953 + a33b64b commit 396f2be
Show file tree
Hide file tree
Showing 139 changed files with 7,398 additions and 3,769 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
validator.js
validator.min.js
23 changes: 23 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "airbnb/base",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"es6": true,
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"camelcase": [0],
"no-param-reassign": [0],
"one-var": 0,
"one-var-declaration-per-line": 0,
"func-names": 0,
"no-console": 0,
"newline-per-chained-call": 0,
"prefer-const": 0
}
}
3 changes: 0 additions & 3 deletions .jshintrc

This file was deleted.

34 changes: 0 additions & 34 deletions Makefile

This file was deleted.

18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ If you're not sure if your input is a string, coerce it using `input + ''`.
- **contains(str, seed)** - check if the string contains the seed.
- **equals(str, comparison)** - check if the string matches the comparison.
- **isAfter(str [, date])** - check if the string is a date that's after the specified date (defaults to now).
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM', 'ru-RU']`) and defaults to `en-US`.
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM', 'ru-RU']`) and defaults to `en-US`.
- **isAlpha(str [, locale])** - check if the string contains only letters (a-zA-Z). Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QM', 'ar-QA', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM', 'ru-RU']`) and defaults to `en-US`.
- **isAlphanumeric(str [, locale])** - check if the string contains only letters and numbers. Locale is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QM', 'ar-QA', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'en-US', 'de-DE', 'es-ES', 'fr-FR', 'nl-NL', 'pt-PT', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-ZA', 'en-ZM', 'ru-RU']`) and defaults to `en-US`.
- **isAscii(str)** - check if the string contains ASCII chars only.
- **isBase64(str)** - check if a string is base64 encoded.
- **isBefore(str [, date])** - check if the string is a date that's before the specified date.
Expand Down Expand Up @@ -74,7 +74,7 @@ If you're not sure if your input is a string, coerce it using `input + ''`.
- **isLength(str, options)** - check if the string's length falls in a range. `options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
- **isLowercase(str)** - check if the string is lowercase.
- **isMACAddress(str)** - check if the string is a MAC address.
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN', 'es-ES', 'de-DE', 'fi-FI']`).
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-SY', 'zh-CN', 'zh-TW', 'en-ZA', 'en-AU', 'en-HK', 'pt-PT', 'fr-FR', 'el-GR', 'en-GB', 'en-US', 'en-ZM', 'ru-RU', 'nb-NO', 'nn-NO', 'vi-VN', 'en-NZ', 'en-IN', 'es-ES', 'de-DE', 'fi-FI']`).
- **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
- **isMultibyte(str)** - check if the string contains one or more multibyte chars.
- **isNull(str)** - check if the string is null.
Expand Down Expand Up @@ -108,16 +108,6 @@ XSS sanitization was removed from the library in [2d5d6999](https://github.com/c

For an alternative, look at Yahoo's [xss-filters library](https://github.com/yahoo/xss-filters).

### Extensions

You can add your own validators using `validator.extend(name, fn)`

```javascript
validator.extend('isWhitespace', function (str) {
return /^\s+$/.test(str);
});
```

Note that the first argument will be automatically coerced to a string.

```javascript
Expand Down Expand Up @@ -178,4 +168,4 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[bower]: http://bower.io/

[mongoid]: http://docs.mongodb.org/manual/reference/object-id/
[ISIN]: https://en.wikipedia.org/wiki/International_Securities_Identification_Number
[ISIN]: https://en.wikipedia.org/wiki/International_Securities_Identification_Number
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"license": "MIT",
"ignore": [
"**/.*",
"index.js",
"build*.js",
"package.json",
"node_modules",
"bower_components",
"test",
"tests",
"Makefile",
"package.json"
"test"
]
}
28 changes: 28 additions & 0 deletions build-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const pkg = require('./package.json');
const fs = require('fs');
const rollup = require('rollup').rollup;
const babel = require('rollup-plugin-babel');

rollup({
entry: 'src/index.js',
plugins: [
babel({
presets: ['es2015-rollup'],
babelrc: false,
}),
],
}).then(bundle => (
bundle.write({
dest: 'validator.js',
format: 'umd',
moduleName: pkg.name,
banner: (
'/*!\n' +
String(fs.readFileSync('./LICENSE')).trim().split('\n').map(l => ` * ${l}`).join('\n') +
'\n */'
),
})
)).catch(e => {
process.stderr.write(e.message + '\n');
process.exit(1);
});
Loading

0 comments on commit 396f2be

Please sign in to comment.