-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
ES module for webpack tree shaking #1015
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e78930f
marking the package as side effects free
banjankri 45732cc
bumping up version
banjankri f5e479b
bumping up version
banjankri 024ded1
adding es transpilation
banjankri 8f7f6b9
amending version in index
banjankri 6b47252
updating readme file about es module
banjankri eb35eff
reverting spacing change
banjankri b2d0fda
amending version - skipped one perviously
banjankri bb19acd
Revert "amending version - skipped one perviously"
banjankri 52b302f
Revert "amending version in index"
banjankri 6f458ec
reverting version change
banjankri 1c00775
merging with upstream master
banjankri 7f4221a
merging with upstream master
banjankri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
{ | ||
"presets": [ | ||
["@babel/preset-env", {"targets": {"node": "0.10"}}] | ||
], | ||
"plugins": [ | ||
[ | ||
"add-module-exports", | ||
{ | ||
"addDefaultProperty": true | ||
} | ||
] | ||
] | ||
} | ||
"env": { | ||
"es": { | ||
"presets": [ | ||
["@babel/preset-env", { | ||
"modules": false | ||
}] | ||
] | ||
}, | ||
"development": { | ||
"presets": [ | ||
["@babel/preset-env", { "targets": { "node": "0.10" } }] | ||
], | ||
"plugins": [ | ||
[ | ||
"add-module-exports", | ||
{ | ||
"addDefaultProperty": true | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import toDate from './lib/toDate'; | ||
import toFloat from './lib/toFloat'; | ||
import toInt from './lib/toInt'; | ||
import toBoolean from './lib/toBoolean'; | ||
import equals from './lib/equals'; | ||
import contains from './lib/contains'; | ||
import matches from './lib/matches'; | ||
import isEmail from './lib/isEmail'; | ||
import isURL from './lib/isURL'; | ||
import isMACAddress from './lib/isMACAddress'; | ||
import isIP from './lib/isIP'; | ||
import isIPRange from './lib/isIPRange'; | ||
import isFQDN from './lib/isFQDN'; | ||
import isBoolean from './lib/isBoolean'; | ||
import isAlpha, { locales as isAlphaLocales } from './lib/isAlpha'; | ||
import isAlphanumeric, { locales as isAlphanumericLocales } from './lib/isAlphanumeric'; | ||
import isNumeric from './lib/isNumeric'; | ||
import isPort from './lib/isPort'; | ||
import isLowercase from './lib/isLowercase'; | ||
import isUppercase from './lib/isUppercase'; | ||
import isAscii from './lib/isAscii'; | ||
import isFullWidth from './lib/isFullWidth'; | ||
import isHalfWidth from './lib/isHalfWidth'; | ||
import isVariableWidth from './lib/isVariableWidth'; | ||
import isMultibyte from './lib/isMultibyte'; | ||
import isSurrogatePair from './lib/isSurrogatePair'; | ||
import isInt from './lib/isInt'; | ||
import isFloat, { locales as isFloatLocales } from './lib/isFloat'; | ||
import isDecimal from './lib/isDecimal'; | ||
import isHexadecimal from './lib/isHexadecimal'; | ||
import isDivisibleBy from './lib/isDivisibleBy'; | ||
import isHexColor from './lib/isHexColor'; | ||
import isISRC from './lib/isISRC'; | ||
import isMD5 from './lib/isMD5'; | ||
import isHash from './lib/isHash'; | ||
import isJWT from './lib/isJWT'; | ||
import isJSON from './lib/isJSON'; | ||
import isEmpty from './lib/isEmpty'; | ||
import isLength from './lib/isLength'; | ||
import isByteLength from './lib/isByteLength'; | ||
import isUUID from './lib/isUUID'; | ||
import isMongoId from './lib/isMongoId'; | ||
import isAfter from './lib/isAfter'; | ||
import isBefore from './lib/isBefore'; | ||
import isIn from './lib/isIn'; | ||
import isCreditCard from './lib/isCreditCard'; | ||
import isIdentityCard from './lib/isIdentityCard'; | ||
import isISIN from './lib/isISIN'; | ||
import isISBN from './lib/isISBN'; | ||
import isISSN from './lib/isISSN'; | ||
import isMobilePhone, { locales as isMobilePhoneLocales } from './lib/isMobilePhone'; | ||
import isCurrency from './lib/isCurrency'; | ||
import isISO8601 from './lib/isISO8601'; | ||
import isRFC3339 from './lib/isRFC3339'; | ||
import isISO31661Alpha2 from './lib/isISO31661Alpha2'; | ||
import isISO31661Alpha3 from './lib/isISO31661Alpha3'; | ||
import isBase64 from './lib/isBase64'; | ||
import isDataURI from './lib/isDataURI'; | ||
import isMagnetURI from './lib/isMagnetURI'; | ||
import isMimeType from './lib/isMimeType'; | ||
import isLatLong from './lib/isLatLong'; | ||
import isPostalCode, { locales as isPostalCodeLocales } from './lib/isPostalCode'; | ||
import ltrim from './lib/ltrim'; | ||
import rtrim from './lib/rtrim'; | ||
import trim from './lib/trim'; | ||
import escape from './lib/escape'; | ||
import unescape from './lib/unescape'; | ||
import stripLow from './lib/stripLow'; | ||
import whitelist from './lib/whitelist'; | ||
import blacklist from './lib/blacklist'; | ||
import isWhitelisted from './lib/isWhitelisted'; | ||
import normalizeEmail from './lib/normalizeEmail'; | ||
import toString from './lib/util/toString'; | ||
var version = '10.11.0'; | ||
var validator = { | ||
version: version, | ||
toDate: toDate, | ||
toFloat: toFloat, | ||
toInt: toInt, | ||
toBoolean: toBoolean, | ||
equals: equals, | ||
contains: contains, | ||
matches: matches, | ||
isEmail: isEmail, | ||
isURL: isURL, | ||
isMACAddress: isMACAddress, | ||
isIP: isIP, | ||
isIPRange: isIPRange, | ||
isFQDN: isFQDN, | ||
isBoolean: isBoolean, | ||
isAlpha: isAlpha, | ||
isAlphaLocales: isAlphaLocales, | ||
isAlphanumeric: isAlphanumeric, | ||
isAlphanumericLocales: isAlphanumericLocales, | ||
isNumeric: isNumeric, | ||
isPort: isPort, | ||
isLowercase: isLowercase, | ||
isUppercase: isUppercase, | ||
isAscii: isAscii, | ||
isFullWidth: isFullWidth, | ||
isHalfWidth: isHalfWidth, | ||
isVariableWidth: isVariableWidth, | ||
isMultibyte: isMultibyte, | ||
isSurrogatePair: isSurrogatePair, | ||
isInt: isInt, | ||
isFloat: isFloat, | ||
isFloatLocales: isFloatLocales, | ||
isDecimal: isDecimal, | ||
isHexadecimal: isHexadecimal, | ||
isDivisibleBy: isDivisibleBy, | ||
isHexColor: isHexColor, | ||
isISRC: isISRC, | ||
isMD5: isMD5, | ||
isHash: isHash, | ||
isJWT: isJWT, | ||
isJSON: isJSON, | ||
isEmpty: isEmpty, | ||
isLength: isLength, | ||
isByteLength: isByteLength, | ||
isUUID: isUUID, | ||
isMongoId: isMongoId, | ||
isAfter: isAfter, | ||
isBefore: isBefore, | ||
isIn: isIn, | ||
isCreditCard: isCreditCard, | ||
isIdentityCard: isIdentityCard, | ||
isISIN: isISIN, | ||
isISBN: isISBN, | ||
isISSN: isISSN, | ||
isMobilePhone: isMobilePhone, | ||
isMobilePhoneLocales: isMobilePhoneLocales, | ||
isPostalCode: isPostalCode, | ||
isPostalCodeLocales: isPostalCodeLocales, | ||
isCurrency: isCurrency, | ||
isISO8601: isISO8601, | ||
isRFC3339: isRFC3339, | ||
isISO31661Alpha2: isISO31661Alpha2, | ||
isISO31661Alpha3: isISO31661Alpha3, | ||
isBase64: isBase64, | ||
isDataURI: isDataURI, | ||
isMagnetURI: isMagnetURI, | ||
isMimeType: isMimeType, | ||
isLatLong: isLatLong, | ||
ltrim: ltrim, | ||
rtrim: rtrim, | ||
trim: trim, | ||
escape: escape, | ||
unescape: unescape, | ||
stripLow: stripLow, | ||
whitelist: whitelist, | ||
blacklist: blacklist, | ||
isWhitelisted: isWhitelisted, | ||
normalizeEmail: normalizeEmail, | ||
toString: toString | ||
}; | ||
export default validator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
export var alpha = { | ||
'en-US': /^[A-Z]+$/i, | ||
'bg-BG': /^[А-Я]+$/i, | ||
'cs-CZ': /^[A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, | ||
'da-DK': /^[A-ZÆØÅ]+$/i, | ||
'de-DE': /^[A-ZÄÖÜß]+$/i, | ||
'el-GR': /^[Α-ω]+$/i, | ||
'es-ES': /^[A-ZÁÉÍÑÓÚÜ]+$/i, | ||
'fr-FR': /^[A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, | ||
'it-IT': /^[A-ZÀÉÈÌÎÓÒÙ]+$/i, | ||
'nb-NO': /^[A-ZÆØÅ]+$/i, | ||
'nl-NL': /^[A-ZÁÉËÏÓÖÜÚ]+$/i, | ||
'nn-NO': /^[A-ZÆØÅ]+$/i, | ||
'hu-HU': /^[A-ZÁÉÍÓÖŐÚÜŰ]+$/i, | ||
'pl-PL': /^[A-ZĄĆĘŚŁŃÓŻŹ]+$/i, | ||
'pt-PT': /^[A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, | ||
'ru-RU': /^[А-ЯЁ]+$/i, | ||
'sl-SI': /^[A-ZČĆĐŠŽ]+$/i, | ||
'sk-SK': /^[A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, | ||
'sr-RS@latin': /^[A-ZČĆŽŠĐ]+$/i, | ||
'sr-RS': /^[А-ЯЂЈЉЊЋЏ]+$/i, | ||
'sv-SE': /^[A-ZÅÄÖ]+$/i, | ||
'tr-TR': /^[A-ZÇĞİıÖŞÜ]+$/i, | ||
'uk-UA': /^[А-ЩЬЮЯЄIЇҐі]+$/i, | ||
'ku-IQ': /^[ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i, | ||
ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/ | ||
}; | ||
export var alphanumeric = { | ||
'en-US': /^[0-9A-Z]+$/i, | ||
'bg-BG': /^[0-9А-Я]+$/i, | ||
'cs-CZ': /^[0-9A-ZÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ]+$/i, | ||
'da-DK': /^[0-9A-ZÆØÅ]+$/i, | ||
'de-DE': /^[0-9A-ZÄÖÜß]+$/i, | ||
'el-GR': /^[0-9Α-ω]+$/i, | ||
'es-ES': /^[0-9A-ZÁÉÍÑÓÚÜ]+$/i, | ||
'fr-FR': /^[0-9A-ZÀÂÆÇÉÈÊËÏÎÔŒÙÛÜŸ]+$/i, | ||
'it-IT': /^[0-9A-ZÀÉÈÌÎÓÒÙ]+$/i, | ||
'hu-HU': /^[0-9A-ZÁÉÍÓÖŐÚÜŰ]+$/i, | ||
'nb-NO': /^[0-9A-ZÆØÅ]+$/i, | ||
'nl-NL': /^[0-9A-ZÁÉËÏÓÖÜÚ]+$/i, | ||
'nn-NO': /^[0-9A-ZÆØÅ]+$/i, | ||
'pl-PL': /^[0-9A-ZĄĆĘŚŁŃÓŻŹ]+$/i, | ||
'pt-PT': /^[0-9A-ZÃÁÀÂÇÉÊÍÕÓÔÚÜ]+$/i, | ||
'ru-RU': /^[0-9А-ЯЁ]+$/i, | ||
'sl-SI': /^[0-9A-ZČĆĐŠŽ]+$/i, | ||
'sk-SK': /^[0-9A-ZÁČĎÉÍŇÓŠŤÚÝŽĹŔĽÄÔ]+$/i, | ||
'sr-RS@latin': /^[0-9A-ZČĆŽŠĐ]+$/i, | ||
'sr-RS': /^[0-9А-ЯЂЈЉЊЋЏ]+$/i, | ||
'sv-SE': /^[0-9A-ZÅÄÖ]+$/i, | ||
'tr-TR': /^[0-9A-ZÇĞİıÖŞÜ]+$/i, | ||
'uk-UA': /^[0-9А-ЩЬЮЯЄIЇҐі]+$/i, | ||
'ku-IQ': /^[٠١٢٣٤٥٦٧٨٩0-9ئابپتجچحخدرڕزژسشعغفڤقکگلڵمنوۆھەیێيطؤثآإأكضصةظذ]+$/i, | ||
ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/ | ||
}; | ||
export var decimal = { | ||
'en-US': '.', | ||
ar: '٫' | ||
}; | ||
export var englishLocales = ['AU', 'GB', 'HK', 'IN', 'NZ', 'ZA', 'ZM']; | ||
|
||
for (var locale, i = 0; i < englishLocales.length; i++) { | ||
locale = "en-".concat(englishLocales[i]); | ||
alpha[locale] = alpha['en-US']; | ||
alphanumeric[locale] = alphanumeric['en-US']; | ||
decimal[locale] = decimal['en-US']; | ||
} // Source: http://www.localeplanet.com/java/ | ||
|
||
|
||
export var arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE']; | ||
|
||
for (var _locale, _i = 0; _i < arabicLocales.length; _i++) { | ||
_locale = "ar-".concat(arabicLocales[_i]); | ||
alpha[_locale] = alpha.ar; | ||
alphanumeric[_locale] = alphanumeric.ar; | ||
decimal[_locale] = decimal.ar; | ||
} // Source: https://en.wikipedia.org/wiki/Decimal_mark | ||
|
||
|
||
export var dotDecimal = []; | ||
export var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'es-ES', 'fr-FR', 'it-IT', 'ku-IQ', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA']; | ||
|
||
for (var _i2 = 0; _i2 < dotDecimal.length; _i2++) { | ||
decimal[dotDecimal[_i2]] = decimal['en-US']; | ||
} | ||
|
||
for (var _i3 = 0; _i3 < commaDecimal.length; _i3++) { | ||
decimal[commaDecimal[_i3]] = ','; | ||
} | ||
|
||
alpha['pt-BR'] = alpha['pt-PT']; | ||
alphanumeric['pt-BR'] = alphanumeric['pt-PT']; | ||
decimal['pt-BR'] = decimal['pt-PT']; // see #862 | ||
|
||
alpha['pl-Pl'] = alpha['pl-PL']; | ||
alphanumeric['pl-Pl'] = alphanumeric['pl-PL']; | ||
decimal['pl-Pl'] = decimal['pl-PL']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import assertString from './util/assertString'; | ||
export default function blacklist(str, chars) { | ||
assertString(str); | ||
return str.replace(new RegExp("[".concat(chars, "]+"), 'g'), ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import assertString from './util/assertString'; | ||
import toString from './util/toString'; | ||
export default function contains(str, elem) { | ||
assertString(str); | ||
return str.indexOf(toString(elem)) >= 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import assertString from './util/assertString'; | ||
export default function equals(str, comparison) { | ||
assertString(str); | ||
return str === comparison; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import assertString from './util/assertString'; | ||
export default function escape(str) { | ||
assertString(str); | ||
return str.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''').replace(/</g, '<').replace(/>/g, '>').replace(/\//g, '/').replace(/\\/g, '\').replace(/`/g, '`'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import assertString from './util/assertString'; | ||
import toDate from './toDate'; | ||
export default function isAfter(str) { | ||
var date = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : String(new Date()); | ||
assertString(str); | ||
var comparison = toDate(date); | ||
var original = toDate(str); | ||
return !!(original && comparison && original > comparison); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import assertString from './util/assertString'; | ||
import { alpha } from './alpha'; | ||
export default function isAlpha(str) { | ||
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US'; | ||
assertString(str); | ||
|
||
if (locale in alpha) { | ||
return alpha[locale].test(str); | ||
} | ||
|
||
throw new Error("Invalid locale '".concat(locale, "'")); | ||
} | ||
export var locales = Object.keys(alpha); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import assertString from './util/assertString'; | ||
import { alphanumeric } from './alpha'; | ||
export default function isAlphanumeric(str) { | ||
var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en-US'; | ||
assertString(str); | ||
|
||
if (locale in alphanumeric) { | ||
return alphanumeric[locale].test(str); | ||
} | ||
|
||
throw new Error("Invalid locale '".concat(locale, "'")); | ||
} | ||
export var locales = Object.keys(alphanumeric); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import assertString from './util/assertString'; | ||
/* eslint-disable no-control-regex */ | ||
|
||
var ascii = /^[\x00-\x7F]+$/; | ||
/* eslint-enable no-control-regex */ | ||
|
||
export default function isAscii(str) { | ||
assertString(str); | ||
return ascii.test(str); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are having to repeat all the code in the
/es
folder, it means changes have to be made in duplicate. Could we think of a build process where this code is generated into the folder and all the necessary transformations made? 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done already, please see "build:es" script in package.json. It is then invoked as part of the "build" script. Added also cleanup for it accordingly, following what was done for "clean:browser" and "clean:node".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, got it 👍