Skip to content

Commit

Permalink
merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ezkemboi committed Dec 6, 2019
2 parents 4f47c89 + 549cbec commit 051875d
Show file tree
Hide file tree
Showing 109 changed files with 2,979 additions and 74 deletions.
35 changes: 23 additions & 12 deletions .babelrc
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
}
]
]
}
}
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ sudo: false
language: node_js
node_js:
- stable
- 12
- 11
- 10
- 9
- 8
notifications:
email: false
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
#### 12.1.0

- ES module for webpack tree shaking
([#1015](https://github.com/chriso/validator.js/pull/1015))
- Updated `isIP()` to accept scoped IPv6 addresses
([#1160](https://github.com/chriso/validator.js/pull/1160))
- New and improved locales
([#1162](https://github.com/chriso/validator.js/pull/1162),
[#1183](https://github.com/chriso/validator.js/pull/1183),
[#1187](https://github.com/chriso/validator.js/pull/1187),
[#1191](https://github.com/chriso/validator.js/pull/1191))

#### 12.0.0

- Added `isOctal()` validator
([#1153](https://github.com/chriso/validator.js/pull/1153))
- Added `isSlug()` validator
([#1096](https://github.com/chriso/validator.js/pull/1096))
- Added `isBIC()` validator for bank identification codes
([#1071](https://github.com/chriso/validator.js/pull/1071))
- Allow uppercase chars in `isHash()`
([#1062](https://github.com/chriso/validator.js/pull/1062))
- Allow additional prefixes in `isHexadecimal()`
([#1147](https://github.com/chriso/validator.js/pull/1147))
- Allow additional separators in `isMACAddress()`
([#1065](https://github.com/chriso/validator.js/pull/1065))
- Better defaults for `isLength()`
([#1070](https://github.com/chriso/validator.js/pull/1070))
- Bug fixes
([#1074](https://github.com/chriso/validator.js/pull/1074))
- New and improved locales
([#1059](https://github.com/chriso/validator.js/pull/1059),
[#1060](https://github.com/chriso/validator.js/pull/1060),
[#1069](https://github.com/chriso/validator.js/pull/1069),
[#1073](https://github.com/chriso/validator.js/pull/1073),
[#1082](https://github.com/chriso/validator.js/pull/1082),
[#1092](https://github.com/chriso/validator.js/pull/1092),
[#1121](https://github.com/chriso/validator.js/pull/1121),
[#1125](https://github.com/chriso/validator.js/pull/1125),
[#1132](https://github.com/chriso/validator.js/pull/1132),
[#1152](https://github.com/chriso/validator.js/pull/1152),
[#1165](https://github.com/chriso/validator.js/pull/1165),
[#1166](https://github.com/chriso/validator.js/pull/1166),
[#1174](https://github.com/chriso/validator.js/pull/1174))

#### 11.1.0

- Code coverage improvements
Expand Down
44 changes: 27 additions & 17 deletions README.md

Large diffs are not rendered by default.

165 changes: 165 additions & 0 deletions es/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
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 isLocale from './lib/isLocale';
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 isOctal from './lib/isOctal';
import isDivisibleBy from './lib/isDivisibleBy';
import isHexColor from './lib/isHexColor';
import isISRC from './lib/isISRC';
import isBIC from './lib/isBIC';
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 isBase32 from './lib/isBase32';
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 isSlug from './lib/isSlug';
var version = '12.1.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,
isBIC: isBIC,
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,
isOctal: isOctal,
isDivisibleBy: isDivisibleBy,
isHexColor: isHexColor,
isISRC: isISRC,
isMD5: isMD5,
isHash: isHash,
isJWT: isJWT,
isJSON: isJSON,
isEmpty: isEmpty,
isLength: isLength,
isLocale: isLocale,
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,
isBase32: isBase32,
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,
isSlug: isSlug
};
export default validator;
100 changes: 100 additions & 0 deletions es/lib/alpha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[א-ת]+$/,
'fa-IR': /^['آابپتثجچهخدذرزژسشصضطظعغفقکگلمنوهی']+$/i
};
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ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/,
he: /^[0-9א-ת]+$/,
'fa-IR': /^['0-9آابپتثجچهخدذرزژسشصضطظعغفقکگلمنوهی۱۲۳۴۵۶۷۸۹۰']+$/i
};
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 = ['ar-EG', 'ar-LB', 'ar-LY'];
export var commaDecimal = ['bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', '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'];
5 changes: 5 additions & 0 deletions es/lib/blacklist.js
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'), '');
}
6 changes: 6 additions & 0 deletions es/lib/contains.js
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;
}
5 changes: 5 additions & 0 deletions es/lib/equals.js
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;
}
5 changes: 5 additions & 0 deletions es/lib/escape.js
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, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
}
Loading

0 comments on commit 051875d

Please sign in to comment.