Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ES6 #496

Merged
merged 41 commits into from
Feb 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
61906f0
Replace jshint with eslint
forabi Feb 11, 2016
d369a39
Migrate to ES6
forabi Feb 11, 2016
5dc5c24
Remove tests from bower ignore (does not exist)
forabi Feb 11, 2016
0ebb3b4
ESLint: ignore builds and tests
forabi Feb 11, 2016
2487421
Restore test for AMD
forabi Feb 11, 2016
95f853b
Restore deprecation message but do not coerce
forabi Feb 12, 2016
9b73512
ESLint: move ignore to .eslintignore
forabi Feb 12, 2016
150667d
ESLint: extends not needed in test dir
forabi Feb 12, 2016
51aaaa9
Tidy up npm scripts
forabi Feb 12, 2016
d5d53fe
Update builds
forabi Feb 12, 2016
daa442a
Readd comments to browser builds, do not join variables in unminified…
forabi Feb 13, 2016
8aa4a57
Revert version number
forabi Feb 13, 2016
238248a
Add for-in guard
forabi Feb 13, 2016
850286d
Revert depd version
forabi Feb 13, 2016
7832ee3
Remove unnecessary prototype check in toDate
forabi Feb 13, 2016
1a264a0
Revert version number in source
forabi Feb 13, 2016
ad5c980
Remove coersion test
forabi Feb 13, 2016
c9efde6
Remove depd and all related deprecation code
forabi Feb 13, 2016
760015d
Fix isBefore and isAfter defaulting to Date instance instead of string
forabi Feb 13, 2016
3cdb173
Move util to lib/util (only in builds)
forabi Feb 13, 2016
2a3a92d
disable no console warning in root dir
forabi Feb 13, 2016
81337be
Remove unnecessary ignore rules
forabi Feb 13, 2016
0283443
Remove Makefile from bower.json
forabi Feb 13, 2016
bd5e68b
Add explicit dependency "babel-core"
forabi Feb 13, 2016
5197625
ESLint: Add no console warning in src
forabi Feb 13, 2016
11c98c8
Build script: move resolveModuleSource outside waterfall function
forabi Feb 13, 2016
e53389a
bower: ignore index, build and package.json
forabi Feb 13, 2016
bf9232a
Keep things simple
forabi Feb 14, 2016
eaf5088
Specify package files instead of ignored files
forabi Feb 14, 2016
e25b884
assertString throw a TypeError
forabi Feb 15, 2016
a2c4471
Remove extend documentation from README
forabi Feb 15, 2016
8b84882
Add isMobilePhone validation for ar-SY, isAlpha and isAlphanumeric fo…
forabi Feb 16, 2016
369b753
Lint tests
forabi Feb 16, 2016
95f355c
Add Arabic locales with tests for isAlpha and isAlphanumeric
forabi Feb 16, 2016
e44ca88
Update README: Add new Arabic locales
forabi Feb 16, 2016
f919358
Prefer template strings
forabi Feb 20, 2016
af94fb7
Upgrade to ESLint 2, remove unnecessary deps
forabi Feb 21, 2016
b1ff8bc
Remove old ESLint config file
forabi Feb 21, 2016
bf16624
Fix ESLint config
forabi Feb 21, 2016
be9fb9c
Rebase on 4.9.0
forabi Feb 21, 2016
a33b64b
Fix README.md
forabi Feb 21, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still work with all of the import schemes defined here? e.g. #448

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriso I do not use Ember so I'm not sure. Maybe some one can help test it? If it does not work I can open a rollup issue to fix it there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is what is causing issues when I tried to switch to es6 modules in an ember app - TryGhost/Admin#34

Please let me know if there is any way I can help resolve the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevinansfield the rollup package is responsible for generating the output code. There may be a rollup plugin that works for Ember, or a patch to the main rollup repo might be required. I'm happy to quickly accept a PR that fixes the problem or updates dependencies. I don't use Ember so cannot test fixes.

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