From e78930fb611156931d41addb214a44be02040bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Bana=C5=9B?= Date: Wed, 10 Apr 2019 12:42:22 +0200 Subject: [PATCH 01/11] marking the package as side effects free for webpack tree shaing --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index cc99db576..1570297af 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "validator", "description": "String validation and sanitization", "version": "10.11.0", + "sideEffects" false, "homepage": "https://github.com/chriso/validator.js", "files": [ "index.js", From 45732cccef7f79642e45d604f3234e17e70ae5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Bana=C5=9B?= Date: Wed, 10 Apr 2019 12:51:09 +0200 Subject: [PATCH 02/11] bumping up version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1570297af..24891929e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validator", "description": "String validation and sanitization", - "version": "10.11.0", + "version": "10.12.0", "sideEffects" false, "homepage": "https://github.com/chriso/validator.js", "files": [ From f5e479b2fd598008df3c908893297ad4e361ce4e Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Fri, 12 Apr 2019 07:46:55 +0200 Subject: [PATCH 03/11] bumping up version --- package.json | 140 +++++++++++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index 24891929e..4cca07cad 100644 --- a/package.json +++ b/package.json @@ -1,72 +1,70 @@ { - "name": "validator", - "description": "String validation and sanitization", - "version": "10.12.0", - "sideEffects" false, - "homepage": "https://github.com/chriso/validator.js", - "files": [ - "index.js", - "lib", - "README.md", - "LICENCE", - "validator.js", - "validator.min.js" - ], - "keywords": [ - "validator", - "validation", - "validate", - "sanitization", - "sanitize", - "sanitisation", - "sanitise", - "assert" - ], - "author": "Chris O'Hara ", - "contributors": [ - { - "name": "Anthony Nandaa", - "url": "https://github.com/profnandaa" - } - ], - "main": "index.js", - "bugs": { - "url": "https://github.com/chriso/validator.js/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/chriso/validator.js.git" - }, - "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/preset-env": "^7.0.0", - "@babel/register": "^7.0.0", - "babel-eslint": "^10.0.1", - "babel-plugin-add-module-exports": "^1.0.0", - "eslint": "^4.19.1", - "eslint-config-airbnb-base": "^12.1.0", - "eslint-plugin-import": "^2.11.0", - "mocha": "^5.1.1", - "rollup": "^0.43.0", - "rollup-plugin-babel": "^4.0.1", - "uglify-js": "^3.0.19" - }, - "scripts": { - "lint": "eslint src test", - "lint:fix": "eslint --fix src test", - "clean:node": "rm -rf index.js lib", - "clean:browser": "rm -rf validator*.js", - "clean": "npm run clean:node && npm run clean:browser", - "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", - "build:browser": "node --require @babel/register build-browser && npm run minify", - "build:node": "babel src -d .", - "build": "npm run build:browser && npm run build:node", - "pretest": "npm run lint && npm run build", - "test": "mocha --require @babel/register --reporter dot" - }, - "engines": { - "node": ">= 0.10" - }, - "license": "MIT" -} + "name": "validator", + "description": "String validation and sanitization", + "version": "10.13.0", + "sideEffects": false, + "homepage": "https://github.com/chriso/validator.js", + "files": [ + "index.js", + "lib", + "README.md", + "LICENCE", + "validator.js", + "validator.min.js" + ], + "keywords": [ + "validator", + "validation", + "validate", + "sanitization", + "sanitize", + "sanitisation", + "sanitise", + "assert" + ], + "author": "Chris O'Hara ", + "contributors": [{ + "name": "Anthony Nandaa", + "url": "https://github.com/profnandaa" + }], + "main": "index.js", + "bugs": { + "url": "https://github.com/chriso/validator.js/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/chriso/validator.js.git" + }, + "devDependencies": { + "@babel/cli": "^7.0.0", + "@babel/core": "^7.0.0", + "@babel/preset-env": "^7.0.0", + "@babel/register": "^7.0.0", + "babel-eslint": "^10.0.1", + "babel-plugin-add-module-exports": "^1.0.0", + "eslint": "^4.19.1", + "eslint-config-airbnb-base": "^12.1.0", + "eslint-plugin-import": "^2.11.0", + "mocha": "^5.1.1", + "rollup": "^0.43.0", + "rollup-plugin-babel": "^4.0.1", + "uglify-js": "^3.0.19" + }, + "scripts": { + "lint": "eslint src test", + "lint:fix": "eslint --fix src test", + "clean:node": "rm -rf index.js lib", + "clean:browser": "rm -rf validator*.js", + "clean": "npm run clean:node && npm run clean:browser", + "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", + "build:browser": "node --require @babel/register build-browser && npm run minify", + "build:node": "babel src -d .", + "build": "npm run build:browser && npm run build:node", + "pretest": "npm run lint && npm run build", + "test": "mocha --require @babel/register --reporter dot" + }, + "engines": { + "node": ">= 0.10" + }, + "license": "MIT" +} \ No newline at end of file From 024ded1e6a240a676cf06c6700d670c87b91f742 Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Fri, 12 Apr 2019 09:04:54 +0200 Subject: [PATCH 04/11] adding es transpilation --- .babelrc | 35 ++++--- es/index.js | 156 ++++++++++++++++++++++++++++ es/lib/alpha.js | 96 +++++++++++++++++ es/lib/blacklist.js | 5 + es/lib/contains.js | 6 ++ es/lib/equals.js | 5 + es/lib/escape.js | 5 + es/lib/isAfter.js | 9 ++ es/lib/isAlpha.js | 13 +++ es/lib/isAlphanumeric.js | 13 +++ es/lib/isAscii.js | 10 ++ es/lib/isBase64.js | 13 +++ es/lib/isBefore.js | 9 ++ es/lib/isBoolean.js | 5 + es/lib/isByteLength.js | 22 ++++ es/lib/isCreditCard.js | 40 +++++++ es/lib/isCurrency.js | 75 +++++++++++++ es/lib/isDataURI.js | 40 +++++++ es/lib/isDecimal.js | 26 +++++ es/lib/isDivisibleBy.js | 6 ++ es/lib/isEmail.js | 116 +++++++++++++++++++++ es/lib/isEmpty.js | 10 ++ es/lib/isFQDN.js | 60 +++++++++++ es/lib/isFloat.js | 16 +++ es/lib/isFullWidth.js | 6 ++ es/lib/isHalfWidth.js | 6 ++ es/lib/isHash.js | 21 ++++ es/lib/isHexColor.js | 6 ++ es/lib/isHexadecimal.js | 6 ++ es/lib/isIP.js | 72 +++++++++++++ es/lib/isIPRange.js | 22 ++++ es/lib/isISBN.js | 51 +++++++++ es/lib/isISIN.js | 38 +++++++ es/lib/isISO31661Alpha2.js | 8 ++ es/lib/isISO31661Alpha3.js | 8 ++ es/lib/isISO8601.js | 46 ++++++++ es/lib/isISRC.js | 7 ++ es/lib/isISSN.js | 23 ++++ es/lib/isIdentityCard.js | 47 +++++++++ es/lib/isIn.js | 26 +++++ es/lib/isInt.js | 16 +++ es/lib/isJSON.js | 15 +++ es/lib/isJWT.js | 6 ++ es/lib/isLatLong.js | 9 ++ es/lib/isLength.js | 23 ++++ es/lib/isLowercase.js | 5 + es/lib/isMACAddress.js | 12 +++ es/lib/isMD5.js | 6 ++ es/lib/isMagnetURI.js | 6 ++ es/lib/isMimeType.js | 39 +++++++ es/lib/isMobilePhone.js | 119 +++++++++++++++++++++ es/lib/isMongoId.js | 6 ++ es/lib/isMultibyte.js | 10 ++ es/lib/isNumeric.js | 12 +++ es/lib/isPort.js | 7 ++ es/lib/isPostalCode.js | 76 ++++++++++++++ es/lib/isRFC3339.js | 20 ++++ es/lib/isSurrogatePair.js | 6 ++ es/lib/isURL.js | 136 ++++++++++++++++++++++++ es/lib/isUUID.js | 13 +++ es/lib/isUppercase.js | 5 + es/lib/isVariableWidth.js | 7 ++ es/lib/isWhitelisted.js | 12 +++ es/lib/ltrim.js | 6 ++ es/lib/matches.js | 10 ++ es/lib/normalizeEmail.js | 138 ++++++++++++++++++++++++ es/lib/rtrim.js | 12 +++ es/lib/stripLow.js | 7 ++ es/lib/toBoolean.js | 10 ++ es/lib/toDate.js | 6 ++ es/lib/toFloat.js | 5 + es/lib/toInt.js | 5 + es/lib/trim.js | 5 + es/lib/unescape.js | 5 + es/lib/util/assertString.js | 23 ++++ es/lib/util/includes.js | 7 ++ es/lib/util/merge.js | 12 +++ es/lib/util/toString.js | 15 +++ es/lib/whitelist.js | 5 + package.json | 7 +- validator.js | 202 ++---------------------------------- validator.min.js | 2 +- 82 files changed, 2024 insertions(+), 208 deletions(-) create mode 100644 es/index.js create mode 100644 es/lib/alpha.js create mode 100644 es/lib/blacklist.js create mode 100644 es/lib/contains.js create mode 100644 es/lib/equals.js create mode 100644 es/lib/escape.js create mode 100644 es/lib/isAfter.js create mode 100644 es/lib/isAlpha.js create mode 100644 es/lib/isAlphanumeric.js create mode 100644 es/lib/isAscii.js create mode 100644 es/lib/isBase64.js create mode 100644 es/lib/isBefore.js create mode 100644 es/lib/isBoolean.js create mode 100644 es/lib/isByteLength.js create mode 100644 es/lib/isCreditCard.js create mode 100644 es/lib/isCurrency.js create mode 100644 es/lib/isDataURI.js create mode 100644 es/lib/isDecimal.js create mode 100644 es/lib/isDivisibleBy.js create mode 100644 es/lib/isEmail.js create mode 100644 es/lib/isEmpty.js create mode 100644 es/lib/isFQDN.js create mode 100644 es/lib/isFloat.js create mode 100644 es/lib/isFullWidth.js create mode 100644 es/lib/isHalfWidth.js create mode 100644 es/lib/isHash.js create mode 100644 es/lib/isHexColor.js create mode 100644 es/lib/isHexadecimal.js create mode 100644 es/lib/isIP.js create mode 100644 es/lib/isIPRange.js create mode 100644 es/lib/isISBN.js create mode 100644 es/lib/isISIN.js create mode 100644 es/lib/isISO31661Alpha2.js create mode 100644 es/lib/isISO31661Alpha3.js create mode 100644 es/lib/isISO8601.js create mode 100644 es/lib/isISRC.js create mode 100644 es/lib/isISSN.js create mode 100644 es/lib/isIdentityCard.js create mode 100644 es/lib/isIn.js create mode 100644 es/lib/isInt.js create mode 100644 es/lib/isJSON.js create mode 100644 es/lib/isJWT.js create mode 100644 es/lib/isLatLong.js create mode 100644 es/lib/isLength.js create mode 100644 es/lib/isLowercase.js create mode 100644 es/lib/isMACAddress.js create mode 100644 es/lib/isMD5.js create mode 100644 es/lib/isMagnetURI.js create mode 100644 es/lib/isMimeType.js create mode 100644 es/lib/isMobilePhone.js create mode 100644 es/lib/isMongoId.js create mode 100644 es/lib/isMultibyte.js create mode 100644 es/lib/isNumeric.js create mode 100644 es/lib/isPort.js create mode 100644 es/lib/isPostalCode.js create mode 100644 es/lib/isRFC3339.js create mode 100644 es/lib/isSurrogatePair.js create mode 100644 es/lib/isURL.js create mode 100644 es/lib/isUUID.js create mode 100644 es/lib/isUppercase.js create mode 100644 es/lib/isVariableWidth.js create mode 100644 es/lib/isWhitelisted.js create mode 100644 es/lib/ltrim.js create mode 100644 es/lib/matches.js create mode 100644 es/lib/normalizeEmail.js create mode 100644 es/lib/rtrim.js create mode 100644 es/lib/stripLow.js create mode 100644 es/lib/toBoolean.js create mode 100644 es/lib/toDate.js create mode 100644 es/lib/toFloat.js create mode 100644 es/lib/toInt.js create mode 100644 es/lib/trim.js create mode 100644 es/lib/unescape.js create mode 100644 es/lib/util/assertString.js create mode 100644 es/lib/util/includes.js create mode 100644 es/lib/util/merge.js create mode 100644 es/lib/util/toString.js create mode 100644 es/lib/whitelist.js diff --git a/.babelrc b/.babelrc index 318ea9718..332bba6f9 100644 --- a/.babelrc +++ b/.babelrc @@ -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 + } + ] + ] + } + } +} \ No newline at end of file diff --git a/es/index.js b/es/index.js new file mode 100644 index 000000000..d31792546 --- /dev/null +++ b/es/index.js @@ -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; \ No newline at end of file diff --git a/es/lib/alpha.js b/es/lib/alpha.js new file mode 100644 index 000000000..68f735065 --- /dev/null +++ b/es/lib/alpha.js @@ -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']; \ No newline at end of file diff --git a/es/lib/blacklist.js b/es/lib/blacklist.js new file mode 100644 index 000000000..77c0e5cfc --- /dev/null +++ b/es/lib/blacklist.js @@ -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'), ''); +} \ No newline at end of file diff --git a/es/lib/contains.js b/es/lib/contains.js new file mode 100644 index 000000000..10bd66860 --- /dev/null +++ b/es/lib/contains.js @@ -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; +} \ No newline at end of file diff --git a/es/lib/equals.js b/es/lib/equals.js new file mode 100644 index 000000000..87a9ded0e --- /dev/null +++ b/es/lib/equals.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function equals(str, comparison) { + assertString(str); + return str === comparison; +} \ No newline at end of file diff --git a/es/lib/escape.js b/es/lib/escape.js new file mode 100644 index 000000000..e9bb6de30 --- /dev/null +++ b/es/lib/escape.js @@ -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, '`'); +} \ No newline at end of file diff --git a/es/lib/isAfter.js b/es/lib/isAfter.js new file mode 100644 index 000000000..b99cfa424 --- /dev/null +++ b/es/lib/isAfter.js @@ -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); +} \ No newline at end of file diff --git a/es/lib/isAlpha.js b/es/lib/isAlpha.js new file mode 100644 index 000000000..2b30d1463 --- /dev/null +++ b/es/lib/isAlpha.js @@ -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); \ No newline at end of file diff --git a/es/lib/isAlphanumeric.js b/es/lib/isAlphanumeric.js new file mode 100644 index 000000000..4bbca75ba --- /dev/null +++ b/es/lib/isAlphanumeric.js @@ -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); \ No newline at end of file diff --git a/es/lib/isAscii.js b/es/lib/isAscii.js new file mode 100644 index 000000000..e322121fc --- /dev/null +++ b/es/lib/isAscii.js @@ -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); +} \ No newline at end of file diff --git a/es/lib/isBase64.js b/es/lib/isBase64.js new file mode 100644 index 000000000..de9e4e31b --- /dev/null +++ b/es/lib/isBase64.js @@ -0,0 +1,13 @@ +import assertString from './util/assertString'; +var notBase64 = /[^A-Z0-9+\/=]/i; +export default function isBase64(str) { + assertString(str); + var len = str.length; + + if (!len || len % 4 !== 0 || notBase64.test(str)) { + return false; + } + + var firstPaddingChar = str.indexOf('='); + return firstPaddingChar === -1 || firstPaddingChar === len - 1 || firstPaddingChar === len - 2 && str[len - 1] === '='; +} \ No newline at end of file diff --git a/es/lib/isBefore.js b/es/lib/isBefore.js new file mode 100644 index 000000000..794dbaba3 --- /dev/null +++ b/es/lib/isBefore.js @@ -0,0 +1,9 @@ +import assertString from './util/assertString'; +import toDate from './toDate'; +export default function isBefore(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); +} \ No newline at end of file diff --git a/es/lib/isBoolean.js b/es/lib/isBoolean.js new file mode 100644 index 000000000..d50092f24 --- /dev/null +++ b/es/lib/isBoolean.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function isBoolean(str) { + assertString(str); + return ['true', 'false', '1', '0'].indexOf(str) >= 0; +} \ No newline at end of file diff --git a/es/lib/isByteLength.js b/es/lib/isByteLength.js new file mode 100644 index 000000000..20d76dfa5 --- /dev/null +++ b/es/lib/isByteLength.js @@ -0,0 +1,22 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +import assertString from './util/assertString'; +/* eslint-disable prefer-rest-params */ + +export default function isByteLength(str, options) { + assertString(str); + var min; + var max; + + if (_typeof(options) === 'object') { + min = options.min || 0; + max = options.max; + } else { + // backwards compatibility: isByteLength(str, min [, max]) + min = arguments[1]; + max = arguments[2]; + } + + var len = encodeURI(str).split(/%..|./).length - 1; + return len >= min && (typeof max === 'undefined' || len <= max); +} \ No newline at end of file diff --git a/es/lib/isCreditCard.js b/es/lib/isCreditCard.js new file mode 100644 index 000000000..7f147365b --- /dev/null +++ b/es/lib/isCreditCard.js @@ -0,0 +1,40 @@ +import assertString from './util/assertString'; +/* eslint-disable max-len */ + +var creditCard = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/; +/* eslint-enable max-len */ + +export default function isCreditCard(str) { + assertString(str); + var sanitized = str.replace(/[- ]+/g, ''); + + if (!creditCard.test(sanitized)) { + return false; + } + + var sum = 0; + var digit; + var tmpNum; + var shouldDouble; + + for (var i = sanitized.length - 1; i >= 0; i--) { + digit = sanitized.substring(i, i + 1); + tmpNum = parseInt(digit, 10); + + if (shouldDouble) { + tmpNum *= 2; + + if (tmpNum >= 10) { + sum += tmpNum % 10 + 1; + } else { + sum += tmpNum; + } + } else { + sum += tmpNum; + } + + shouldDouble = !shouldDouble; + } + + return !!(sum % 10 === 0 ? sanitized : false); +} \ No newline at end of file diff --git a/es/lib/isCurrency.js b/es/lib/isCurrency.js new file mode 100644 index 000000000..a95020bb5 --- /dev/null +++ b/es/lib/isCurrency.js @@ -0,0 +1,75 @@ +import merge from './util/merge'; +import assertString from './util/assertString'; + +function currencyRegex(options) { + var decimal_digits = "\\d{".concat(options.digits_after_decimal[0], "}"); + options.digits_after_decimal.forEach(function (digit, index) { + if (index !== 0) decimal_digits = "".concat(decimal_digits, "|\\d{").concat(digit, "}"); + }); + var symbol = "(\\".concat(options.symbol.replace(/\./g, '\\.'), ")").concat(options.require_symbol ? '' : '?'), + negative = '-?', + whole_dollar_amount_without_sep = '[1-9]\\d*', + whole_dollar_amount_with_sep = "[1-9]\\d{0,2}(\\".concat(options.thousands_separator, "\\d{3})*"), + valid_whole_dollar_amounts = ['0', whole_dollar_amount_without_sep, whole_dollar_amount_with_sep], + whole_dollar_amount = "(".concat(valid_whole_dollar_amounts.join('|'), ")?"), + decimal_amount = "(\\".concat(options.decimal_separator, "(").concat(decimal_digits, "))").concat(options.require_decimal ? '' : '?'); + var pattern = whole_dollar_amount + (options.allow_decimal || options.require_decimal ? decimal_amount : ''); // default is negative sign before symbol, but there are two other options (besides parens) + + if (options.allow_negatives && !options.parens_for_negatives) { + if (options.negative_sign_after_digits) { + pattern += negative; + } else if (options.negative_sign_before_digits) { + pattern = negative + pattern; + } + } // South African Rand, for example, uses R 123 (space) and R-123 (no space) + + + if (options.allow_negative_sign_placeholder) { + pattern = "( (?!\\-))?".concat(pattern); + } else if (options.allow_space_after_symbol) { + pattern = " ?".concat(pattern); + } else if (options.allow_space_after_digits) { + pattern += '( (?!$))?'; + } + + if (options.symbol_after_digits) { + pattern += symbol; + } else { + pattern = symbol + pattern; + } + + if (options.allow_negatives) { + if (options.parens_for_negatives) { + pattern = "(\\(".concat(pattern, "\\)|").concat(pattern, ")"); + } else if (!(options.negative_sign_before_digits || options.negative_sign_after_digits)) { + pattern = negative + pattern; + } + } // ensure there's a dollar and/or decimal amount, and that + // it doesn't start with a space or a negative sign followed by a space + + + return new RegExp("^(?!-? )(?=.*\\d)".concat(pattern, "$")); +} + +var default_currency_options = { + symbol: '$', + require_symbol: false, + allow_space_after_symbol: false, + symbol_after_digits: false, + allow_negatives: true, + parens_for_negatives: false, + negative_sign_before_digits: false, + negative_sign_after_digits: false, + allow_negative_sign_placeholder: false, + thousands_separator: ',', + decimal_separator: '.', + allow_decimal: true, + require_decimal: false, + digits_after_decimal: [2], + allow_space_after_digits: false +}; +export default function isCurrency(str, options) { + assertString(str); + options = merge(options, default_currency_options); + return currencyRegex(options).test(str); +} \ No newline at end of file diff --git a/es/lib/isDataURI.js b/es/lib/isDataURI.js new file mode 100644 index 000000000..781be5b3c --- /dev/null +++ b/es/lib/isDataURI.js @@ -0,0 +1,40 @@ +import assertString from './util/assertString'; +var validMediaType = /^[a-z]+\/[a-z0-9\-\+]+$/i; +var validAttribute = /^[a-z\-]+=[a-z0-9\-]+$/i; +var validData = /^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i; +export default function isDataURI(str) { + assertString(str); + var data = str.split(','); + + if (data.length < 2) { + return false; + } + + var attributes = data.shift().trim().split(';'); + var schemeAndMediaType = attributes.shift(); + + if (schemeAndMediaType.substr(0, 5) !== 'data:') { + return false; + } + + var mediaType = schemeAndMediaType.substr(5); + + if (mediaType !== '' && !validMediaType.test(mediaType)) { + return false; + } + + for (var i = 0; i < attributes.length; i++) { + if (i === attributes.length - 1 && attributes[i].toLowerCase() === 'base64') {// ok + } else if (!validAttribute.test(attributes[i])) { + return false; + } + } + + for (var _i = 0; _i < data.length; _i++) { + if (!validData.test(data[_i])) { + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/es/lib/isDecimal.js b/es/lib/isDecimal.js new file mode 100644 index 000000000..597f42c5e --- /dev/null +++ b/es/lib/isDecimal.js @@ -0,0 +1,26 @@ +import merge from './util/merge'; +import assertString from './util/assertString'; +import includes from './util/includes'; +import { decimal } from './alpha'; + +function decimalRegExp(options) { + var regExp = new RegExp("^[-+]?([0-9]+)?(\\".concat(decimal[options.locale], "[0-9]{").concat(options.decimal_digits, "})").concat(options.force_decimal ? '' : '?', "$")); + return regExp; +} + +var default_decimal_options = { + force_decimal: false, + decimal_digits: '1,', + locale: 'en-US' +}; +var blacklist = ['', '-', '+']; +export default function isDecimal(str, options) { + assertString(str); + options = merge(options, default_decimal_options); + + if (options.locale in decimal) { + return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str); + } + + throw new Error("Invalid locale '".concat(options.locale, "'")); +} \ No newline at end of file diff --git a/es/lib/isDivisibleBy.js b/es/lib/isDivisibleBy.js new file mode 100644 index 000000000..f71d5f4e2 --- /dev/null +++ b/es/lib/isDivisibleBy.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +import toFloat from './toFloat'; +export default function isDivisibleBy(str, num) { + assertString(str); + return toFloat(str) % parseInt(num, 10) === 0; +} \ No newline at end of file diff --git a/es/lib/isEmail.js b/es/lib/isEmail.js new file mode 100644 index 000000000..e006bf4c0 --- /dev/null +++ b/es/lib/isEmail.js @@ -0,0 +1,116 @@ +import assertString from './util/assertString'; +import merge from './util/merge'; +import isByteLength from './isByteLength'; +import isFQDN from './isFQDN'; +import isIP from './isIP'; +var default_email_options = { + allow_display_name: false, + require_display_name: false, + allow_utf8_local_part: true, + require_tld: true +}; +/* eslint-disable max-len */ + +/* eslint-disable no-control-regex */ + +var displayName = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\,\.\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF\s]*<(.+)>$/i; +var emailUserPart = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i; +var gmailUserPart = /^[a-z\d]+$/; +var quotedEmailUser = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i; +var emailUserUtf8Part = /^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i; +var quotedEmailUserUtf8 = /^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i; +/* eslint-enable max-len */ + +/* eslint-enable no-control-regex */ + +export default function isEmail(str, options) { + assertString(str); + options = merge(options, default_email_options); + + if (options.require_display_name || options.allow_display_name) { + var display_email = str.match(displayName); + + if (display_email) { + str = display_email[1]; + } else if (options.require_display_name) { + return false; + } + } + + var parts = str.split('@'); + var domain = parts.pop(); + var user = parts.join('@'); + var lower_domain = domain.toLowerCase(); + + if (options.domain_specific_validation && (lower_domain === 'gmail.com' || lower_domain === 'googlemail.com')) { + /* + Previously we removed dots for gmail addresses before validating. + This was removed because it allows `multiple..dots@gmail.com` + to be reported as valid, but it is not. + Gmail only normalizes single dots, removing them from here is pointless, + should be done in normalizeEmail + */ + user = user.toLowerCase(); // Removing sub-address from username before gmail validation + + var username = user.split('+')[0]; // Dots are not included in gmail length restriction + + if (!isByteLength(username.replace('.', ''), { + min: 6, + max: 30 + })) { + return false; + } + + var _user_parts = username.split('.'); + + for (var i = 0; i < _user_parts.length; i++) { + if (!gmailUserPart.test(_user_parts[i])) { + return false; + } + } + } + + if (!isByteLength(user, { + max: 64 + }) || !isByteLength(domain, { + max: 254 + })) { + return false; + } + + if (!isFQDN(domain, { + require_tld: options.require_tld + })) { + if (!options.allow_ip_domain) { + return false; + } + + if (!isIP(domain)) { + if (!domain.startsWith('[') || !domain.endsWith(']')) { + return false; + } + + var noBracketdomain = domain.substr(1, domain.length - 2); + + if (noBracketdomain.length === 0 || !isIP(noBracketdomain)) { + return false; + } + } + } + + if (user[0] === '"') { + user = user.slice(1, user.length - 1); + return options.allow_utf8_local_part ? quotedEmailUserUtf8.test(user) : quotedEmailUser.test(user); + } + + var pattern = options.allow_utf8_local_part ? emailUserUtf8Part : emailUserPart; + var user_parts = user.split('.'); + + for (var _i = 0; _i < user_parts.length; _i++) { + if (!pattern.test(user_parts[_i])) { + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/es/lib/isEmpty.js b/es/lib/isEmpty.js new file mode 100644 index 000000000..79e29f74d --- /dev/null +++ b/es/lib/isEmpty.js @@ -0,0 +1,10 @@ +import assertString from './util/assertString'; +import merge from './util/merge'; +var default_is_empty_options = { + ignore_whitespace: false +}; +export default function isEmpty(str, options) { + assertString(str); + options = merge(options, default_is_empty_options); + return (options.ignore_whitespace ? str.trim().length : str.length) === 0; +} \ No newline at end of file diff --git a/es/lib/isFQDN.js b/es/lib/isFQDN.js new file mode 100644 index 000000000..8a64bf2d4 --- /dev/null +++ b/es/lib/isFQDN.js @@ -0,0 +1,60 @@ +import assertString from './util/assertString'; +import merge from './util/merge'; +var default_fqdn_options = { + require_tld: true, + allow_underscores: false, + allow_trailing_dot: false +}; +export default function isFQDN(str, options) { + assertString(str); + options = merge(options, default_fqdn_options); + /* Remove the optional trailing dot before checking validity */ + + if (options.allow_trailing_dot && str[str.length - 1] === '.') { + str = str.substring(0, str.length - 1); + } + + var parts = str.split('.'); + + for (var i = 0; i < parts.length; i++) { + if (parts[i].length > 63) { + return false; + } + } + + if (options.require_tld) { + var tld = parts.pop(); + + if (!parts.length || !/^([a-z\u00a1-\uffff]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) { + return false; + } // disallow spaces + + + if (/[\s\u2002-\u200B\u202F\u205F\u3000\uFEFF\uDB40\uDC20]/.test(tld)) { + return false; + } + } + + for (var part, _i = 0; _i < parts.length; _i++) { + part = parts[_i]; + + if (options.allow_underscores) { + part = part.replace(/_/g, ''); + } + + if (!/^[a-z\u00a1-\uffff0-9-]+$/i.test(part)) { + return false; + } // disallow full-width chars + + + if (/[\uff01-\uff5e]/.test(part)) { + return false; + } + + if (part[0] === '-' || part[part.length - 1] === '-') { + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/es/lib/isFloat.js b/es/lib/isFloat.js new file mode 100644 index 000000000..069873b21 --- /dev/null +++ b/es/lib/isFloat.js @@ -0,0 +1,16 @@ +import assertString from './util/assertString'; +import { decimal } from './alpha'; +export default function isFloat(str, options) { + assertString(str); + options = options || {}; + + var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")); + + if (str === '' || str === '.' || str === '-' || str === '+') { + return false; + } + + var value = parseFloat(str.replace(',', '.')); + return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt); +} +export var locales = Object.keys(decimal); \ No newline at end of file diff --git a/es/lib/isFullWidth.js b/es/lib/isFullWidth.js new file mode 100644 index 000000000..ae5462957 --- /dev/null +++ b/es/lib/isFullWidth.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +export var fullWidth = /[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/; +export default function isFullWidth(str) { + assertString(str); + return fullWidth.test(str); +} \ No newline at end of file diff --git a/es/lib/isHalfWidth.js b/es/lib/isHalfWidth.js new file mode 100644 index 000000000..b0c879573 --- /dev/null +++ b/es/lib/isHalfWidth.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +export var halfWidth = /[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/; +export default function isHalfWidth(str) { + assertString(str); + return halfWidth.test(str); +} \ No newline at end of file diff --git a/es/lib/isHash.js b/es/lib/isHash.js new file mode 100644 index 000000000..05620b647 --- /dev/null +++ b/es/lib/isHash.js @@ -0,0 +1,21 @@ +import assertString from './util/assertString'; +var lengths = { + md5: 32, + md4: 32, + sha1: 40, + sha256: 64, + sha384: 96, + sha512: 128, + ripemd128: 32, + ripemd160: 40, + tiger128: 32, + tiger160: 40, + tiger192: 48, + crc32: 8, + crc32b: 8 +}; +export default function isHash(str, algorithm) { + assertString(str); + var hash = new RegExp("^[a-f0-9]{".concat(lengths[algorithm], "}$")); + return hash.test(str); +} \ No newline at end of file diff --git a/es/lib/isHexColor.js b/es/lib/isHexColor.js new file mode 100644 index 000000000..dbd1df668 --- /dev/null +++ b/es/lib/isHexColor.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +var hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{6})$/i; +export default function isHexColor(str) { + assertString(str); + return hexcolor.test(str); +} \ No newline at end of file diff --git a/es/lib/isHexadecimal.js b/es/lib/isHexadecimal.js new file mode 100644 index 000000000..0cc972f41 --- /dev/null +++ b/es/lib/isHexadecimal.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +var hexadecimal = /^[0-9A-F]+$/i; +export default function isHexadecimal(str) { + assertString(str); + return hexadecimal.test(str); +} \ No newline at end of file diff --git a/es/lib/isIP.js b/es/lib/isIP.js new file mode 100644 index 000000000..219d5af93 --- /dev/null +++ b/es/lib/isIP.js @@ -0,0 +1,72 @@ +import assertString from './util/assertString'; +var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +var ipv6Block = /^[0-9A-F]{1,4}$/i; +export default function isIP(str) { + var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; + assertString(str); + version = String(version); + + if (!version) { + return isIP(str, 4) || isIP(str, 6); + } else if (version === '4') { + if (!ipv4Maybe.test(str)) { + return false; + } + + var parts = str.split('.').sort(function (a, b) { + return a - b; + }); + return parts[3] <= 255; + } else if (version === '6') { + var blocks = str.split(':'); + var foundOmissionBlock = false; // marker to indicate :: + // At least some OS accept the last 32 bits of an IPv6 address + // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says + // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses, + // and '::a.b.c.d' is deprecated, but also valid. + + var foundIPv4TransitionBlock = isIP(blocks[blocks.length - 1], 4); + var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8; + + if (blocks.length > expectedNumberOfBlocks) { + return false; + } // initial or final :: + + + if (str === '::') { + return true; + } else if (str.substr(0, 2) === '::') { + blocks.shift(); + blocks.shift(); + foundOmissionBlock = true; + } else if (str.substr(str.length - 2) === '::') { + blocks.pop(); + blocks.pop(); + foundOmissionBlock = true; + } + + for (var i = 0; i < blocks.length; ++i) { + // test for a :: which can not be at the string start/end + // since those cases have been handled above + if (blocks[i] === '' && i > 0 && i < blocks.length - 1) { + if (foundOmissionBlock) { + return false; // multiple :: in address + } + + foundOmissionBlock = true; + } else if (foundIPv4TransitionBlock && i === blocks.length - 1) {// it has been checked before that the last + // block is a valid IPv4 address + } else if (!ipv6Block.test(blocks[i])) { + return false; + } + } + + if (foundOmissionBlock) { + return blocks.length >= 1; + } + + return blocks.length === expectedNumberOfBlocks; + } + + return false; +} \ No newline at end of file diff --git a/es/lib/isIPRange.js b/es/lib/isIPRange.js new file mode 100644 index 000000000..feb6c553c --- /dev/null +++ b/es/lib/isIPRange.js @@ -0,0 +1,22 @@ +import assertString from './util/assertString'; +import isIP from './isIP'; +var subnetMaybe = /^\d{1,2}$/; +export default function isIPRange(str) { + assertString(str); + var parts = str.split('/'); // parts[0] -> ip, parts[1] -> subnet + + if (parts.length !== 2) { + return false; + } + + if (!subnetMaybe.test(parts[1])) { + return false; + } // Disallow preceding 0 i.e. 01, 02, ... + + + if (parts[1].length > 1 && parts[1].startsWith('0')) { + return false; + } + + return isIP(parts[0], 4) && parts[1] <= 32 && parts[1] >= 0; +} \ No newline at end of file diff --git a/es/lib/isISBN.js b/es/lib/isISBN.js new file mode 100644 index 000000000..da2c435ba --- /dev/null +++ b/es/lib/isISBN.js @@ -0,0 +1,51 @@ +import assertString from './util/assertString'; +var isbn10Maybe = /^(?:[0-9]{9}X|[0-9]{10})$/; +var isbn13Maybe = /^(?:[0-9]{13})$/; +var factor = [1, 3]; +export default function isISBN(str) { + var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; + assertString(str); + version = String(version); + + if (!version) { + return isISBN(str, 10) || isISBN(str, 13); + } + + var sanitized = str.replace(/[\s-]+/g, ''); + var checksum = 0; + var i; + + if (version === '10') { + if (!isbn10Maybe.test(sanitized)) { + return false; + } + + for (i = 0; i < 9; i++) { + checksum += (i + 1) * sanitized.charAt(i); + } + + if (sanitized.charAt(9) === 'X') { + checksum += 10 * 10; + } else { + checksum += 10 * sanitized.charAt(9); + } + + if (checksum % 11 === 0) { + return !!sanitized; + } + } else if (version === '13') { + if (!isbn13Maybe.test(sanitized)) { + return false; + } + + for (i = 0; i < 12; i++) { + checksum += factor[i % 2] * sanitized.charAt(i); + } + + if (sanitized.charAt(12) - (10 - checksum % 10) % 10 === 0) { + return !!sanitized; + } + } + + return false; +} \ No newline at end of file diff --git a/es/lib/isISIN.js b/es/lib/isISIN.js new file mode 100644 index 000000000..c93c5804d --- /dev/null +++ b/es/lib/isISIN.js @@ -0,0 +1,38 @@ +import assertString from './util/assertString'; +var isin = /^[A-Z]{2}[0-9A-Z]{9}[0-9]$/; +export default function isISIN(str) { + assertString(str); + + if (!isin.test(str)) { + return false; + } + + var checksumStr = str.replace(/[A-Z]/g, function (character) { + return parseInt(character, 36); + }); + var sum = 0; + var digit; + var tmpNum; + var shouldDouble = true; + + for (var i = checksumStr.length - 2; i >= 0; i--) { + digit = checksumStr.substring(i, i + 1); + tmpNum = parseInt(digit, 10); + + if (shouldDouble) { + tmpNum *= 2; + + if (tmpNum >= 10) { + sum += tmpNum + 1; + } else { + sum += tmpNum; + } + } else { + sum += tmpNum; + } + + shouldDouble = !shouldDouble; + } + + return parseInt(str.substr(str.length - 1), 10) === (10000 - sum) % 10; +} \ No newline at end of file diff --git a/es/lib/isISO31661Alpha2.js b/es/lib/isISO31661Alpha2.js new file mode 100644 index 000000000..219a511a2 --- /dev/null +++ b/es/lib/isISO31661Alpha2.js @@ -0,0 +1,8 @@ +import assertString from './util/assertString'; +import includes from './util/includes'; // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + +var validISO31661Alpha2CountriesCodes = ['AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'SS', 'ST', 'SV', 'SX', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW']; +export default function isISO31661Alpha2(str) { + assertString(str); + return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase()); +} \ No newline at end of file diff --git a/es/lib/isISO31661Alpha3.js b/es/lib/isISO31661Alpha3.js new file mode 100644 index 000000000..f51ab59d0 --- /dev/null +++ b/es/lib/isISO31661Alpha3.js @@ -0,0 +1,8 @@ +import assertString from './util/assertString'; +import includes from './util/includes'; // from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3 + +var validISO31661Alpha3CountriesCodes = ['AFG', 'ALA', 'ALB', 'DZA', 'ASM', 'AND', 'AGO', 'AIA', 'ATA', 'ATG', 'ARG', 'ARM', 'ABW', 'AUS', 'AUT', 'AZE', 'BHS', 'BHR', 'BGD', 'BRB', 'BLR', 'BEL', 'BLZ', 'BEN', 'BMU', 'BTN', 'BOL', 'BES', 'BIH', 'BWA', 'BVT', 'BRA', 'IOT', 'BRN', 'BGR', 'BFA', 'BDI', 'KHM', 'CMR', 'CAN', 'CPV', 'CYM', 'CAF', 'TCD', 'CHL', 'CHN', 'CXR', 'CCK', 'COL', 'COM', 'COG', 'COD', 'COK', 'CRI', 'CIV', 'HRV', 'CUB', 'CUW', 'CYP', 'CZE', 'DNK', 'DJI', 'DMA', 'DOM', 'ECU', 'EGY', 'SLV', 'GNQ', 'ERI', 'EST', 'ETH', 'FLK', 'FRO', 'FJI', 'FIN', 'FRA', 'GUF', 'PYF', 'ATF', 'GAB', 'GMB', 'GEO', 'DEU', 'GHA', 'GIB', 'GRC', 'GRL', 'GRD', 'GLP', 'GUM', 'GTM', 'GGY', 'GIN', 'GNB', 'GUY', 'HTI', 'HMD', 'VAT', 'HND', 'HKG', 'HUN', 'ISL', 'IND', 'IDN', 'IRN', 'IRQ', 'IRL', 'IMN', 'ISR', 'ITA', 'JAM', 'JPN', 'JEY', 'JOR', 'KAZ', 'KEN', 'KIR', 'PRK', 'KOR', 'KWT', 'KGZ', 'LAO', 'LVA', 'LBN', 'LSO', 'LBR', 'LBY', 'LIE', 'LTU', 'LUX', 'MAC', 'MKD', 'MDG', 'MWI', 'MYS', 'MDV', 'MLI', 'MLT', 'MHL', 'MTQ', 'MRT', 'MUS', 'MYT', 'MEX', 'FSM', 'MDA', 'MCO', 'MNG', 'MNE', 'MSR', 'MAR', 'MOZ', 'MMR', 'NAM', 'NRU', 'NPL', 'NLD', 'NCL', 'NZL', 'NIC', 'NER', 'NGA', 'NIU', 'NFK', 'MNP', 'NOR', 'OMN', 'PAK', 'PLW', 'PSE', 'PAN', 'PNG', 'PRY', 'PER', 'PHL', 'PCN', 'POL', 'PRT', 'PRI', 'QAT', 'REU', 'ROU', 'RUS', 'RWA', 'BLM', 'SHN', 'KNA', 'LCA', 'MAF', 'SPM', 'VCT', 'WSM', 'SMR', 'STP', 'SAU', 'SEN', 'SRB', 'SYC', 'SLE', 'SGP', 'SXM', 'SVK', 'SVN', 'SLB', 'SOM', 'ZAF', 'SGS', 'SSD', 'ESP', 'LKA', 'SDN', 'SUR', 'SJM', 'SWZ', 'SWE', 'CHE', 'SYR', 'TWN', 'TJK', 'TZA', 'THA', 'TLS', 'TGO', 'TKL', 'TON', 'TTO', 'TUN', 'TUR', 'TKM', 'TCA', 'TUV', 'UGA', 'UKR', 'ARE', 'GBR', 'USA', 'UMI', 'URY', 'UZB', 'VUT', 'VEN', 'VNM', 'VGB', 'VIR', 'WLF', 'ESH', 'YEM', 'ZMB', 'ZWE']; +export default function isISO31661Alpha3(str) { + assertString(str); + return includes(validISO31661Alpha3CountriesCodes, str.toUpperCase()); +} \ No newline at end of file diff --git a/es/lib/isISO8601.js b/es/lib/isISO8601.js new file mode 100644 index 000000000..1744d5bc5 --- /dev/null +++ b/es/lib/isISO8601.js @@ -0,0 +1,46 @@ +import assertString from './util/assertString'; +/* eslint-disable max-len */ +// from http://goo.gl/0ejHHW + +var iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; +/* eslint-enable max-len */ + +var isValidDate = function isValidDate(str) { + // str must have passed the ISO8601 check + // this check is meant to catch invalid dates + // like 2009-02-31 + // first check for ordinal dates + var ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/); + + if (ordinalMatch) { + var oYear = Number(ordinalMatch[1]); + var oDay = Number(ordinalMatch[2]); // if is leap year + + if (oYear % 4 === 0 && oYear % 100 !== 0) return oDay <= 366; + return oDay <= 365; + } + + var match = str.match(/(\d{4})-?(\d{0,2})-?(\d*)/).map(Number); + var year = match[1]; + var month = match[2]; + var day = match[3]; + var monthString = month ? "0".concat(month).slice(-2) : month; + var dayString = day ? "0".concat(day).slice(-2) : day; // create a date object and compare + + var d = new Date("".concat(year, "-").concat(monthString || '01', "-").concat(dayString || '01')); + if (isNaN(d.getUTCFullYear())) return false; + + if (month && day) { + return d.getUTCFullYear() === year && d.getUTCMonth() + 1 === month && d.getUTCDate() === day; + } + + return true; +}; + +export default function isISO8601(str, options) { + assertString(str); + var check = iso8601.test(str); + if (!options) return check; + if (check && options.strict) return isValidDate(str); + return check; +} \ No newline at end of file diff --git a/es/lib/isISRC.js b/es/lib/isISRC.js new file mode 100644 index 000000000..275c10a95 --- /dev/null +++ b/es/lib/isISRC.js @@ -0,0 +1,7 @@ +import assertString from './util/assertString'; // see http://isrc.ifpi.org/en/isrc-standard/code-syntax + +var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/; +export default function isISRC(str) { + assertString(str); + return isrc.test(str); +} \ No newline at end of file diff --git a/es/lib/isISSN.js b/es/lib/isISSN.js new file mode 100644 index 000000000..bebfa9eeb --- /dev/null +++ b/es/lib/isISSN.js @@ -0,0 +1,23 @@ +import assertString from './util/assertString'; +var issn = '^\\d{4}-?\\d{3}[\\dX]$'; +export default function isISSN(str) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + assertString(str); + var testIssn = issn; + testIssn = options.require_hyphen ? testIssn.replace('?', '') : testIssn; + testIssn = options.case_sensitive ? new RegExp(testIssn) : new RegExp(testIssn, 'i'); + + if (!testIssn.test(str)) { + return false; + } + + var digits = str.replace('-', '').toUpperCase(); + var checksum = 0; + + for (var i = 0; i < digits.length; i++) { + var digit = digits[i]; + checksum += (digit === 'X' ? 10 : +digit) * (8 - i); + } + + return checksum % 11 === 0; +} \ No newline at end of file diff --git a/es/lib/isIdentityCard.js b/es/lib/isIdentityCard.js new file mode 100644 index 000000000..0a2bf648a --- /dev/null +++ b/es/lib/isIdentityCard.js @@ -0,0 +1,47 @@ +import assertString from './util/assertString'; +var validators = { + ES: function ES(str) { + assertString(str); + var DNI = /^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/; + var charsValue = { + X: 0, + Y: 1, + Z: 2 + }; + var controlDigits = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E']; // sanitize user input + + var sanitized = str.trim().toUpperCase(); // validate the data structure + + if (!DNI.test(sanitized)) { + return false; + } // validate the control digit + + + var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) { + return charsValue[_char]; + }); + return sanitized.endsWith(controlDigits[number % 23]); + } +}; +export default function isIdentityCard(str) { + var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'any'; + assertString(str); + + if (locale in validators) { + return validators[locale](str); + } else if (locale === 'any') { + for (var key in validators) { + if (validators.hasOwnProperty(key)) { + var validator = validators[key]; + + if (validator(str)) { + return true; + } + } + } + + return false; + } + + throw new Error("Invalid locale '".concat(locale, "'")); +} \ No newline at end of file diff --git a/es/lib/isIn.js b/es/lib/isIn.js new file mode 100644 index 000000000..9d4acd641 --- /dev/null +++ b/es/lib/isIn.js @@ -0,0 +1,26 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +import assertString from './util/assertString'; +import toString from './util/toString'; +export default function isIn(str, options) { + assertString(str); + var i; + + if (Object.prototype.toString.call(options) === '[object Array]') { + var array = []; + + for (i in options) { + if ({}.hasOwnProperty.call(options, i)) { + array[i] = toString(options[i]); + } + } + + return array.indexOf(str) >= 0; + } else if (_typeof(options) === 'object') { + return options.hasOwnProperty(str); + } else if (options && typeof options.indexOf === 'function') { + return options.indexOf(str) >= 0; + } + + return false; +} \ No newline at end of file diff --git a/es/lib/isInt.js b/es/lib/isInt.js new file mode 100644 index 000000000..b58dab40d --- /dev/null +++ b/es/lib/isInt.js @@ -0,0 +1,16 @@ +import assertString from './util/assertString'; +var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/; +var intLeadingZeroes = /^[-+]?[0-9]+$/; +export default function isInt(str, options) { + assertString(str); + options = options || {}; // Get the regex to use for testing, based on whether + // leading zeroes are allowed or not. + + var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? _int : intLeadingZeroes; // Check min/max/lt/gt + + var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min; + var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max; + var ltCheckPassed = !options.hasOwnProperty('lt') || str < options.lt; + var gtCheckPassed = !options.hasOwnProperty('gt') || str > options.gt; + return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed; +} \ No newline at end of file diff --git a/es/lib/isJSON.js b/es/lib/isJSON.js new file mode 100644 index 000000000..ddcccf0e7 --- /dev/null +++ b/es/lib/isJSON.js @@ -0,0 +1,15 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +import assertString from './util/assertString'; +export default function isJSON(str) { + assertString(str); + + try { + var obj = JSON.parse(str); + return !!obj && _typeof(obj) === 'object'; + } catch (e) { + /* ignore */ + } + + return false; +} \ No newline at end of file diff --git a/es/lib/isJWT.js b/es/lib/isJWT.js new file mode 100644 index 000000000..41a6ece0d --- /dev/null +++ b/es/lib/isJWT.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +var jwt = /^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/; +export default function isJWT(str) { + assertString(str); + return jwt.test(str); +} \ No newline at end of file diff --git a/es/lib/isLatLong.js b/es/lib/isLatLong.js new file mode 100644 index 000000000..694921298 --- /dev/null +++ b/es/lib/isLatLong.js @@ -0,0 +1,9 @@ +import assertString from './util/assertString'; +var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; +var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; +export default function (str) { + assertString(str); + if (!str.includes(',')) return false; + var pair = str.split(','); + return lat.test(pair[0]) && _long.test(pair[1]); +} \ No newline at end of file diff --git a/es/lib/isLength.js b/es/lib/isLength.js new file mode 100644 index 000000000..a6b63c737 --- /dev/null +++ b/es/lib/isLength.js @@ -0,0 +1,23 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +import assertString from './util/assertString'; +/* eslint-disable prefer-rest-params */ + +export default function isLength(str, options) { + assertString(str); + var min; + var max; + + if (_typeof(options) === 'object') { + min = options.min || 0; + max = options.max; + } else { + // backwards compatibility: isLength(str, min [, max]) + min = arguments[1]; + max = arguments[2]; + } + + var surrogatePairs = str.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g) || []; + var len = str.length - surrogatePairs.length; + return len >= min && (typeof max === 'undefined' || len <= max); +} \ No newline at end of file diff --git a/es/lib/isLowercase.js b/es/lib/isLowercase.js new file mode 100644 index 000000000..034785646 --- /dev/null +++ b/es/lib/isLowercase.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function isLowercase(str) { + assertString(str); + return str === str.toLowerCase(); +} \ No newline at end of file diff --git a/es/lib/isMACAddress.js b/es/lib/isMACAddress.js new file mode 100644 index 000000000..bedc25cc3 --- /dev/null +++ b/es/lib/isMACAddress.js @@ -0,0 +1,12 @@ +import assertString from './util/assertString'; +var macAddress = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/; +var macAddressNoColons = /^([0-9a-fA-F]){12}$/; +export default function isMACAddress(str, options) { + assertString(str); + + if (options && options.no_colons) { + return macAddressNoColons.test(str); + } + + return macAddress.test(str); +} \ No newline at end of file diff --git a/es/lib/isMD5.js b/es/lib/isMD5.js new file mode 100644 index 000000000..701ed7b34 --- /dev/null +++ b/es/lib/isMD5.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +var md5 = /^[a-f0-9]{32}$/; +export default function isMD5(str) { + assertString(str); + return md5.test(str); +} \ No newline at end of file diff --git a/es/lib/isMagnetURI.js b/es/lib/isMagnetURI.js new file mode 100644 index 000000000..e34166584 --- /dev/null +++ b/es/lib/isMagnetURI.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +var magnetURI = /^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i; +export default function isMagnetURI(url) { + assertString(url); + return magnetURI.test(url.trim()); +} \ No newline at end of file diff --git a/es/lib/isMimeType.js b/es/lib/isMimeType.js new file mode 100644 index 000000000..cddaf00a9 --- /dev/null +++ b/es/lib/isMimeType.js @@ -0,0 +1,39 @@ +import assertString from './util/assertString'; +/* + Checks if the provided string matches to a correct Media type format (MIME type) + + This function only checks is the string format follows the + etablished rules by the according RFC specifications. + This function supports 'charset' in textual media types + (https://tools.ietf.org/html/rfc6657). + + This function does not check against all the media types listed + by the IANA (https://www.iana.org/assignments/media-types/media-types.xhtml) + because of lightness purposes : it would require to include + all these MIME types in this librairy, which would weigh it + significantly. This kind of effort maybe is not worth for the use that + this function has in this entire librairy. + + More informations in the RFC specifications : + - https://tools.ietf.org/html/rfc2045 + - https://tools.ietf.org/html/rfc2046 + - https://tools.ietf.org/html/rfc7231#section-3.1.1.1 + - https://tools.ietf.org/html/rfc7231#section-3.1.1.5 +*/ +// Match simple MIME types +// NB : +// Subtype length must not exceed 100 characters. +// This rule does not comply to the RFC specs (what is the max length ?). + +var mimeTypeSimple = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i; // eslint-disable-line max-len +// Handle "charset" in "text/*" + +var mimeTypeText = /^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i; // eslint-disable-line max-len +// Handle "boundary" in "multipart/*" + +var mimeTypeMultipart = /^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i; // eslint-disable-line max-len + +export default function isMimeType(str) { + assertString(str); + return mimeTypeSimple.test(str) || mimeTypeText.test(str) || mimeTypeMultipart.test(str); +} \ No newline at end of file diff --git a/es/lib/isMobilePhone.js b/es/lib/isMobilePhone.js new file mode 100644 index 000000000..6f11c0ea2 --- /dev/null +++ b/es/lib/isMobilePhone.js @@ -0,0 +1,119 @@ +import assertString from './util/assertString'; +/* eslint-disable max-len */ + +var phones = { + 'ar-AE': /^((\+?971)|0)?5[024568]\d{7}$/, + 'ar-DZ': /^(\+?213|0)(5|6|7)\d{8}$/, + 'ar-EG': /^((\+?20)|0)?1[012]\d{8}$/, + 'ar-IQ': /^(\+?964|0)?7[0-9]\d{8}$/, + 'ar-JO': /^(\+?962|0)?7[789]\d{7}$/, + 'ar-KW': /^(\+?965)[569]\d{7}$/, + 'ar-SA': /^(!?(\+?966)|0)?5\d{8}$/, + 'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/, + 'ar-TN': /^(\+?216)?[2459]\d{7}$/, + 'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/, + 'bg-BG': /^(\+?359|0)?8[789]\d{7}$/, + 'bn-BD': /\+?(88)?0?1[356789][0-9]{8}\b/, + 'cs-CZ': /^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, + 'da-DK': /^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'de-DE': /^(\+49)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/, + 'el-GR': /^(\+?30|0)?(69\d{8})$/, + 'en-AU': /^(\+?61|0)4\d{8}$/, + 'en-GB': /^(\+?44|0)7\d{9}$/, + 'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/, + 'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/, + 'en-IE': /^(\+?353|0)8[356789]\d{7}$/, + 'en-IN': /^(\+?91|0)?[6789]\d{9}$/, + 'en-KE': /^(\+?254|0)?[7]\d{8}$/, + 'en-MU': /^(\+?230|0)?\d{8}$/, + 'en-NG': /^(\+?234|0)?[789]\d{9}$/, + 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/, + 'en-PK': /^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/, + 'en-RW': /^(\+?250|0)?[7]\d{8}$/, + 'en-SG': /^(\+65)?[89]\d{7}$/, + 'en-TZ': /^(\+?255|0)?[67]\d{8}$/, + 'en-UG': /^(\+?256|0)?[7]\d{8}$/, + 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/, + 'en-ZA': /^(\+?27|0)\d{9}$/, + 'en-ZM': /^(\+?26)?09[567]\d{7}$/, + 'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/, + 'es-MX': /^(\+?52)?(1|01)?\d{10,11}$/, + 'es-UY': /^(\+598|0)9[1-9][\d]{6}$/, + 'et-EE': /^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/, + 'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/, + 'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/, + 'fo-FO': /^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'fr-FR': /^(\+?33|0)[67]\d{8}$/, + 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/, + 'hu-HU': /^(\+?36)(20|30|70)\d{7}$/, + 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/, + 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/, + 'ja-JP': /^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/, + 'kk-KZ': /^(\+?7|8)?7\d{9}$/, + 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/, + 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/, + 'lt-LT': /^(\+370|8)\d{8}$/, + 'ms-MY': /^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/, + 'nb-NO': /^(\+?47)?[49]\d{7}$/, + 'nl-BE': /^(\+?32|0)4?\d{8}$/, + 'nn-NO': /^(\+?47)?[49]\d{7}$/, + 'pl-PL': /^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/, + 'pt-BR': /(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/, + 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, + 'ro-RO': /^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/, + 'ru-RU': /^(\+?7|8)?9\d{9}$/, + 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/, + 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, + 'sr-RS': /^(\+3816|06)[- \d]{5,9}$/, + 'sv-SE': /^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/, + 'th-TH': /^(\+66|66|0)\d{9}$/, + 'tr-TR': /^(\+?90|0)?5\d{9}$/, + 'uk-UA': /^(\+?38|8)?0\d{9}$/, + 'vi-VN': /^(\+?84|0)((3([2-9]))|(5([689]))|(7([0|6-9]))|(8([1-5]))|(9([0-9])))([0-9]{7})$/, + 'zh-CN': /^((\+|00)86)?1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/, + 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/ +}; +/* eslint-enable max-len */ +// aliases + +phones['en-CA'] = phones['en-US']; +phones['fr-BE'] = phones['nl-BE']; +phones['zh-HK'] = phones['en-HK']; +export default function isMobilePhone(str, locale, options) { + assertString(str); + + if (options && options.strictMode && !str.startsWith('+')) { + return false; + } + + if (Array.isArray(locale)) { + return locale.some(function (key) { + if (phones.hasOwnProperty(key)) { + var phone = phones[key]; + + if (phone.test(str)) { + return true; + } + } + + return false; + }); + } else if (locale in phones) { + return phones[locale].test(str); // alias falsey locale as 'any' + } else if (!locale || locale === 'any') { + for (var key in phones) { + if (phones.hasOwnProperty(key)) { + var phone = phones[key]; + + if (phone.test(str)) { + return true; + } + } + } + + return false; + } + + throw new Error("Invalid locale '".concat(locale, "'")); +} +export var locales = Object.keys(phones); \ No newline at end of file diff --git a/es/lib/isMongoId.js b/es/lib/isMongoId.js new file mode 100644 index 000000000..fc87b89e4 --- /dev/null +++ b/es/lib/isMongoId.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +import isHexadecimal from './isHexadecimal'; +export default function isMongoId(str) { + assertString(str); + return isHexadecimal(str) && str.length === 24; +} \ No newline at end of file diff --git a/es/lib/isMultibyte.js b/es/lib/isMultibyte.js new file mode 100644 index 000000000..7a13857fb --- /dev/null +++ b/es/lib/isMultibyte.js @@ -0,0 +1,10 @@ +import assertString from './util/assertString'; +/* eslint-disable no-control-regex */ + +var multibyte = /[^\x00-\x7F]/; +/* eslint-enable no-control-regex */ + +export default function isMultibyte(str) { + assertString(str); + return multibyte.test(str); +} \ No newline at end of file diff --git a/es/lib/isNumeric.js b/es/lib/isNumeric.js new file mode 100644 index 000000000..b87bfad1a --- /dev/null +++ b/es/lib/isNumeric.js @@ -0,0 +1,12 @@ +import assertString from './util/assertString'; +var numeric = /^[+-]?([0-9]*[.])?[0-9]+$/; +var numericNoSymbols = /^[0-9]+$/; +export default function isNumeric(str, options) { + assertString(str); + + if (options && options.no_symbols) { + return numericNoSymbols.test(str); + } + + return numeric.test(str); +} \ No newline at end of file diff --git a/es/lib/isPort.js b/es/lib/isPort.js new file mode 100644 index 000000000..6490cad21 --- /dev/null +++ b/es/lib/isPort.js @@ -0,0 +1,7 @@ +import isInt from './isInt'; +export default function isPort(str) { + return isInt(str, { + min: 0, + max: 65535 + }); +} \ No newline at end of file diff --git a/es/lib/isPostalCode.js b/es/lib/isPostalCode.js new file mode 100644 index 000000000..278980cec --- /dev/null +++ b/es/lib/isPostalCode.js @@ -0,0 +1,76 @@ +import assertString from './util/assertString'; // common patterns + +var threeDigit = /^\d{3}$/; +var fourDigit = /^\d{4}$/; +var fiveDigit = /^\d{5}$/; +var sixDigit = /^\d{6}$/; +var patterns = { + AD: /^AD\d{3}$/, + AT: fourDigit, + AU: fourDigit, + BE: fourDigit, + BG: fourDigit, + CA: /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i, + CH: fourDigit, + CZ: /^\d{3}\s?\d{2}$/, + DE: fiveDigit, + DK: fourDigit, + DZ: fiveDigit, + EE: fiveDigit, + ES: fiveDigit, + FI: fiveDigit, + FR: /^\d{2}\s?\d{3}$/, + GB: /^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i, + GR: /^\d{3}\s?\d{2}$/, + HR: /^([1-5]\d{4}$)/, + HU: fourDigit, + IL: fiveDigit, + IN: sixDigit, + IS: threeDigit, + IT: fiveDigit, + JP: /^\d{3}\-\d{4}$/, + KE: fiveDigit, + LI: /^(948[5-9]|949[0-7])$/, + LT: /^LT\-\d{5}$/, + LU: fourDigit, + LV: /^LV\-\d{4}$/, + MX: fiveDigit, + NL: /^\d{4}\s?[a-z]{2}$/i, + NO: fourDigit, + PL: /^\d{2}\-\d{3}$/, + PT: /^\d{4}\-\d{3}?$/, + RO: sixDigit, + RU: sixDigit, + SA: fiveDigit, + SE: /^\d{3}\s?\d{2}$/, + SI: fourDigit, + SK: /^\d{3}\s?\d{2}$/, + TN: fourDigit, + TW: /^\d{3}(\d{2})?$/, + UA: fiveDigit, + US: /^\d{5}(-\d{4})?$/, + ZA: fourDigit, + ZM: fiveDigit +}; +export var locales = Object.keys(patterns); +export default function (str, locale) { + assertString(str); + + if (locale in patterns) { + return patterns[locale].test(str); + } else if (locale === 'any') { + for (var key in patterns) { + if (patterns.hasOwnProperty(key)) { + var pattern = patterns[key]; + + if (pattern.test(str)) { + return true; + } + } + } + + return false; + } + + throw new Error("Invalid locale '".concat(locale, "'")); +} \ No newline at end of file diff --git a/es/lib/isRFC3339.js b/es/lib/isRFC3339.js new file mode 100644 index 000000000..8357ecbfa --- /dev/null +++ b/es/lib/isRFC3339.js @@ -0,0 +1,20 @@ +import assertString from './util/assertString'; +/* Based on https://tools.ietf.org/html/rfc3339#section-5.6 */ + +var dateFullYear = /[0-9]{4}/; +var dateMonth = /(0[1-9]|1[0-2])/; +var dateMDay = /([12]\d|0[1-9]|3[01])/; +var timeHour = /([01][0-9]|2[0-3])/; +var timeMinute = /[0-5][0-9]/; +var timeSecond = /([0-5][0-9]|60)/; +var timeSecFrac = /(\.[0-9]+)?/; +var timeNumOffset = new RegExp("[-+]".concat(timeHour.source, ":").concat(timeMinute.source)); +var timeOffset = new RegExp("([zZ]|".concat(timeNumOffset.source, ")")); +var partialTime = new RegExp("".concat(timeHour.source, ":").concat(timeMinute.source, ":").concat(timeSecond.source).concat(timeSecFrac.source)); +var fullDate = new RegExp("".concat(dateFullYear.source, "-").concat(dateMonth.source, "-").concat(dateMDay.source)); +var fullTime = new RegExp("".concat(partialTime.source).concat(timeOffset.source)); +var rfc3339 = new RegExp("".concat(fullDate.source, "[ tT]").concat(fullTime.source)); +export default function isRFC3339(str) { + assertString(str); + return rfc3339.test(str); +} \ No newline at end of file diff --git a/es/lib/isSurrogatePair.js b/es/lib/isSurrogatePair.js new file mode 100644 index 000000000..1e0efb2f8 --- /dev/null +++ b/es/lib/isSurrogatePair.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +var surrogatePair = /[\uD800-\uDBFF][\uDC00-\uDFFF]/; +export default function isSurrogatePair(str) { + assertString(str); + return surrogatePair.test(str); +} \ No newline at end of file diff --git a/es/lib/isURL.js b/es/lib/isURL.js new file mode 100644 index 000000000..d4ff49e30 --- /dev/null +++ b/es/lib/isURL.js @@ -0,0 +1,136 @@ +import assertString from './util/assertString'; +import isFQDN from './isFQDN'; +import isIP from './isIP'; +import merge from './util/merge'; +var default_url_options = { + protocols: ['http', 'https', 'ftp'], + require_tld: true, + require_protocol: false, + require_host: true, + require_valid_protocol: true, + allow_underscores: false, + allow_trailing_dot: false, + allow_protocol_relative_urls: false +}; +var wrapped_ipv6 = /^\[([^\]]+)\](?::([0-9]+))?$/; + +function isRegExp(obj) { + return Object.prototype.toString.call(obj) === '[object RegExp]'; +} + +function checkHost(host, matches) { + for (var i = 0; i < matches.length; i++) { + var match = matches[i]; + + if (host === match || isRegExp(match) && match.test(host)) { + return true; + } + } + + return false; +} + +export default function isURL(url, options) { + assertString(url); + + if (!url || url.length >= 2083 || /[\s<>]/.test(url)) { + return false; + } + + if (url.indexOf('mailto:') === 0) { + return false; + } + + options = merge(options, default_url_options); + var protocol, auth, host, hostname, port, port_str, split, ipv6; + split = url.split('#'); + url = split.shift(); + split = url.split('?'); + url = split.shift(); + split = url.split('://'); + + if (split.length > 1) { + protocol = split.shift().toLowerCase(); + + if (options.require_valid_protocol && options.protocols.indexOf(protocol) === -1) { + return false; + } + } else if (options.require_protocol) { + return false; + } else if (url.substr(0, 2) === '//') { + if (!options.allow_protocol_relative_urls) { + return false; + } + + split[0] = url.substr(2); + } + + url = split.join('://'); + + if (url === '') { + return false; + } + + split = url.split('/'); + url = split.shift(); + + if (url === '' && !options.require_host) { + return true; + } + + split = url.split('@'); + + if (split.length > 1) { + if (options.disallow_auth) { + return false; + } + + auth = split.shift(); + + if (auth.indexOf(':') >= 0 && auth.split(':').length > 2) { + return false; + } + } + + hostname = split.join('@'); + port_str = null; + ipv6 = null; + var ipv6_match = hostname.match(wrapped_ipv6); + + if (ipv6_match) { + host = ''; + ipv6 = ipv6_match[1]; + port_str = ipv6_match[2] || null; + } else { + split = hostname.split(':'); + host = split.shift(); + + if (split.length) { + port_str = split.join(':'); + } + } + + if (port_str !== null) { + port = parseInt(port_str, 10); + + if (!/^[0-9]+$/.test(port_str) || port <= 0 || port > 65535) { + return false; + } + } + + if (!isIP(host) && !isFQDN(host, options) && (!ipv6 || !isIP(ipv6, 6))) { + return false; + } + + host = host || ipv6; + + if (options.host_whitelist && !checkHost(host, options.host_whitelist)) { + return false; + } + + if (options.host_blacklist && checkHost(host, options.host_blacklist)) { + return false; + } + + return true; +} \ No newline at end of file diff --git a/es/lib/isUUID.js b/es/lib/isUUID.js new file mode 100644 index 000000000..04de3ee01 --- /dev/null +++ b/es/lib/isUUID.js @@ -0,0 +1,13 @@ +import assertString from './util/assertString'; +var uuid = { + 3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + 4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + 5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i +}; +export default function isUUID(str) { + var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; + assertString(str); + var pattern = uuid[version]; + return pattern && pattern.test(str); +} \ No newline at end of file diff --git a/es/lib/isUppercase.js b/es/lib/isUppercase.js new file mode 100644 index 000000000..fca87907e --- /dev/null +++ b/es/lib/isUppercase.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function isUppercase(str) { + assertString(str); + return str === str.toUpperCase(); +} \ No newline at end of file diff --git a/es/lib/isVariableWidth.js b/es/lib/isVariableWidth.js new file mode 100644 index 000000000..890119ea3 --- /dev/null +++ b/es/lib/isVariableWidth.js @@ -0,0 +1,7 @@ +import assertString from './util/assertString'; +import { fullWidth } from './isFullWidth'; +import { halfWidth } from './isHalfWidth'; +export default function isVariableWidth(str) { + assertString(str); + return fullWidth.test(str) && halfWidth.test(str); +} \ No newline at end of file diff --git a/es/lib/isWhitelisted.js b/es/lib/isWhitelisted.js new file mode 100644 index 000000000..2cbb95cec --- /dev/null +++ b/es/lib/isWhitelisted.js @@ -0,0 +1,12 @@ +import assertString from './util/assertString'; +export default function isWhitelisted(str, chars) { + assertString(str); + + for (var i = str.length - 1; i >= 0; i--) { + if (chars.indexOf(str[i]) === -1) { + return false; + } + } + + return true; +} \ No newline at end of file diff --git a/es/lib/ltrim.js b/es/lib/ltrim.js new file mode 100644 index 000000000..f11997d2a --- /dev/null +++ b/es/lib/ltrim.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +export default function ltrim(str, chars) { + assertString(str); + var pattern = chars ? new RegExp("^[".concat(chars, "]+"), 'g') : /^\s+/g; + return str.replace(pattern, ''); +} \ No newline at end of file diff --git a/es/lib/matches.js b/es/lib/matches.js new file mode 100644 index 000000000..7840b1c4a --- /dev/null +++ b/es/lib/matches.js @@ -0,0 +1,10 @@ +import assertString from './util/assertString'; +export default function matches(str, pattern, modifiers) { + assertString(str); + + if (Object.prototype.toString.call(pattern) !== '[object RegExp]') { + pattern = new RegExp(pattern, modifiers); + } + + return pattern.test(str); +} \ No newline at end of file diff --git a/es/lib/normalizeEmail.js b/es/lib/normalizeEmail.js new file mode 100644 index 000000000..301df8311 --- /dev/null +++ b/es/lib/normalizeEmail.js @@ -0,0 +1,138 @@ +import merge from './util/merge'; +var default_normalize_email_options = { + // The following options apply to all email addresses + // Lowercases the local part of the email address. + // Please note this may violate RFC 5321 as per http://stackoverflow.com/a/9808332/192024). + // The domain is always lowercased, as per RFC 1035 + all_lowercase: true, + // The following conversions are specific to GMail + // Lowercases the local part of the GMail address (known to be case-insensitive) + gmail_lowercase: true, + // Removes dots from the local part of the email address, as that's ignored by GMail + gmail_remove_dots: true, + // Removes the subaddress (e.g. "+foo") from the email address + gmail_remove_subaddress: true, + // Conversts the googlemail.com domain to gmail.com + gmail_convert_googlemaildotcom: true, + // The following conversions are specific to Outlook.com / Windows Live / Hotmail + // Lowercases the local part of the Outlook.com address (known to be case-insensitive) + outlookdotcom_lowercase: true, + // Removes the subaddress (e.g. "+foo") from the email address + outlookdotcom_remove_subaddress: true, + // The following conversions are specific to Yahoo + // Lowercases the local part of the Yahoo address (known to be case-insensitive) + yahoo_lowercase: true, + // Removes the subaddress (e.g. "-foo") from the email address + yahoo_remove_subaddress: true, + // The following conversions are specific to Yandex + // Lowercases the local part of the Yandex address (known to be case-insensitive) + yandex_lowercase: true, + // The following conversions are specific to iCloud + // Lowercases the local part of the iCloud address (known to be case-insensitive) + icloud_lowercase: true, + // Removes the subaddress (e.g. "+foo") from the email address + icloud_remove_subaddress: true +}; // List of domains used by iCloud + +var icloud_domains = ['icloud.com', 'me.com']; // List of domains used by Outlook.com and its predecessors +// This list is likely incomplete. +// Partial reference: +// https://blogs.office.com/2013/04/17/outlook-com-gets-two-step-verification-sign-in-by-alias-and-new-international-domains/ + +var outlookdotcom_domains = ['hotmail.at', 'hotmail.be', 'hotmail.ca', 'hotmail.cl', 'hotmail.co.il', 'hotmail.co.nz', 'hotmail.co.th', 'hotmail.co.uk', 'hotmail.com', 'hotmail.com.ar', 'hotmail.com.au', 'hotmail.com.br', 'hotmail.com.gr', 'hotmail.com.mx', 'hotmail.com.pe', 'hotmail.com.tr', 'hotmail.com.vn', 'hotmail.cz', 'hotmail.de', 'hotmail.dk', 'hotmail.es', 'hotmail.fr', 'hotmail.hu', 'hotmail.id', 'hotmail.ie', 'hotmail.in', 'hotmail.it', 'hotmail.jp', 'hotmail.kr', 'hotmail.lv', 'hotmail.my', 'hotmail.ph', 'hotmail.pt', 'hotmail.sa', 'hotmail.sg', 'hotmail.sk', 'live.be', 'live.co.uk', 'live.com', 'live.com.ar', 'live.com.mx', 'live.de', 'live.es', 'live.eu', 'live.fr', 'live.it', 'live.nl', 'msn.com', 'outlook.at', 'outlook.be', 'outlook.cl', 'outlook.co.il', 'outlook.co.nz', 'outlook.co.th', 'outlook.com', 'outlook.com.ar', 'outlook.com.au', 'outlook.com.br', 'outlook.com.gr', 'outlook.com.pe', 'outlook.com.tr', 'outlook.com.vn', 'outlook.cz', 'outlook.de', 'outlook.dk', 'outlook.es', 'outlook.fr', 'outlook.hu', 'outlook.id', 'outlook.ie', 'outlook.in', 'outlook.it', 'outlook.jp', 'outlook.kr', 'outlook.lv', 'outlook.my', 'outlook.ph', 'outlook.pt', 'outlook.sa', 'outlook.sg', 'outlook.sk', 'passport.com']; // List of domains used by Yahoo Mail +// This list is likely incomplete + +var yahoo_domains = ['rocketmail.com', 'yahoo.ca', 'yahoo.co.uk', 'yahoo.com', 'yahoo.de', 'yahoo.fr', 'yahoo.in', 'yahoo.it', 'ymail.com']; // List of domains used by yandex.ru + +var yandex_domains = ['yandex.ru', 'yandex.ua', 'yandex.kz', 'yandex.com', 'yandex.by', 'ya.ru']; // replace single dots, but not multiple consecutive dots + +function dotsReplacer(match) { + if (match.length > 1) { + return match; + } + + return ''; +} + +export default function normalizeEmail(email, options) { + options = merge(options, default_normalize_email_options); + var raw_parts = email.split('@'); + var domain = raw_parts.pop(); + var user = raw_parts.join('@'); + var parts = [user, domain]; // The domain is always lowercased, as it's case-insensitive per RFC 1035 + + parts[1] = parts[1].toLowerCase(); + + if (parts[1] === 'gmail.com' || parts[1] === 'googlemail.com') { + // Address is GMail + if (options.gmail_remove_subaddress) { + parts[0] = parts[0].split('+')[0]; + } + + if (options.gmail_remove_dots) { + // this does not replace consecutive dots like example..email@gmail.com + parts[0] = parts[0].replace(/\.+/g, dotsReplacer); + } + + if (!parts[0].length) { + return false; + } + + if (options.all_lowercase || options.gmail_lowercase) { + parts[0] = parts[0].toLowerCase(); + } + + parts[1] = options.gmail_convert_googlemaildotcom ? 'gmail.com' : parts[1]; + } else if (icloud_domains.indexOf(parts[1]) >= 0) { + // Address is iCloud + if (options.icloud_remove_subaddress) { + parts[0] = parts[0].split('+')[0]; + } + + if (!parts[0].length) { + return false; + } + + if (options.all_lowercase || options.icloud_lowercase) { + parts[0] = parts[0].toLowerCase(); + } + } else if (outlookdotcom_domains.indexOf(parts[1]) >= 0) { + // Address is Outlook.com + if (options.outlookdotcom_remove_subaddress) { + parts[0] = parts[0].split('+')[0]; + } + + if (!parts[0].length) { + return false; + } + + if (options.all_lowercase || options.outlookdotcom_lowercase) { + parts[0] = parts[0].toLowerCase(); + } + } else if (yahoo_domains.indexOf(parts[1]) >= 0) { + // Address is Yahoo + if (options.yahoo_remove_subaddress) { + var components = parts[0].split('-'); + parts[0] = components.length > 1 ? components.slice(0, -1).join('-') : components[0]; + } + + if (!parts[0].length) { + return false; + } + + if (options.all_lowercase || options.yahoo_lowercase) { + parts[0] = parts[0].toLowerCase(); + } + } else if (yandex_domains.indexOf(parts[1]) >= 0) { + if (options.all_lowercase || options.yandex_lowercase) { + parts[0] = parts[0].toLowerCase(); + } + + parts[1] = 'yandex.ru'; // all yandex domains are equal, 1st preffered + } else if (options.all_lowercase) { + // Any other address + parts[0] = parts[0].toLowerCase(); + } + + return parts.join('@'); +} \ No newline at end of file diff --git a/es/lib/rtrim.js b/es/lib/rtrim.js new file mode 100644 index 000000000..984ac71e7 --- /dev/null +++ b/es/lib/rtrim.js @@ -0,0 +1,12 @@ +import assertString from './util/assertString'; +export default function rtrim(str, chars) { + assertString(str); + var pattern = chars ? new RegExp("[".concat(chars, "]")) : /\s/; + var idx = str.length - 1; + + for (; idx >= 0 && pattern.test(str[idx]); idx--) { + ; + } + + return idx < str.length ? str.substr(0, idx + 1) : str; +} \ No newline at end of file diff --git a/es/lib/stripLow.js b/es/lib/stripLow.js new file mode 100644 index 000000000..c79842551 --- /dev/null +++ b/es/lib/stripLow.js @@ -0,0 +1,7 @@ +import assertString from './util/assertString'; +import blacklist from './blacklist'; +export default function stripLow(str, keep_new_lines) { + assertString(str); + var chars = keep_new_lines ? '\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F' : '\\x00-\\x1F\\x7F'; + return blacklist(str, chars); +} \ No newline at end of file diff --git a/es/lib/toBoolean.js b/es/lib/toBoolean.js new file mode 100644 index 000000000..06111ad22 --- /dev/null +++ b/es/lib/toBoolean.js @@ -0,0 +1,10 @@ +import assertString from './util/assertString'; +export default function toBoolean(str, strict) { + assertString(str); + + if (strict) { + return str === '1' || str === 'true'; + } + + return str !== '0' && str !== 'false' && str !== ''; +} \ No newline at end of file diff --git a/es/lib/toDate.js b/es/lib/toDate.js new file mode 100644 index 000000000..62422a317 --- /dev/null +++ b/es/lib/toDate.js @@ -0,0 +1,6 @@ +import assertString from './util/assertString'; +export default function toDate(date) { + assertString(date); + date = Date.parse(date); + return !isNaN(date) ? new Date(date) : null; +} \ No newline at end of file diff --git a/es/lib/toFloat.js b/es/lib/toFloat.js new file mode 100644 index 000000000..30e637897 --- /dev/null +++ b/es/lib/toFloat.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function toFloat(str) { + assertString(str); + return parseFloat(str); +} \ No newline at end of file diff --git a/es/lib/toInt.js b/es/lib/toInt.js new file mode 100644 index 000000000..22d566e74 --- /dev/null +++ b/es/lib/toInt.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function toInt(str, radix) { + assertString(str); + return parseInt(str, radix || 10); +} \ No newline at end of file diff --git a/es/lib/trim.js b/es/lib/trim.js new file mode 100644 index 000000000..b9b8fa0dd --- /dev/null +++ b/es/lib/trim.js @@ -0,0 +1,5 @@ +import rtrim from './rtrim'; +import ltrim from './ltrim'; +export default function trim(str, chars) { + return rtrim(ltrim(str, chars), chars); +} \ No newline at end of file diff --git a/es/lib/unescape.js b/es/lib/unescape.js new file mode 100644 index 000000000..d6c807754 --- /dev/null +++ b/es/lib/unescape.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function unescape(str) { + assertString(str); + return str.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, "'").replace(/</g, '<').replace(/>/g, '>').replace(///g, '/').replace(/\/g, '\\').replace(/`/g, '`'); +} \ No newline at end of file diff --git a/es/lib/util/assertString.js b/es/lib/util/assertString.js new file mode 100644 index 000000000..cd3f302f5 --- /dev/null +++ b/es/lib/util/assertString.js @@ -0,0 +1,23 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +export default function assertString(input) { + var isString = typeof input === 'string' || input instanceof String; + + if (!isString) { + var invalidType; + + if (input === null) { + invalidType = 'null'; + } else { + invalidType = _typeof(input); + + if (invalidType === 'object' && input.constructor && input.constructor.hasOwnProperty('name')) { + invalidType = input.constructor.name; + } else { + invalidType = "a ".concat(invalidType); + } + } + + throw new TypeError("Expected string but received ".concat(invalidType, ".")); + } +} \ No newline at end of file diff --git a/es/lib/util/includes.js b/es/lib/util/includes.js new file mode 100644 index 000000000..b01c69244 --- /dev/null +++ b/es/lib/util/includes.js @@ -0,0 +1,7 @@ +var includes = function includes(arr, val) { + return arr.some(function (arrVal) { + return val === arrVal; + }); +}; + +export default includes; \ No newline at end of file diff --git a/es/lib/util/merge.js b/es/lib/util/merge.js new file mode 100644 index 000000000..0d1f6997d --- /dev/null +++ b/es/lib/util/merge.js @@ -0,0 +1,12 @@ +export default function merge() { + var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var defaults = arguments.length > 1 ? arguments[1] : undefined; + + for (var key in defaults) { + if (typeof obj[key] === 'undefined') { + obj[key] = defaults[key]; + } + } + + return obj; +} \ No newline at end of file diff --git a/es/lib/util/toString.js b/es/lib/util/toString.js new file mode 100644 index 000000000..8f5167576 --- /dev/null +++ b/es/lib/util/toString.js @@ -0,0 +1,15 @@ +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } + +export default function toString(input) { + if (_typeof(input) === 'object' && input !== null) { + if (typeof input.toString === 'function') { + input = input.toString(); + } else { + input = '[object Object]'; + } + } else if (input === null || typeof input === 'undefined' || isNaN(input) && !input.length) { + input = ''; + } + + return String(input); +} \ No newline at end of file diff --git a/es/lib/whitelist.js b/es/lib/whitelist.js new file mode 100644 index 000000000..244881b41 --- /dev/null +++ b/es/lib/whitelist.js @@ -0,0 +1,5 @@ +import assertString from './util/assertString'; +export default function whitelist(str, chars) { + assertString(str); + return str.replace(new RegExp("[^".concat(chars, "]+"), 'g'), ''); +} \ No newline at end of file diff --git a/package.json b/package.json index 4cca07cad..e3191d4a7 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "homepage": "https://github.com/chriso/validator.js", "files": [ "index.js", + "es", "lib", "README.md", "LICENCE", @@ -54,12 +55,14 @@ "lint": "eslint src test", "lint:fix": "eslint --fix src test", "clean:node": "rm -rf index.js lib", + "clean:es": "rm -rf es", "clean:browser": "rm -rf validator*.js", - "clean": "npm run clean:node && npm run clean:browser", + "clean": "npm run clean:node && npm run clean:browser && npm run clean:es", "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", "build:browser": "node --require @babel/register build-browser && npm run minify", + "build:es": "babel src -d es --env-name=es", "build:node": "babel src -d .", - "build": "npm run build:browser && npm run build:node", + "build": "npm run build:browser && npm run build:node && npm run build:es", "pretest": "npm run lint && npm run build", "test": "mocha --require @babel/register --reporter dot" }, diff --git a/validator.js b/validator.js index 7a32e3bb2..c7c6c9c10 100644 --- a/validator.js +++ b/validator.js @@ -40,191 +40,6 @@ function _typeof(obj) { return _typeof(obj); } -function _toArray(arr) { - return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest(); -} - -function _arrayWithHoles(arr) { - if (Array.isArray(arr)) return arr; -} - -function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); -} - -function _nonIterableRest() { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); -} - -function _toPrimitive(input, hint) { - if (typeof input !== "object" || input === null) return input; - var prim = input[Symbol.toPrimitive]; - - if (prim !== undefined) { - var res = prim.call(input, hint || "default"); - if (typeof res !== "object") return res; - throw new TypeError("@@toPrimitive must return a primitive value."); - } - - return (hint === "string" ? String : Number)(input); -} - -function _toPropertyKey(arg) { - var key = _toPrimitive(arg, "string"); - - return typeof key === "symbol" ? key : String(key); -} - -function _addElementPlacement(element, placements, silent) { - var keys = placements[element.placement]; - - if (!silent && keys.indexOf(element.key) !== -1) { - throw new TypeError("Duplicated element (" + element.key + ")"); - } - - keys.push(element.key); -} - -function _fromElementDescriptor(element) { - var obj = { - kind: element.kind, - key: element.key, - placement: element.placement, - descriptor: element.descriptor - }; - var desc = { - value: "Descriptor", - configurable: true - }; - Object.defineProperty(obj, Symbol.toStringTag, desc); - if (element.kind === "field") obj.initializer = element.initializer; - return obj; -} - -function _toElementDescriptors(elementObjects) { - if (elementObjects === undefined) return; - return _toArray(elementObjects).map(function (elementObject) { - var element = _toElementDescriptor(elementObject); - - _disallowProperty(elementObject, "finisher", "An element descriptor"); - - _disallowProperty(elementObject, "extras", "An element descriptor"); - - return element; - }); -} - -function _toElementDescriptor(elementObject) { - var kind = String(elementObject.kind); - - if (kind !== "method" && kind !== "field") { - throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"'); - } - - var key = _toPropertyKey(elementObject.key); - - var placement = String(elementObject.placement); - - if (placement !== "static" && placement !== "prototype" && placement !== "own") { - throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"'); - } - - var descriptor = elementObject.descriptor; - - _disallowProperty(elementObject, "elements", "An element descriptor"); - - var element = { - kind: kind, - key: key, - placement: placement, - descriptor: Object.assign({}, descriptor) - }; - - if (kind !== "field") { - _disallowProperty(elementObject, "initializer", "A method descriptor"); - } else { - _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor"); - - _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor"); - - _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor"); - - element.initializer = elementObject.initializer; - } - - return element; -} - -function _toElementFinisherExtras(elementObject) { - var element = _toElementDescriptor(elementObject); - - var finisher = _optionalCallableProperty(elementObject, "finisher"); - - var extras = _toElementDescriptors(elementObject.extras); - - return { - element: element, - finisher: finisher, - extras: extras - }; -} - -function _fromClassDescriptor(elements) { - var obj = { - kind: "class", - elements: elements.map(_fromElementDescriptor) - }; - var desc = { - value: "Descriptor", - configurable: true - }; - Object.defineProperty(obj, Symbol.toStringTag, desc); - return obj; -} - -function _toClassDescriptor(obj) { - var kind = String(obj.kind); - - if (kind !== "class") { - throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"'); - } - - _disallowProperty(obj, "key", "A class descriptor"); - - _disallowProperty(obj, "placement", "A class descriptor"); - - _disallowProperty(obj, "descriptor", "A class descriptor"); - - _disallowProperty(obj, "initializer", "A class descriptor"); - - _disallowProperty(obj, "extras", "A class descriptor"); - - var finisher = _optionalCallableProperty(obj, "finisher"); - - var elements = _toElementDescriptors(obj.elements); - - return { - elements: elements, - finisher: finisher - }; -} - -function _disallowProperty(obj, name, objectType) { - if (obj[name] !== undefined) { - throw new TypeError(objectType + " can't have a ." + name + " property."); - } -} - -function _optionalCallableProperty(obj, name) { - var value = obj[name]; - - if (value !== undefined && typeof value !== "function") { - throw new TypeError("Expected '" + name + "' to be a function"); - } - - return value; -} - function assertString(input) { var isString = typeof input === 'string' || input instanceof String; @@ -887,14 +702,14 @@ function isNumeric(str, options) { return numeric.test(str); } -var int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/; +var _int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/; var intLeadingZeroes = /^[-+]?[0-9]+$/; function isInt(str, options) { assertString(str); options = options || {}; // Get the regex to use for testing, based on whether // leading zeroes are allowed or not. - var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? int : intLeadingZeroes; // Check min/max/lt/gt + var regex = options.hasOwnProperty('allow_leading_zeroes') && !options.allow_leading_zeroes ? _int : intLeadingZeroes; // Check min/max/lt/gt var minCheckPassed = !options.hasOwnProperty('min') || str >= options.min; var maxCheckPassed = !options.hasOwnProperty('max') || str <= options.max; @@ -966,14 +781,15 @@ function isSurrogatePair(str) { function isFloat(str, options) { assertString(str); options = options || {}; - var float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")); + + var _float = new RegExp("^(?:[-+])?(?:[0-9]+)?(?:\\".concat(options.locale ? decimal[options.locale] : '.', "[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$")); if (str === '' || str === '.' || str === '-' || str === '+') { return false; } var value = parseFloat(str.replace(',', '.')); - return float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt); + return _float.test(str) && (!options.hasOwnProperty('min') || value >= options.min) && (!options.hasOwnProperty('max') || value <= options.max) && (!options.hasOwnProperty('lt') || value < options.lt) && (!options.hasOwnProperty('gt') || value > options.gt); } var locales$2 = Object.keys(decimal); @@ -1219,8 +1035,8 @@ var validators = { } // validate the control digit - var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (char) { - return charsValue[char]; + var number = sanitized.slice(0, -1).replace(/[X,Y,Z]/g, function (_char) { + return charsValue[_char]; }); return sanitized.endsWith(controlDigits[number % 23]); } @@ -1729,12 +1545,12 @@ function isMimeType(str) { } var lat = /^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/; -var long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; +var _long = /^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/; var isLatLong = function (str) { assertString(str); if (!str.includes(',')) return false; var pair = str.split(','); - return lat.test(pair[0]) && long.test(pair[1]); + return lat.test(pair[0]) && _long.test(pair[1]); }; var threeDigit = /^\d{3}$/; diff --git a/validator.min.js b/validator.min.js index 8fbfc7f4c..fddf81781 100644 --- a/validator.min.js +++ b/validator.min.js @@ -20,4 +20,4 @@ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.validator=e()}(this,function(){"use strict";function a(t){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function g(t){var e;if(!("string"==typeof t||t instanceof String))throw e=null===t?"null":"object"===(e=a(t))&&t.constructor&&t.constructor.hasOwnProperty("name")?t.constructor.name:"a ".concat(e),new TypeError("Expected string but received ".concat(e,"."))}function n(t){return g(t),t=Date.parse(t),isNaN(t)?null:new Date(t)}function r(t){return g(t),parseFloat(t)}function i(t){return"object"===a(t)&&null!==t?t="function"==typeof t.toString?t.toString():"[object Object]":(null==t||isNaN(t)&&!t.length)&&(t=""),String(t)}function h(){var t=0i)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(r.shift(),r.shift(),o=!0):"::"===t.substr(t.length-2)&&(r.pop(),r.pop(),o=!0);for(var a=0;a$/i,F=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,S=/^[a-z\d]+$/,R=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,C=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},f=/^\[([^\]]+)\](?::([0-9]+))?$/;function p(t,e){for(var r=0;r=e.min,n=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&o&&n&&i&&a}var z=/^[\x00-\x7F]+$/;var W=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var Y=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var V=/[^\x00-\x7F]/;var j=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;var J=Object.keys(w),q=function(t,e){return t.some(function(t){return e===t})};var Q={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},X=["","-","+"];var tt=/^[0-9A-F]+$/i;function et(t){return g(t),tt.test(t)}var rt=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var ot=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var nt=/^[a-f0-9]{32}$/;var it={md5:32,md4:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8};var at=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var lt={ignore_whitespace:!1};var st={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};var ut=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;var ct={ES:function(t){g(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var o=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][o%23])}};var dt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var ft=/^(?:[0-9]{9}X|[0-9]{10})$/,pt=/^(?:[0-9]{13})$/,gt=[1,3];var ht={"ar-AE":/^((\+?971)|0)?5[024568]\d{7}$/,"ar-DZ":/^(\+?213|0)(5|6|7)\d{8}$/,"ar-EG":/^((\+?20)|0)?1[012]\d{8}$/,"ar-IQ":/^(\+?964|0)?7[0-9]\d{8}$/,"ar-JO":/^(\+?962|0)?7[789]\d{7}$/,"ar-KW":/^(\+?965)[569]\d{7}$/,"ar-SA":/^(!?(\+?966)|0)?5\d{8}$/,"ar-SY":/^(!?(\+?963)|0)?9\d{8}$/,"ar-TN":/^(\+?216)?[2459]\d{7}$/,"be-BY":/^(\+?375)?(24|25|29|33|44)\d{7}$/,"bg-BG":/^(\+?359|0)?8[789]\d{7}$/,"bn-BD":/\+?(88)?0?1[356789][0-9]{8}\b/,"cs-CZ":/^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"da-DK":/^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,"de-DE":/^(\+49)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,"el-GR":/^(\+?30|0)?(69\d{8})$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-GH":/^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,"en-HK":/^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,"en-IE":/^(\+?353|0)8[356789]\d{7}$/,"en-IN":/^(\+?91|0)?[6789]\d{9}$/,"en-KE":/^(\+?254|0)?[7]\d{8}$/,"en-MU":/^(\+?230|0)?\d{8}$/,"en-NG":/^(\+?234|0)?[789]\d{9}$/,"en-NZ":/^(\+?64|0)[28]\d{7,9}$/,"en-PK":/^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,"en-RW":/^(\+?250|0)?[7]\d{8}$/,"en-SG":/^(\+65)?[89]\d{7}$/,"en-TZ":/^(\+?255|0)?[67]\d{8}$/,"en-UG":/^(\+?256|0)?[7]\d{8}$/,"en-US":/^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-ZM":/^(\+?26)?09[567]\d{7}$/,"es-ES":/^(\+?34)?(6\d{1}|7[1234])\d{7}$/,"es-MX":/^(\+?52)?(1|01)?\d{10,11}$/,"es-UY":/^(\+598|0)9[1-9][\d]{6}$/,"et-EE":/^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,"fa-IR":/^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,"fi-FI":/^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,"fo-FO":/^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"he-IL":/^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,"hu-HU":/^(\+?36)(20|30|70)\d{7}$/,"id-ID":/^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,"it-IT":/^(\+?39)?\s?3\d{2} ?\d{6,7}$/,"ja-JP":/^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,"kk-KZ":/^(\+?7|8)?7\d{9}$/,"kl-GL":/^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"ko-KR":/^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,"lt-LT":/^(\+370|8)\d{8}$/,"ms-MY":/^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,"nb-NO":/^(\+?47)?[49]\d{7}$/,"nl-BE":/^(\+?32|0)4?\d{8}$/,"nn-NO":/^(\+?47)?[49]\d{7}$/,"pl-PL":/^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,"pt-BR":/(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,"pt-PT":/^(\+?351)?9[1236]\d{7}$/,"ro-RO":/^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/,"sl-SI":/^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,"sk-SK":/^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"sr-RS":/^(\+3816|06)[- \d]{5,9}$/,"sv-SE":/^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,"th-TH":/^(\+66|66|0)\d{9}$/,"tr-TR":/^(\+?90|0)?5\d{9}$/,"uk-UA":/^(\+?38|8)?0\d{9}$/,"vi-VN":/^(\+?84|0)((3([2-9]))|(5([689]))|(7([0|6-9]))|(8([1-5]))|(9([0-9])))([0-9]{7})$/,"zh-CN":/^((\+|00)86)?1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/};ht["en-CA"]=ht["en-US"],ht["fr-BE"]=ht["nl-BE"],ht["zh-HK"]=ht["en-HK"];var At=Object.keys(ht);var mt={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_decimal:!0,require_decimal:!1,digits_after_decimal:[2],allow_space_after_digits:!1};var $t=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;var vt=/([01][0-9]|2[0-3])/,_t=/[0-5][0-9]/,Ft=new RegExp("[-+]".concat(vt.source,":").concat(_t.source)),St=new RegExp("([zZ]|".concat(Ft.source,")")),Rt=new RegExp("".concat(vt.source,":").concat(_t.source,":").concat(/([0-5][0-9]|60)/.source).concat(/(\.[0-9]+)?/.source)),Et=new RegExp("".concat(/[0-9]{4}/.source,"-").concat(/(0[1-9]|1[0-2])/.source,"-").concat(/([12]\d|0[1-9]|3[01])/.source)),Ct=new RegExp("".concat(Rt.source).concat(St.source)),xt=new RegExp("".concat(Et.source,"[ tT]").concat(Ct.source));var Mt=["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","ZA","ZM","ZW"];var Nt=["AFG","ALA","ALB","DZA","ASM","AND","AGO","AIA","ATA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BES","BIH","BWA","BVT","BRA","IOT","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CYM","CAF","TCD","CHL","CHN","CXR","CCK","COL","COM","COG","COD","COK","CRI","CIV","HRV","CUB","CUW","CYP","CZE","DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","ATF","GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","VAT","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","IMN","ISR","ITA","JAM","JPN","JEY","JOR","KAZ","KEN","KIR","PRK","KOR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR","NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","NFK","MNP","NOR","OMN","PAK","PLW","PSE","PAN","PNG","PRY","PER","PHL","PCN","POL","PRT","PRI","QAT","REU","ROU","RUS","RWA","BLM","SHN","KNA","LCA","MAF","SPM","VCT","WSM","SMR","STP","SAU","SEN","SRB","SYC","SLE","SGP","SXM","SVK","SVN","SLB","SOM","ZAF","SGS","SSD","ESP","LKA","SDN","SUR","SJM","SWZ","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TKL","TON","TTO","TUN","TUR","TKM","TCA","TUV","UGA","UKR","ARE","GBR","USA","UMI","URY","UZB","VUT","VEN","VNM","VGB","VIR","WLF","ESH","YEM","ZMB","ZWE"];var wt=/[^A-Z0-9+\/=]/i;var Lt=/^[a-z]+\/[a-z0-9\-\+]+$/i,It=/^[a-z\-]+=[a-z0-9\-]+$/i,Tt=/^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;var Zt=/^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i;var Bt=/^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i,yt=/^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i,bt=/^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i;var Dt=/^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/,Ut=/^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/,Ot=/^\d{4}$/,Gt=/^\d{5}$/,Pt=/^\d{6}$/,kt={AD:/^AD\d{3}$/,AT:Ot,AU:Ot,BE:Ot,BG:Ot,CA:/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,CH:Ot,CZ:/^\d{3}\s?\d{2}$/,DE:Gt,DK:Ot,DZ:Gt,EE:Gt,ES:Gt,FI:Gt,FR:/^\d{2}\s?\d{3}$/,GB:/^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,GR:/^\d{3}\s?\d{2}$/,HR:/^([1-5]\d{4}$)/,HU:Ot,IL:Gt,IN:Pt,IS:/^\d{3}$/,IT:Gt,JP:/^\d{3}\-\d{4}$/,KE:Gt,LI:/^(948[5-9]|949[0-7])$/,LT:/^LT\-\d{5}$/,LU:Ot,LV:/^LV\-\d{4}$/,MX:Gt,NL:/^\d{4}\s?[a-z]{2}$/i,NO:Ot,PL:/^\d{2}\-\d{3}$/,PT:/^\d{4}\-\d{3}?$/,RO:Pt,RU:Pt,SA:Gt,SE:/^\d{3}\s?\d{2}$/,SI:Ot,SK:/^\d{3}\s?\d{2}$/,TN:Ot,TW:/^\d{3}(\d{2})?$/,UA:Gt,US:/^\d{5}(-\d{4})?$/,ZA:Ot,ZM:Gt},Kt=Object.keys(kt);function Ht(t,e){g(t);var r=e?new RegExp("^[".concat(e,"]+"),"g"):/^\s+/g;return t.replace(r,"")}function zt(t,e){g(t);for(var r=e?new RegExp("[".concat(e,"]")):/\s/,o=t.length-1;0<=o&&r.test(t[o]);o--);return o]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,o,n,i,a,l,s,u;if(e=h(e,d),1<(s=(t=(s=(t=(s=t.split("#")).shift()).split("?")).shift()).split("://")).length){if(r=s.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;s[0]=t.substr(2)}}if(""===(t=s.join("://")))return!1;if(""===(t=(s=t.split("/")).shift())&&!e.require_host)return!0;if(1<(s=t.split("@")).length){if(e.disallow_auth)return!1;if(0<=(o=s.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||o<=e.max)&&(!e.hasOwnProperty("lt")||oe.gt)},isFloatLocales:J,isDecimal:function(t,e){if(g(t),(e=h(e,Q)).locale in w)return!q(X,t.replace(/ /g,""))&&(r=e,new RegExp("^[-+]?([0-9]+)?(\\".concat(w[r.locale],"[0-9]{").concat(r.decimal_digits,"})").concat(r.force_decimal?"":"?","$"))).test(t);var r;throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:et,isDivisibleBy:function(t,e){return g(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return g(t),rt.test(t)},isISRC:function(t){return g(t),ot.test(t)},isMD5:function(t){return g(t),nt.test(t)},isHash:function(t,e){return g(t),new RegExp("^[a-f0-9]{".concat(it[e],"}$")).test(t)},isJWT:function(t){return g(t),at.test(t)},isJSON:function(t){g(t);try{var e=JSON.parse(t);return!!e&&"object"===a(e)}catch(t){}return!1},isEmpty:function(t,e){return g(t),0===((e=h(e,lt)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,o;g(t),o="object"===a(e)?(r=e.min||0,e.max):(r=e,arguments[2]);var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return r<=i&&(void 0===o||i<=o)},isByteLength:A,isUUID:function(t){var e=1/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return g(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return g(t),Wt(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return g(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Wt,isWhitelisted:function(t,e){g(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=h(e,Yt);var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];if(n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if(e.gmail_remove_subaddress&&(n[0]=n[0].split("+")[0]),e.gmail_remove_dots&&(n[0]=n[0].replace(/\.+/g,Qt)),!n[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(n[0]=n[0].toLowerCase()),n[1]=e.gmail_convert_googlemaildotcom?"gmail.com":n[1]}else if(0<=Vt.indexOf(n[1])){if(e.icloud_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(n[0]=n[0].toLowerCase())}else if(0<=jt.indexOf(n[1])){if(e.outlookdotcom_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(n[0]=n[0].toLowerCase())}else if(0<=Jt.indexOf(n[1])){if(e.yahoo_remove_subaddress){var i=n[0].split("-");n[0]=1i)return!1;if("::"===t)return!0;"::"===t.substr(0,2)?(r.shift(),r.shift(),o=!0):"::"===t.substr(t.length-2)&&(r.pop(),r.pop(),o=!0);for(var a=0;a$/i,F=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~]+$/i,S=/^[a-z\d]+$/,R=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f]))*$/i,E=/^[a-z\d!#\$%&'\*\+\-\/=\?\^_`{\|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+$/i,C=/^([\s\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|(\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*$/i;var d={protocols:["http","https","ftp"],require_tld:!0,require_protocol:!1,require_host:!0,require_valid_protocol:!0,allow_underscores:!1,allow_trailing_dot:!1,allow_protocol_relative_urls:!1},f=/^\[([^\]]+)\](?::([0-9]+))?$/;function p(t,e){for(var r=0;r=e.min,n=!e.hasOwnProperty("max")||t<=e.max,i=!e.hasOwnProperty("lt")||te.gt;return r.test(t)&&o&&n&&i&&a}var z=/^[\x00-\x7F]+$/;var W=/[^\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var Y=/[\u0020-\u007E\uFF61-\uFF9F\uFFA0-\uFFDC\uFFE8-\uFFEE0-9a-zA-Z]/;var V=/[^\x00-\x7F]/;var j=/[\uD800-\uDBFF][\uDC00-\uDFFF]/;var J=Object.keys(w),q=function(t,e){return t.some(function(t){return e===t})};var Q={force_decimal:!1,decimal_digits:"1,",locale:"en-US"},X=["","-","+"];var tt=/^[0-9A-F]+$/i;function et(t){return g(t),tt.test(t)}var rt=/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;var ot=/^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;var nt=/^[a-f0-9]{32}$/;var it={md5:32,md4:32,sha1:40,sha256:64,sha384:96,sha512:128,ripemd128:32,ripemd160:40,tiger128:32,tiger160:40,tiger192:48,crc32:8,crc32b:8};var at=/^([A-Za-z0-9\-_~+\/]+[=]{0,2})\.([A-Za-z0-9\-_~+\/]+[=]{0,2})(?:\.([A-Za-z0-9\-_~+\/]+[=]{0,2}))?$/;var lt={ignore_whitespace:!1};var st={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};var ut=/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14})$/;var ct={ES:function(t){g(t);var e={X:0,Y:1,Z:2},r=t.trim().toUpperCase();if(!/^[0-9X-Z][0-9]{7}[TRWAGMYFPDXBNJZSQVHLCKE]$/.test(r))return!1;var o=r.slice(0,-1).replace(/[X,Y,Z]/g,function(t){return e[t]});return r.endsWith(["T","R","W","A","G","M","Y","F","P","D","X","B","N","J","Z","S","Q","V","H","L","C","K","E"][o%23])}};var dt=/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/;var ft=/^(?:[0-9]{9}X|[0-9]{10})$/,pt=/^(?:[0-9]{13})$/,gt=[1,3];var ht={"ar-AE":/^((\+?971)|0)?5[024568]\d{7}$/,"ar-DZ":/^(\+?213|0)(5|6|7)\d{8}$/,"ar-EG":/^((\+?20)|0)?1[012]\d{8}$/,"ar-IQ":/^(\+?964|0)?7[0-9]\d{8}$/,"ar-JO":/^(\+?962|0)?7[789]\d{7}$/,"ar-KW":/^(\+?965)[569]\d{7}$/,"ar-SA":/^(!?(\+?966)|0)?5\d{8}$/,"ar-SY":/^(!?(\+?963)|0)?9\d{8}$/,"ar-TN":/^(\+?216)?[2459]\d{7}$/,"be-BY":/^(\+?375)?(24|25|29|33|44)\d{7}$/,"bg-BG":/^(\+?359|0)?8[789]\d{7}$/,"bn-BD":/\+?(88)?0?1[356789][0-9]{8}\b/,"cs-CZ":/^(\+?420)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"da-DK":/^(\+?45)?\s?\d{2}\s?\d{2}\s?\d{2}\s?\d{2}$/,"de-DE":/^(\+49)?0?1(5[0-25-9]\d|6([23]|0\d?)|7([0-57-9]|6\d))\d{7}$/,"el-GR":/^(\+?30|0)?(69\d{8})$/,"en-AU":/^(\+?61|0)4\d{8}$/,"en-GB":/^(\+?44|0)7\d{9}$/,"en-GH":/^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,"en-HK":/^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,"en-IE":/^(\+?353|0)8[356789]\d{7}$/,"en-IN":/^(\+?91|0)?[6789]\d{9}$/,"en-KE":/^(\+?254|0)?[7]\d{8}$/,"en-MU":/^(\+?230|0)?\d{8}$/,"en-NG":/^(\+?234|0)?[789]\d{9}$/,"en-NZ":/^(\+?64|0)[28]\d{7,9}$/,"en-PK":/^((\+92)|(0092))-{0,1}\d{3}-{0,1}\d{7}$|^\d{11}$|^\d{4}-\d{7}$/,"en-RW":/^(\+?250|0)?[7]\d{8}$/,"en-SG":/^(\+65)?[89]\d{7}$/,"en-TZ":/^(\+?255|0)?[67]\d{8}$/,"en-UG":/^(\+?256|0)?[7]\d{8}$/,"en-US":/^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/,"en-ZA":/^(\+?27|0)\d{9}$/,"en-ZM":/^(\+?26)?09[567]\d{7}$/,"es-ES":/^(\+?34)?(6\d{1}|7[1234])\d{7}$/,"es-MX":/^(\+?52)?(1|01)?\d{10,11}$/,"es-UY":/^(\+598|0)9[1-9][\d]{6}$/,"et-EE":/^(\+?372)?\s?(5|8[1-4])\s?([0-9]\s?){6,7}$/,"fa-IR":/^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,"fi-FI":/^(\+?358|0)\s?(4(0|1|2|4|5|6)?|50)\s?(\d\s?){4,8}\d$/,"fo-FO":/^(\+?298)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"fr-FR":/^(\+?33|0)[67]\d{8}$/,"he-IL":/^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/,"hu-HU":/^(\+?36)(20|30|70)\d{7}$/,"id-ID":/^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/,"it-IT":/^(\+?39)?\s?3\d{2} ?\d{6,7}$/,"ja-JP":/^(\+?81|0)[789]0[ \-]?[1-9]\d{2}[ \-]?\d{5}$/,"kk-KZ":/^(\+?7|8)?7\d{9}$/,"kl-GL":/^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/,"ko-KR":/^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,"lt-LT":/^(\+370|8)\d{8}$/,"ms-MY":/^(\+?6?01){1}(([0145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,"nb-NO":/^(\+?47)?[49]\d{7}$/,"nl-BE":/^(\+?32|0)4?\d{8}$/,"nn-NO":/^(\+?47)?[49]\d{7}$/,"pl-PL":/^(\+?48)? ?[5-8]\d ?\d{3} ?\d{2} ?\d{2}$/,"pt-BR":/(?=^(\+?5{2}\-?|0)[1-9]{2}\-?\d{4}\-?\d{4}$)(^(\+?5{2}\-?|0)[1-9]{2}\-?[6-9]{1}\d{3}\-?\d{4}$)|(^(\+?5{2}\-?|0)[1-9]{2}\-?9[6-9]{1}\d{3}\-?\d{4}$)/,"pt-PT":/^(\+?351)?9[1236]\d{7}$/,"ro-RO":/^(\+?4?0)\s?7\d{2}(\/|\s|\.|\-)?\d{3}(\s|\.|\-)?\d{3}$/,"ru-RU":/^(\+?7|8)?9\d{9}$/,"sl-SI":/^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/,"sk-SK":/^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/,"sr-RS":/^(\+3816|06)[- \d]{5,9}$/,"sv-SE":/^(\+?46|0)[\s\-]?7[\s\-]?[02369]([\s\-]?\d){7}$/,"th-TH":/^(\+66|66|0)\d{9}$/,"tr-TR":/^(\+?90|0)?5\d{9}$/,"uk-UA":/^(\+?38|8)?0\d{9}$/,"vi-VN":/^(\+?84|0)((3([2-9]))|(5([689]))|(7([0|6-9]))|(8([1-5]))|(9([0-9])))([0-9]{7})$/,"zh-CN":/^((\+|00)86)?1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/,"zh-TW":/^(\+?886\-?|0)?9\d{8}$/};ht["en-CA"]=ht["en-US"],ht["fr-BE"]=ht["nl-BE"],ht["zh-HK"]=ht["en-HK"];var At=Object.keys(ht);var mt={symbol:"$",require_symbol:!1,allow_space_after_symbol:!1,symbol_after_digits:!1,allow_negatives:!0,parens_for_negatives:!1,negative_sign_before_digits:!1,negative_sign_after_digits:!1,allow_negative_sign_placeholder:!1,thousands_separator:",",decimal_separator:".",allow_decimal:!0,require_decimal:!1,digits_after_decimal:[2],allow_space_after_digits:!1};var $t=/^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;var vt=/([01][0-9]|2[0-3])/,_t=/[0-5][0-9]/,Ft=new RegExp("[-+]".concat(vt.source,":").concat(_t.source)),St=new RegExp("([zZ]|".concat(Ft.source,")")),Rt=new RegExp("".concat(vt.source,":").concat(_t.source,":").concat(/([0-5][0-9]|60)/.source).concat(/(\.[0-9]+)?/.source)),Et=new RegExp("".concat(/[0-9]{4}/.source,"-").concat(/(0[1-9]|1[0-2])/.source,"-").concat(/([12]\d|0[1-9]|3[01])/.source)),Ct=new RegExp("".concat(Rt.source).concat(St.source)),xt=new RegExp("".concat(Et.source,"[ tT]").concat(Ct.source));var Mt=["AD","AE","AF","AG","AI","AL","AM","AO","AQ","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","ZA","ZM","ZW"];var Nt=["AFG","ALA","ALB","DZA","ASM","AND","AGO","AIA","ATA","ATG","ARG","ARM","ABW","AUS","AUT","AZE","BHS","BHR","BGD","BRB","BLR","BEL","BLZ","BEN","BMU","BTN","BOL","BES","BIH","BWA","BVT","BRA","IOT","BRN","BGR","BFA","BDI","KHM","CMR","CAN","CPV","CYM","CAF","TCD","CHL","CHN","CXR","CCK","COL","COM","COG","COD","COK","CRI","CIV","HRV","CUB","CUW","CYP","CZE","DNK","DJI","DMA","DOM","ECU","EGY","SLV","GNQ","ERI","EST","ETH","FLK","FRO","FJI","FIN","FRA","GUF","PYF","ATF","GAB","GMB","GEO","DEU","GHA","GIB","GRC","GRL","GRD","GLP","GUM","GTM","GGY","GIN","GNB","GUY","HTI","HMD","VAT","HND","HKG","HUN","ISL","IND","IDN","IRN","IRQ","IRL","IMN","ISR","ITA","JAM","JPN","JEY","JOR","KAZ","KEN","KIR","PRK","KOR","KWT","KGZ","LAO","LVA","LBN","LSO","LBR","LBY","LIE","LTU","LUX","MAC","MKD","MDG","MWI","MYS","MDV","MLI","MLT","MHL","MTQ","MRT","MUS","MYT","MEX","FSM","MDA","MCO","MNG","MNE","MSR","MAR","MOZ","MMR","NAM","NRU","NPL","NLD","NCL","NZL","NIC","NER","NGA","NIU","NFK","MNP","NOR","OMN","PAK","PLW","PSE","PAN","PNG","PRY","PER","PHL","PCN","POL","PRT","PRI","QAT","REU","ROU","RUS","RWA","BLM","SHN","KNA","LCA","MAF","SPM","VCT","WSM","SMR","STP","SAU","SEN","SRB","SYC","SLE","SGP","SXM","SVK","SVN","SLB","SOM","ZAF","SGS","SSD","ESP","LKA","SDN","SUR","SJM","SWZ","SWE","CHE","SYR","TWN","TJK","TZA","THA","TLS","TGO","TKL","TON","TTO","TUN","TUR","TKM","TCA","TUV","UGA","UKR","ARE","GBR","USA","UMI","URY","UZB","VUT","VEN","VNM","VGB","VIR","WLF","ESH","YEM","ZMB","ZWE"];var wt=/[^A-Z0-9+\/=]/i;var Lt=/^[a-z]+\/[a-z0-9\-\+]+$/i,It=/^[a-z\-]+=[a-z0-9\-]+$/i,Tt=/^[a-z0-9!\$&'\(\)\*\+,;=\-\._~:@\/\?%\s]*$/i;var Zt=/^magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32,40}&dn=.+&tr=.+$/i;var Bt=/^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9\.\-\+]{1,100}$/i,yt=/^text\/[a-zA-Z0-9\.\-\+]{1,100};\s?charset=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?$/i,bt=/^multipart\/[a-zA-Z0-9\.\-\+]{1,100}(;\s?(boundary|charset)=("[a-zA-Z0-9\.\-\+\s]{0,70}"|[a-zA-Z0-9\.\-\+]{0,70})(\s?\([a-zA-Z0-9\.\-\+\s]{1,20}\))?){0,2}$/i;var Dt=/^\(?[+-]?(90(\.0+)?|[1-8]?\d(\.\d+)?)$/,Ut=/^\s?[+-]?(180(\.0+)?|1[0-7]\d(\.\d+)?|\d{1,2}(\.\d+)?)\)?$/,Ot=/^\d{4}$/,Gt=/^\d{5}$/,Pt=/^\d{6}$/,kt={AD:/^AD\d{3}$/,AT:Ot,AU:Ot,BE:Ot,BG:Ot,CA:/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][\s\-]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,CH:Ot,CZ:/^\d{3}\s?\d{2}$/,DE:Gt,DK:Ot,DZ:Gt,EE:Gt,ES:Gt,FI:Gt,FR:/^\d{2}\s?\d{3}$/,GB:/^(gir\s?0aa|[a-z]{1,2}\d[\da-z]?\s?(\d[a-z]{2})?)$/i,GR:/^\d{3}\s?\d{2}$/,HR:/^([1-5]\d{4}$)/,HU:Ot,IL:Gt,IN:Pt,IS:/^\d{3}$/,IT:Gt,JP:/^\d{3}\-\d{4}$/,KE:Gt,LI:/^(948[5-9]|949[0-7])$/,LT:/^LT\-\d{5}$/,LU:Ot,LV:/^LV\-\d{4}$/,MX:Gt,NL:/^\d{4}\s?[a-z]{2}$/i,NO:Ot,PL:/^\d{2}\-\d{3}$/,PT:/^\d{4}\-\d{3}?$/,RO:Pt,RU:Pt,SA:Gt,SE:/^\d{3}\s?\d{2}$/,SI:Ot,SK:/^\d{3}\s?\d{2}$/,TN:Ot,TW:/^\d{3}(\d{2})?$/,UA:Gt,US:/^\d{5}(-\d{4})?$/,ZA:Ot,ZM:Gt},Kt=Object.keys(kt);function Ht(t,e){g(t);var r=e?new RegExp("^[".concat(e,"]+"),"g"):/^\s+/g;return t.replace(r,"")}function zt(t,e){g(t);for(var r=e?new RegExp("[".concat(e,"]")):/\s/,o=t.length-1;0<=o&&r.test(t[o]);o--);return o]/.test(t))return!1;if(0===t.indexOf("mailto:"))return!1;var r,o,n,i,a,l,s,u;if(e=h(e,d),1<(s=(t=(s=(t=(s=t.split("#")).shift()).split("?")).shift()).split("://")).length){if(r=s.shift().toLowerCase(),e.require_valid_protocol&&-1===e.protocols.indexOf(r))return!1}else{if(e.require_protocol)return!1;if("//"===t.substr(0,2)){if(!e.allow_protocol_relative_urls)return!1;s[0]=t.substr(2)}}if(""===(t=s.join("://")))return!1;if(""===(t=(s=t.split("/")).shift())&&!e.require_host)return!0;if(1<(s=t.split("@")).length){if(e.disallow_auth)return!1;if(0<=(o=s.shift()).indexOf(":")&&2=e.min)&&(!e.hasOwnProperty("max")||o<=e.max)&&(!e.hasOwnProperty("lt")||oe.gt)},isFloatLocales:J,isDecimal:function(t,e){if(g(t),(e=h(e,Q)).locale in w)return!q(X,t.replace(/ /g,""))&&function(t){return new RegExp("^[-+]?([0-9]+)?(\\".concat(w[t.locale],"[0-9]{").concat(t.decimal_digits,"})").concat(t.force_decimal?"":"?","$"))}(e).test(t);throw new Error("Invalid locale '".concat(e.locale,"'"))},isHexadecimal:et,isDivisibleBy:function(t,e){return g(t),r(t)%parseInt(e,10)==0},isHexColor:function(t){return g(t),rt.test(t)},isISRC:function(t){return g(t),ot.test(t)},isMD5:function(t){return g(t),nt.test(t)},isHash:function(t,e){return g(t),new RegExp("^[a-f0-9]{".concat(it[e],"}$")).test(t)},isJWT:function(t){return g(t),at.test(t)},isJSON:function(t){g(t);try{var e=JSON.parse(t);return!!e&&"object"===a(e)}catch(t){}return!1},isEmpty:function(t,e){return g(t),0===((e=h(e,lt)).ignore_whitespace?t.trim().length:t.length)},isLength:function(t,e){var r,o;g(t),o="object"===a(e)?(r=e.min||0,e.max):(r=e,arguments[2]);var n=t.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[],i=t.length-n.length;return r<=i&&(void 0===o||i<=o)},isByteLength:A,isUUID:function(t){var e=1/g,">").replace(/\//g,"/").replace(/\\/g,"\").replace(/`/g,"`")},unescape:function(t){return g(t),t.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(///g,"/").replace(/\/g,"\\").replace(/`/g,"`")},stripLow:function(t,e){return g(t),Wt(t,e?"\\x00-\\x09\\x0B\\x0C\\x0E-\\x1F\\x7F":"\\x00-\\x1F\\x7F")},whitelist:function(t,e){return g(t),t.replace(new RegExp("[^".concat(e,"]+"),"g"),"")},blacklist:Wt,isWhitelisted:function(t,e){g(t);for(var r=t.length-1;0<=r;r--)if(-1===e.indexOf(t[r]))return!1;return!0},normalizeEmail:function(t,e){e=h(e,Yt);var r=t.split("@"),o=r.pop(),n=[r.join("@"),o];if(n[1]=n[1].toLowerCase(),"gmail.com"===n[1]||"googlemail.com"===n[1]){if(e.gmail_remove_subaddress&&(n[0]=n[0].split("+")[0]),e.gmail_remove_dots&&(n[0]=n[0].replace(/\.+/g,Qt)),!n[0].length)return!1;(e.all_lowercase||e.gmail_lowercase)&&(n[0]=n[0].toLowerCase()),n[1]=e.gmail_convert_googlemaildotcom?"gmail.com":n[1]}else if(0<=Vt.indexOf(n[1])){if(e.icloud_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.icloud_lowercase)&&(n[0]=n[0].toLowerCase())}else if(0<=jt.indexOf(n[1])){if(e.outlookdotcom_remove_subaddress&&(n[0]=n[0].split("+")[0]),!n[0].length)return!1;(e.all_lowercase||e.outlookdotcom_lowercase)&&(n[0]=n[0].toLowerCase())}else if(0<=Jt.indexOf(n[1])){if(e.yahoo_remove_subaddress){var i=n[0].split("-");n[0]=1 Date: Fri, 12 Apr 2019 09:51:11 +0200 Subject: [PATCH 05/11] amending version in index --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 4cb4d5188..9ed45f605 100644 --- a/src/index.js +++ b/src/index.js @@ -96,7 +96,7 @@ import normalizeEmail from './lib/normalizeEmail'; import toString from './lib/util/toString'; -const version = '10.11.0'; +const version = '10.13.0'; const validator = { version, From 6b47252c584d71ff8930f229c408abf2ce1ce6b0 Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Fri, 12 Apr 2019 09:51:23 +0200 Subject: [PATCH 06/11] updating readme file about es module --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7bdbc8f6b..a0112d93f 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ Or, import only a subset of the library: import isEmail from 'validator/lib/isEmail'; ``` +#### Tree-shakeable ES imports + +```javascript +import isEmail from 'validator/es/lib/isEmail'; +``` + ### Client-side usage The library can be loaded either as a standalone script, or through an [AMD][amd]-compatible loader From eb35eff63d56c73f900bd649bfc151965459a32e Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Fri, 12 Apr 2019 10:08:56 +0200 Subject: [PATCH 07/11] reverting spacing change --- package.json | 142 +++++++++++++++++++++++++-------------------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/package.json b/package.json index e3191d4a7..ea34f92ca 100644 --- a/package.json +++ b/package.json @@ -1,73 +1,73 @@ { - "name": "validator", - "description": "String validation and sanitization", - "version": "10.13.0", - "sideEffects": false, - "homepage": "https://github.com/chriso/validator.js", - "files": [ - "index.js", - "es", - "lib", - "README.md", - "LICENCE", - "validator.js", - "validator.min.js" - ], - "keywords": [ - "validator", - "validation", - "validate", - "sanitization", - "sanitize", - "sanitisation", - "sanitise", - "assert" - ], - "author": "Chris O'Hara ", - "contributors": [{ - "name": "Anthony Nandaa", - "url": "https://github.com/profnandaa" - }], - "main": "index.js", - "bugs": { - "url": "https://github.com/chriso/validator.js/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/chriso/validator.js.git" - }, - "devDependencies": { - "@babel/cli": "^7.0.0", - "@babel/core": "^7.0.0", - "@babel/preset-env": "^7.0.0", - "@babel/register": "^7.0.0", - "babel-eslint": "^10.0.1", - "babel-plugin-add-module-exports": "^1.0.0", - "eslint": "^4.19.1", - "eslint-config-airbnb-base": "^12.1.0", - "eslint-plugin-import": "^2.11.0", - "mocha": "^5.1.1", - "rollup": "^0.43.0", - "rollup-plugin-babel": "^4.0.1", - "uglify-js": "^3.0.19" - }, - "scripts": { - "lint": "eslint src test", - "lint:fix": "eslint --fix src test", - "clean:node": "rm -rf index.js lib", - "clean:es": "rm -rf es", - "clean:browser": "rm -rf validator*.js", - "clean": "npm run clean:node && npm run clean:browser && npm run clean:es", - "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", - "build:browser": "node --require @babel/register build-browser && npm run minify", - "build:es": "babel src -d es --env-name=es", - "build:node": "babel src -d .", - "build": "npm run build:browser && npm run build:node && npm run build:es", - "pretest": "npm run lint && npm run build", - "test": "mocha --require @babel/register --reporter dot" - }, - "engines": { - "node": ">= 0.10" - }, - "license": "MIT" + "name": "validator", + "description": "String validation and sanitization", + "version": "10.13.0", + "sideEffects": false, + "homepage": "https://github.com/chriso/validator.js", + "files": [ + "index.js", + "es", + "lib", + "README.md", + "LICENCE", + "validator.js", + "validator.min.js" + ], + "keywords": [ + "validator", + "validation", + "validate", + "sanitization", + "sanitize", + "sanitisation", + "sanitise", + "assert" + ], + "author": "Chris O'Hara ", + "contributors": [{ + "name": "Anthony Nandaa", + "url": "https://github.com/profnandaa" + }], + "main": "index.js", + "bugs": { + "url": "https://github.com/chriso/validator.js/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/chriso/validator.js.git" + }, + "devDependencies": { + "@babel/cli": "^7.0.0", + "@babel/core": "^7.0.0", + "@babel/preset-env": "^7.0.0", + "@babel/register": "^7.0.0", + "babel-eslint": "^10.0.1", + "babel-plugin-add-module-exports": "^1.0.0", + "eslint": "^4.19.1", + "eslint-config-airbnb-base": "^12.1.0", + "eslint-plugin-import": "^2.11.0", + "mocha": "^5.1.1", + "rollup": "^0.43.0", + "rollup-plugin-babel": "^4.0.1", + "uglify-js": "^3.0.19" + }, + "scripts": { + "lint": "eslint src test", + "lint:fix": "eslint --fix src test", + "clean:node": "rm -rf index.js lib", + "clean:es": "rm -rf es", + "clean:browser": "rm -rf validator*.js", + "clean": "npm run clean:node && npm run clean:browser && npm run clean:es", + "minify": "uglifyjs validator.js -o validator.min.js --compress --mangle --comments /Copyright/", + "build:browser": "node --require @babel/register build-browser && npm run minify", + "build:es": "babel src -d es --env-name=es", + "build:node": "babel src -d .", + "build": "npm run build:browser && npm run build:node && npm run build:es", + "pretest": "npm run lint && npm run build", + "test": "mocha --require @babel/register --reporter dot" + }, + "engines": { + "node": ">= 0.10" + }, + "license": "MIT" } \ No newline at end of file From b2d0fda436250d75373b89668d749f5483b3e019 Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Fri, 12 Apr 2019 15:35:15 +0200 Subject: [PATCH 08/11] amending version - skipped one perviously --- package.json | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ea34f92ca..04cc70806 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validator", "description": "String validation and sanitization", - "version": "10.13.0", + "version": "10.12.0", "sideEffects": false, "homepage": "https://github.com/chriso/validator.js", "files": [ diff --git a/src/index.js b/src/index.js index 9ed45f605..5892e3c7c 100644 --- a/src/index.js +++ b/src/index.js @@ -96,7 +96,7 @@ import normalizeEmail from './lib/normalizeEmail'; import toString from './lib/util/toString'; -const version = '10.13.0'; +const version = '10.12.0'; const validator = { version, From bb19acd63f1bd42ee28b8702435d7c28ae887d5c Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Mon, 15 Apr 2019 09:03:09 +0200 Subject: [PATCH 09/11] Revert "amending version - skipped one perviously" This reverts commit b2d0fda436250d75373b89668d749f5483b3e019. --- package.json | 2 +- src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 04cc70806..ea34f92ca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validator", "description": "String validation and sanitization", - "version": "10.12.0", + "version": "10.13.0", "sideEffects": false, "homepage": "https://github.com/chriso/validator.js", "files": [ diff --git a/src/index.js b/src/index.js index 5892e3c7c..9ed45f605 100644 --- a/src/index.js +++ b/src/index.js @@ -96,7 +96,7 @@ import normalizeEmail from './lib/normalizeEmail'; import toString from './lib/util/toString'; -const version = '10.12.0'; +const version = '10.13.0'; const validator = { version, From 52b302fab74938df38a2742b7051ca7a4305ba80 Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Mon, 15 Apr 2019 09:04:29 +0200 Subject: [PATCH 10/11] Revert "amending version in index" This reverts commit 8f7f6b934b287c81e6587f8cdc91ec3ae20dda86. --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 9ed45f605..4cb4d5188 100644 --- a/src/index.js +++ b/src/index.js @@ -96,7 +96,7 @@ import normalizeEmail from './lib/normalizeEmail'; import toString from './lib/util/toString'; -const version = '10.13.0'; +const version = '10.11.0'; const validator = { version, From 6f458ec2151035ff0aee2449fc50c4a7ec687ba6 Mon Sep 17 00:00:00 2001 From: Artur Banas Date: Mon, 15 Apr 2019 09:08:38 +0200 Subject: [PATCH 11/11] reverting version change --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea34f92ca..03e0ecfaf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "validator", "description": "String validation and sanitization", - "version": "10.13.0", + "version": "10.11.0", "sideEffects": false, "homepage": "https://github.com/chriso/validator.js", "files": [