🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

purify

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

purify - npm Package Compare versions

Comparing version

to
3.4.0

karma.conf.js

1397

lib/purify.js

@@ -1,353 +0,1122 @@

(function (root, factory) {
if (typeof exports === 'object') {
module.exports = factory(require('one-validation'), require('punycode'), require('unicoderegexp'));
} else if (typeof define === 'function' && define.amd) {
define(['one-validation', 'punycode', 'unicoderegexp'], factory);
} else {
root.purify = factory(root.one.validation, root.punycode, root.unicodeRegExp);
}
}(this, function (oneValidation, punycode, unicodeRegExp) {
var purify = {};
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = global || self, global.purify = factory());
}(this, function () {
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
purify.boolean = function (rawValue, defaultValue) {
if (typeof rawValue === 'boolean') {
return rawValue;
} else if (typeof rawValue === 'string') {
var isTrue = /^(?:1|on|true|yes)$/i.test(rawValue),
isFalse = /^(?:0|off|false|no)$/i.test(rawValue);
return isTrue ? true : (isFalse ? false : defaultValue);
}
return defaultValue;
};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
purify.email = purify.emailAddress = function (rawValue, defaultValue) {
// Should return an email with the domain part in its punycoded form regardless of input
var fragments,
encodedEmail,
encodedDomain;
var validation = createCommonjsModule(function (module, exports) {
/*global module, define*/
try {
if (typeof rawValue === 'string' && oneValidation.emailIdn.test(rawValue)) {
fragments = rawValue.split('@');
encodedDomain = fragments.length === 2 && punycode.toASCII(fragments[1]).toLowerCase();
var decodedDomain = punycode.toUnicode(encodedDomain); // Makes sure invalid domains like foo.xn--no aren't allowed
(function (root, factory) {
{
module.exports = factory();
}
}(commonjsGlobal, function () {
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
encodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
encodedDomain = undefined;
} finally {
encodedEmail = encodedDomain && fragments[0] + '@' + encodedDomain;
if (typeof encodedEmail === 'string' && oneValidation.email.test(encodedEmail)) {
return encodedEmail;
} else {
return defaultValue;
}
}
};
// Poor man's /x flag:
// new RegExp(concatRegExps(
// /blabla/,
// /blablabla/
// ), 'i').test(string);
function concatRegExps() { // ...
var source = '',
i = 0;
for (; i < arguments.length; i += 1) {
if (Object.prototype.toString.call(arguments[i]) === '[object RegExp]') {
source += arguments[i].source;
} else {
source += arguments[i];
}
}
return source;
}
purify.emailIdn = purify.emailAddressIdn = function (rawValue, defaultValue) {
// Should return an email with the domain part in its non-punycoded form regardless of input
var fragments,
decodedDomain,
decodedEmail;
var ipv4DigitRegExpSource = /(?:[0-9]|1?[0-9][0-9]|2[0-4][0-9]|25[0-5])/.source,
validation = {
functions: {}
},
fragments = {
visibleNonAsciiChar: /[ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԥԱ-Ֆՙա-ևא-תװ-ײء-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨऄ-हऽॐक़-ॡॱॲॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡഅ-ഌഎ-ഐഒ-നപ-ഹഽൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜໝༀཀ-ཇཉ-ཬྈ-ྋက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-Ⴥა-ჺჼᄀ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₔℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⴀ-ⴥⴰ-ⵥⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆷㇰ-ㇿ㐀-䶵一-鿋ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙟꙢ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋꞌꟻ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-鶴侮-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ̀-ͯ҃-҉֑-ׇֽֿׁׂׅׄؐ-ًؚ-ٰٞۖ-ۜ۞-۪ۤۧۨ-ܑۭܰ-݊ަ-ް߫-߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࠭ऀ-ः़ा-ॎ॑-ॕॢॣঁ-ঃ়া-ৄেৈো-্ৗৢৣਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑੰੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୢୣஂா-ூெ-ைொ-்ௗఁ-ఃా-ౄె-ైొ-్ౕౖౢౣಂಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣംഃാ-ൄെ-ൈൊ-്ൗൢൣංඃ්ා-ුූෘ-ෟෲෳัิ-ฺ็-๎ັິ-ູົຼ່-ໍ༹༘༙༵༷༾༿ཱ-྄྆྇ྐ-ྗྙ-ྼ࿆ါ-ှၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏႚ-ႝ፟ᜒ-᜔ᜲ-᜴ᝒᝓᝲᝳា-៓៝᠋-᠍ᢩᤠ-ᤫᤰ-᤻ᦰ-ᧀᧈᧉᨗ-ᨛᩕ-ᩞ᩠-᩿᩼ᬀ-ᬄ᬴-᭄᭫-᭳ᮀ-ᮂᮡ-᮪ᰤ-᰷᳐-᳔᳒-᳨᳭ᳲ᷀-᷽ᷦ-᷿⃐-⃰⳯-⳱ⷠ-〪ⷿ-゙゚〯꙯-꙲꙼꙽꛰꛱ꠂ꠆ꠋꠣ-ꠧꢀꢁꢴ-꣄꣠-꣱ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀ꨩ-ꨶꩃꩌꩍꩻꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꯣ-ꯪ꯬꯭ﬞ︀-️︠-︦²³¹¼-¾٠-٩۰-۹߀-߉०-९০-৯৴-৹੦-੯૦-૯୦-୯௦-௲౦-౯౸-౾೦-೯൦-൵๐-๙໐-໙༠-༳၀-၉႐-႙፩-፼ᛮ-ᛰ០-៩៰-៹᠐-᠙᥆-᥏᧐-᧚᪀-᪉᪐-᪙᭐-᭙᮰-᮹᱀-᱉᱐-᱙⁰⁴-⁹₀-₉⅐-ↂↅ-↉①-⒛⓪-⓿❶-➓⳽〇〡-〩〸-〺㆒-㆕㈠-㈩㉑-㉟㊀-㊉㊱-㊿꘠-꘩ꛦ-ꛯ꠰-꠵꣐-꣙꤀-꤉꧐-꧙꩐-꩙꯰-꯹0-9¡«·»¿;·՚-՟։֊־׀׃׆׳״؉؊،؍؛؞؟٪-٭۔܀-܍߷-߹࠰-࠾।॥॰෴๏๚๛༄-༒༺-༽྅࿐-࿔၊-၏჻፡-፨᐀᙭᙮᚛᚜᛫-᛭᜵᜶។-៖៘-៚᠀-᠊᥄᥅᧞᧟᨞᨟᪠-᪦᪨-᪭᭚-᭠᰻-᰿᱾᱿᳓‐-‧‰-⁃⁅-⁑⁓-⁞⁽⁾₍₎〈〉❨-❵⟅⟆⟦-⟯⦃-⦘⧘-⧛⧼⧽⳹-⳼⳾⳿⸀-⸮⸰⸱、-〃〈-】〔-〟〰〽゠・꓾꓿꘍-꘏꙳꙾꛲-꛷꡴-꡷꣎꣏꣸-꣺꤮꤯꥟꧁-꧍꧞꧟꩜-꩟꫞꫟꯫﴾﴿︐-︙︰-﹒﹔-﹡﹣﹨﹪﹫!-#%-*,-/:;?@[-]_{}⦅-・¢-©¬®-±´¶¸×÷˂-˅˒-˟˥-˫˭˯-˿͵΄΅϶҂؆-؈؋؎؏۩۽۾߶৲৳৺৻૱୰௳-௺౿ೱೲ൹฿༁-༃༓-༗༚-༟༴༶༸྾-࿅࿇-࿌࿎࿏࿕-࿘႞႟፠᎐-᎙៛᥀᧠-᧿᭡-᭪᭴-᭼᾽᾿-῁῍-῏῝-῟῭-`´῾⁄⁒⁺-⁼₊-₌₠-₸℀℁℃-℆℈℉℔№-℘℞-℣℥℧℩℮℺℻⅀-⅄⅊-⅍⅏←-⌨⌫-⏨␀-␦⑀-⑊⒜-ⓩ─-⛍⛏-⛡⛣⛨-⛿✁-✄✆-✉✌-✧✩-❋❍❏-❒❖-❞❡-❧➔➘-➯➱-➾⟀-⟄⟇-⟊⟌⟐-⟥⟰-⦂⦙-⧗⧜-⧻⧾-⭌⭐-⭙⳥-⳪⺀-⺙⺛-⻳⼀-⿕⿰-⿻〄〒〓〠〶〷〾〿゛゜㆐㆑㆖-㆟㇀-㇣㈀-㈞㈪-㉐㉠-㉿㊊-㊰㋀-㋾㌀-㏿䷀-䷿꒐-꓆꜀-꜖꜠꜡꞉꞊꠨-꠫꠶-꠹꩷-꩹﬩﷼﷽﹢﹤-﹦﹩$+<->^`|~¢-₩│-\uffee\ufffc\ufffd]/,
domainPart: /[a-z0-9](?:[\-a-z0-9]*[a-z0-9])?/i,
tld: /[a-z][\-a-z]*[a-z]/i,
port: /\d{1,5}/,
localpart: /[a-z0-9!#$%&'*+\/=?\^_`{|}~\-:][\.a-z0-9!#$%&'*+\/=?\^_`{|}~\-]*/i, // taken from: http://www.regular-expressions.info/email.html
user: /[^:@\/]+/i,
uuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i,
lowerCaseUuid: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/,
upperCaseUuid: /[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/,
password: /[^@\/]+?/i,
pathname: /[\w\-\.~%!$&'\(\)*+,;=:@\/]*/,
search: /[\w\-\.~%!$&'\(\)*+,;=:@\/?]*/,
hash: /[\w\-\.~%!$&'\(\)*+,;=:@\/?#]*/,
ipv4: new RegExp('(?:' + ipv4DigitRegExpSource + '\\.){3}' + ipv4DigitRegExpSource)
},
name;
try {
if (typeof rawValue === 'string' && oneValidation.emailIdn.test(rawValue)) {
fragments = rawValue.split('@');
decodedDomain = fragments.length === 2 && punycode.toUnicode(fragments[1]).toLowerCase();
// Highlevel regexes composed of regex fragments
var alphanumericalPlusVisibleNonAsciiChars = new RegExp(fragments.visibleNonAsciiChar.source.replace(/^\[/, '[a-z0-9')),
alphabeticalPlusVisibleNonAsciiChars = new RegExp(fragments.visibleNonAsciiChar.source.replace(/^\[/, '[a-z'));
fragments.domainPartIdn = new RegExp(concatRegExps(alphanumericalPlusVisibleNonAsciiChars,
'(?:',
new RegExp(alphanumericalPlusVisibleNonAsciiChars.source.replace(/^\[/, '[\\-') + '*'),
alphanumericalPlusVisibleNonAsciiChars,
')?'));
fragments.tldIdn = new RegExp(concatRegExps(alphabeticalPlusVisibleNonAsciiChars,
new RegExp(alphabeticalPlusVisibleNonAsciiChars.source.replace(/^\[/, '[\\-') + '*'),
alphabeticalPlusVisibleNonAsciiChars));
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
decodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
decodedDomain = undefined;
} finally {
decodedEmail = decodedDomain && fragments[0] + '@' + decodedDomain;
if (typeof decodedEmail === 'string' && oneValidation.emailIdn.test(decodedEmail)) {
return decodedEmail;
} else {
return defaultValue;
}
}
};
fragments.domain = fragments.domainName = new RegExp('(?:' + fragments.domainPart.source + '\\.)+' + fragments.tld.source, 'i');
fragments.domainIdn = fragments.domainNameIdn = new RegExp('(?:' + fragments.domainPartIdn.source + '\\.)+' + fragments.tldIdn.source, 'i');
purify.domain = purify.domainName = function (rawValue, defaultValue) {
// Should return a domain in its punycoded form regardless of input
var encodedDomain;
try {
if (typeof rawValue === 'string' && oneValidation.domainIdn.test(rawValue)) {
encodedDomain = punycode.toASCII(rawValue.toLowerCase());
var decodedDomain = punycode.toUnicode(encodedDomain); // Makes sure that things like foo.xn--no aren't allowed
fragments.email = fragments.emailAddress = new RegExp(fragments.localpart.source + '@' + fragments.domain.source, 'i');
fragments.emailIdn = fragments.emailAddressIdn = new RegExp(fragments.localpart.source + '@' + fragments.domainIdn.source, 'i');
fragments.mailtoUrl = new RegExp('mailto:' + fragments.email.source, 'i'); // TODO: This needs to be improved
fragments.mailtoUrlIdn = new RegExp('mailto:' + fragments.emailIdn.source, 'i'); // TODO: This needs to be improved
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
encodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
encodedDomain = undefined;
} finally {
if (typeof encodedDomain === 'string' && oneValidation.domain.test(encodedDomain)) {
return encodedDomain;
} else {
return defaultValue;
}
}
};
// Same as location.pathname + location.search + location.hash in the browser:
fragments.pathnameSearchHash = new RegExp(concatRegExps(
'(?:/', fragments.pathname,
'(?:\\?', fragments.search, ')?',
'(?:#', fragments.hash, ')?',
')?' // See http://www.ietf.org/rfc/rfc1738.txt
));
purify.domainIdn = purify.domainNameIdn = function (rawValue, defaultValue) {
// Should return a domain in its non-punycoded form regardless of input
var decodedDomain;
try {
if (typeof rawValue === 'string' && oneValidation.domainIdn.test(rawValue)) {
decodedDomain = punycode.toUnicode(rawValue.toLowerCase());
function createHttpishUrlRegExp(options) {
// [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment]
options = options || {};
return new RegExp(concatRegExps(
(options.scheme || 'https?'), '://',
'(?:',
fragments.user,
'(?::',
fragments.password,
')?@',
')?',
'(?:',
(options.localhost ? 'localhost|' : ''),
(options.idn ? fragments.domainIdn : fragments.domain),
'|',
fragments.ipv4,
')',
'(?::', fragments.port, ')?',
fragments.pathnameSearchHash
), 'i');
}
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
decodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
decodedDomain = undefined;
} finally {
if (typeof decodedDomain === 'string' && oneValidation.domainIdn.test(decodedDomain)) {
return decodedDomain;
} else {
return defaultValue;
}
}
};
fragments.httpUrl = createHttpishUrlRegExp({scheme: /https?/});
fragments.httpUrlIdn = createHttpishUrlRegExp({scheme: /https?/, idn: true});
fragments.ftpUrl = createHttpishUrlRegExp({scheme: /ftp/});
fragments.ftpUrlIdn = createHttpishUrlRegExp({scheme: /ftp/, idn: true});
purify.url = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && oneValidation.httpUrl.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
function getFlagsStringFromRegExp(regExp) {
var flagsString = '';
if (regExp.ignoreCase) {
flagsString += 'i';
}
if (regExp.global) {
flagsString += 'g';
}
if (regExp.multiline) {
flagsString += 'm';
}
return flagsString;
}
var urlWithLocalhostRegExp = new RegExp('^(?:' + oneValidation.createHttpishUrlRegExp({scheme: /https?/, localhost: true}).source + ')$');
// Add convenience regexes and functions
for (name in fragments) {
if (fragments.hasOwnProperty(name)) {
validation[name] = new RegExp('^' + fragments[name].source + '$', getFlagsStringFromRegExp(fragments[name]));
validation.functions[name] = (function (name) {
return function (value) {
return validation[name].test(value);
};
}(name));
}
}
purify.urlWithLocalhost = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && urlWithLocalhostRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
// Expose regex fragments for matching inside larger texts
validation.fragments = fragments;
purify.integer = function (rawValue, defaultValue) {
var integer;
if (typeof rawValue === 'string') {
integer = parseInt(rawValue, 10);
} else if (typeof rawValue === 'number') {
integer = Math.floor(rawValue);
}
if (typeof integer === 'number' && isFinite(integer) && !isNaN(integer)) {
return integer;
} else {
return defaultValue;
}
};
validation.createHttpishUrlRegExp = createHttpishUrlRegExp;
purify.integerInRange = function (rawValue, lower, upper, defaultValue) {
var integer = purify.integer(rawValue);
if (typeof integer === 'number' && !isNaN(integer) && isFinite(integer) && (typeof lower === 'undefined' || integer >= lower) && (typeof upper === 'undefined' || integer <= upper)) {
return integer;
}
return defaultValue;
};
return validation;
}));
});
purify.positiveInteger = function (rawValue, defaultValue) {
var integer = purify.integer(rawValue);
if (typeof integer !== 'undefined' && !isNaN(integer) && isFinite(integer) && integer >= 1) {
return integer;
}
return defaultValue;
};
var punycode = createCommonjsModule(function (module, exports) {
(function(root) {
purify.positiveIntegerOrZero = function (rawValue, defaultValue) {
var integer = purify.integer(rawValue);
if (typeof integer !== 'undefined' && !isNaN(integer) && isFinite(integer) && integer >= 0) {
return integer;
}
return defaultValue;
};
/** Detect free variables */
var freeExports = exports &&
!exports.nodeType && exports;
var freeModule = module &&
!module.nodeType && module;
var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal;
if (
freeGlobal.global === freeGlobal ||
freeGlobal.window === freeGlobal ||
freeGlobal.self === freeGlobal
) {
root = freeGlobal;
}
purify.float = function (rawValue, defaultValue) {
var number;
if (typeof rawValue === 'string') {
if (/^[\-+]?[0-9]*\.?[0-9]+$/.test(rawValue)) {
number = parseFloat(rawValue);
}
} else if (typeof rawValue === 'number') {
number = rawValue;
}
if (typeof number !== 'undefined' && !isNaN(number) && isFinite(number)) {
return number;
}
return defaultValue;
};
/**
* The `punycode` object.
* @name punycode
* @type Object
*/
var punycode,
purify.positiveFloat = function (rawValue, defaultValue) {
var number;
if (typeof rawValue === 'string') {
if (/^\+?[0-9]*\.?[0-9]+$/.test(rawValue)) {
number = parseFloat(rawValue);
}
} else if (typeof rawValue === 'number') {
number = rawValue;
}
if (typeof number !== 'undefined' && !isNaN(number) && isFinite(number) && number > 0) {
return number;
}
return defaultValue;
};
/** Highest positive signed 32-bit float value */
maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
purify.positiveFloatOrZero = function (rawValue, defaultValue) {
var number;
if (typeof rawValue === 'string') {
if (/^\+?[0-9]*\.?[0-9]+$/.test(rawValue)) {
number = parseFloat(rawValue);
}
} else if (typeof rawValue === 'number') {
number = rawValue;
}
if (typeof number !== 'undefined' && !isNaN(number) && isFinite(number) && number >= 0) {
return number;
}
return defaultValue;
};
/** Bootstring parameters */
base = 36,
tMin = 1,
tMax = 26,
skew = 38,
damp = 700,
initialBias = 72,
initialN = 128, // 0x80
delimiter = '-', // '\x2D'
// Visible characters, full Unicode repertoire
var nonEmptyVisibleUnicodeRegExp = new RegExp('^' + unicodeRegExp.visible.source + '+$');
purify.nonEmptyVisibleUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && nonEmptyVisibleUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/** Regular expressions */
regexPunycode = /^xn--/,
regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
// Visible characters, full Unicode repertoire
var visibleUnicodeRegExp = new RegExp('^' + unicodeRegExp.visible.source + '*$');
purify.visibleUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && visibleUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/** Error messages */
errors = {
'overflow': 'Overflow: input needs wider integers to process',
'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
'invalid-input': 'Invalid input'
},
// Visible characters + space, full Unicode repertoire
var nonEmptyPrintableUnicodeRegExp = new RegExp('^' + unicodeRegExp.printable.source + '+$');
purify.nonEmptyPrintableUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && nonEmptyPrintableUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/** Convenience shortcuts */
baseMinusTMin = base - tMin,
floor = Math.floor,
stringFromCharCode = String.fromCharCode,
// Visible characters + space, full Unicode repertoire
var printableUnicodeRegExp = new RegExp('^' + unicodeRegExp.printable.source + '*$');
purify.printableUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && printableUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/** Temporary variable */
key;
purify.nonEmptyVisibleAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x21-\x7e]+$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/*--------------------------------------------------------------------------*/
purify.visibleAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x21-\x7e]*$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/**
* A generic error utility function.
* @private
* @param {String} type The error type.
* @returns {Error} Throws a `RangeError` with the applicable error message.
*/
function error(type) {
throw RangeError(errors[type]);
}
purify.nonEmptyPrintableAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x20-\x7e]+$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/**
* A generic `Array#map` utility function.
* @private
* @param {Array} array The array to iterate over.
* @param {Function} callback The function that gets called for every array
* item.
* @returns {Array} A new array of values returned by the callback function.
*/
function map(array, fn) {
var length = array.length;
var result = [];
while (length--) {
result[length] = fn(array[length]);
}
return result;
}
purify.printableAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x20-\x7e]*$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/**
* A simple `Array#map`-like wrapper to work with domain name strings or email
* addresses.
* @private
* @param {String} domain The domain name or email address.
* @param {Function} callback The function that gets called for every
* character.
* @returns {Array} A new string of characters returned by the callback
* function.
*/
function mapDomain(string, fn) {
var labels = string.split(regexSeparators);
// Note: each label could still contain `@` in the case of an email address.
return map(labels, function(label) {
var parts = label.split('@');
return map(parts, fn).join('@');
}).join('.');
}
purify.alphaNumeric = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9]*$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue) && rawValue === Math.floor(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
/**
* Creates an array containing the numeric code points of each Unicode
* character in the string. While JavaScript uses UCS-2 internally,
* this function will convert a pair of surrogate halves (each of which
* UCS-2 exposes as separate characters) into a single code point,
* matching UTF-16.
* @see `punycode.ucs2.encode`
* @see <http://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode.ucs2
* @name decode
* @param {String} string The Unicode input string (UCS-2).
* @returns {Array} The new array of code points.
*/
function ucs2decode(string) {
var output = [],
counter = 0,
length = string.length,
value,
extra;
while (counter < length) {
value = string.charCodeAt(counter++);
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
// high surrogate, and there is a next character
extra = string.charCodeAt(counter++);
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
} else {
// unmatched surrogate; only append this code unit, in case the next
// code unit is the high surrogate of a surrogate pair
output.push(value);
counter--;
}
} else {
output.push(value);
}
}
return output;
}
purify.nonEmptyAlphaNumeric = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9]+$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue) && rawValue === Math.floor(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
/**
* Creates a string based on an array of numeric code points.
* @see `punycode.ucs2.decode`
* @memberOf punycode.ucs2
* @name encode
* @param {Array} codePoints The array of numeric code points.
* @returns {String} The new Unicode string (UCS-2).
*/
function ucs2encode(array) {
return map(array, function(value) {
var output = '';
if (value > 0xFFFF) {
value -= 0x10000;
output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
value = 0xDC00 | value & 0x3FF;
}
output += stringFromCharCode(value);
return output;
}).join('');
}
purify.alphaNumericWithDot = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9\.]*$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
/**
* Converts a basic code point into a digit/integer.
* @see `digitToBasic()`
* @private
* @param {Number} codePoint The basic numeric code point value.
* @returns {Number} The numeric value of a basic code point (for use in
* representing integers) in the range `0` to `base - 1`, or `base` if
* the code point does not represent a value.
*/
function basicToDigit(codePoint) {
if (codePoint - 48 < 10) {
return codePoint - 22;
}
if (codePoint - 65 < 26) {
return codePoint - 65;
}
if (codePoint - 97 < 26) {
return codePoint - 97;
}
return base;
}
purify.nonEmptyAlphaNumericWithDot = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9\.]+$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
/**
* Converts a digit/integer into a basic code point.
* @see `basicToDigit()`
* @private
* @param {Number} digit The numeric value of a basic code point.
* @returns {Number} The basic code point whose value (when used for
* representing integers) is `digit`, which needs to be in the range
* `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
* used; else, the lowercase form is used. The behavior is undefined
* if `flag` is non-zero and `digit` has no uppercase form.
*/
function digitToBasic(digit, flag) {
// 0..25 map to ASCII a..z or A..Z
// 26..35 map to ASCII 0..9
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
}
purify.uuid = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && oneValidation.uuid.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/**
* Bias adaptation function as per section 3.4 of RFC 3492.
* http://tools.ietf.org/html/rfc3492#section-3.4
* @private
*/
function adapt(delta, numPoints, firstTime) {
var k = 0;
delta = firstTime ? floor(delta / damp) : delta >> 1;
delta += floor(delta / numPoints);
for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
delta = floor(delta / baseMinusTMin);
}
return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
}
purify.upperCaseUuid = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && oneValidation.upperCaseUuid.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
/**
* Converts a Punycode string of ASCII-only symbols to a string of Unicode
* symbols.
* @memberOf punycode
* @param {String} input The Punycode string of ASCII-only symbols.
* @returns {String} The resulting string of Unicode symbols.
*/
function decode(input) {
// Don't use UCS-2
var output = [],
inputLength = input.length,
out,
i = 0,
n = initialN,
bias = initialBias,
basic,
j,
index,
oldi,
w,
k,
digit,
t,
/** Cached calculation results */
baseMinusT;
purify.lowerCaseUuid = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && oneValidation.lowerCaseUuid.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
// Handle the basic code points: let `basic` be the number of input code
// points before the last delimiter, or `0` if there is none, then copy
// the first basic code points to the output.
purify.json = function (rawValue, defaultValue) {
if (typeof rawValue === 'string') {
try {
return JSON.parse(rawValue);
} catch (e) {}
}
return defaultValue;
};
basic = input.lastIndexOf(delimiter);
if (basic < 0) {
basic = 0;
}
return purify;
for (j = 0; j < basic; ++j) {
// if it's not a basic code point
if (input.charCodeAt(j) >= 0x80) {
error('not-basic');
}
output.push(input.charCodeAt(j));
}
// Main decoding loop: start just after the last delimiter if any basic code
// points were copied; start at the beginning otherwise.
for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
// `index` is the index of the next character to be consumed.
// Decode a generalized variable-length integer into `delta`,
// which gets added to `i`. The overflow checking is easier
// if we increase `i` as we go, then subtract off its starting
// value at the end to obtain `delta`.
for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
if (index >= inputLength) {
error('invalid-input');
}
digit = basicToDigit(input.charCodeAt(index++));
if (digit >= base || digit > floor((maxInt - i) / w)) {
error('overflow');
}
i += digit * w;
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (digit < t) {
break;
}
baseMinusT = base - t;
if (w > floor(maxInt / baseMinusT)) {
error('overflow');
}
w *= baseMinusT;
}
out = output.length + 1;
bias = adapt(i - oldi, out, oldi == 0);
// `i` was supposed to wrap around from `out` to `0`,
// incrementing `n` each time, so we'll fix that now:
if (floor(i / out) > maxInt - n) {
error('overflow');
}
n += floor(i / out);
i %= out;
// Insert `n` at position `i` of the output
output.splice(i++, 0, n);
}
return ucs2encode(output);
}
/**
* Converts a string of Unicode symbols (e.g. a domain name label) to a
* Punycode string of ASCII-only symbols.
* @memberOf punycode
* @param {String} input The string of Unicode symbols.
* @returns {String} The resulting Punycode string of ASCII-only symbols.
*/
function encode(input) {
var n,
delta,
handledCPCount,
basicLength,
bias,
j,
m,
q,
k,
t,
currentValue,
output = [],
/** `inputLength` will hold the number of code points in `input`. */
inputLength,
/** Cached calculation results */
handledCPCountPlusOne,
baseMinusT,
qMinusT;
// Convert the input in UCS-2 to Unicode
input = ucs2decode(input);
// Cache the length
inputLength = input.length;
// Initialize the state
n = initialN;
delta = 0;
bias = initialBias;
// Handle the basic code points
for (j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue < 0x80) {
output.push(stringFromCharCode(currentValue));
}
}
handledCPCount = basicLength = output.length;
// `handledCPCount` is the number of code points that have been handled;
// `basicLength` is the number of basic code points.
// Finish the basic string - if it is not empty - with a delimiter
if (basicLength) {
output.push(delimiter);
}
// Main encoding loop:
while (handledCPCount < inputLength) {
// All non-basic code points < n have been handled already. Find the next
// larger one:
for (m = maxInt, j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue >= n && currentValue < m) {
m = currentValue;
}
}
// Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
// but guard against overflow
handledCPCountPlusOne = handledCPCount + 1;
if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
error('overflow');
}
delta += (m - n) * handledCPCountPlusOne;
n = m;
for (j = 0; j < inputLength; ++j) {
currentValue = input[j];
if (currentValue < n && ++delta > maxInt) {
error('overflow');
}
if (currentValue == n) {
// Represent delta as a generalized variable-length integer
for (q = delta, k = base; /* no condition */; k += base) {
t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
if (q < t) {
break;
}
qMinusT = q - t;
baseMinusT = base - t;
output.push(
stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
);
q = floor(qMinusT / baseMinusT);
}
output.push(stringFromCharCode(digitToBasic(q, 0)));
bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
delta = 0;
++handledCPCount;
}
}
++delta;
++n;
}
return output.join('');
}
/**
* Converts a Punycode string representing a domain name or an email address
* to Unicode. Only the Punycoded parts of the input will be converted, i.e.
* it doesn't matter if you call it on a string that has already been
* converted to Unicode.
* @memberOf punycode
* @param {String} input The Punycoded domain name or email address to
* convert to Unicode.
* @returns {String} The Unicode representation of the given Punycode
* string.
*/
function toUnicode(input) {
return mapDomain(input, function(string) {
return regexPunycode.test(string)
? decode(string.slice(4).toLowerCase())
: string;
});
}
/**
* Converts a Unicode string representing a domain name or an email address to
* Punycode. Only the non-ASCII parts of the domain name will be converted,
* i.e. it doesn't matter if you call it with a domain that's already in
* ASCII.
* @memberOf punycode
* @param {String} input The domain name or email address to convert, as a
* Unicode string.
* @returns {String} The Punycode representation of the given domain name or
* email address.
*/
function toASCII(input) {
return mapDomain(input, function(string) {
return regexNonASCII.test(string)
? 'xn--' + encode(string)
: string;
});
}
/*--------------------------------------------------------------------------*/
/** Define the public API */
punycode = {
/**
* A string representing the current Punycode.js version number.
* @memberOf punycode
* @type String
*/
'version': '1.3.0',
/**
* An object of methods to convert from JavaScript's internal character
* representation (UCS-2) to Unicode code points, and back.
* @see <http://mathiasbynens.be/notes/javascript-encoding>
* @memberOf punycode
* @type Object
*/
'ucs2': {
'decode': ucs2decode,
'encode': ucs2encode
},
'decode': decode,
'encode': encode,
'toASCII': toASCII,
'toUnicode': toUnicode
};
/** Expose `punycode` */
// Some AMD build optimizers, like r.js, check for specific condition patterns
// like the following:
if (freeExports && freeModule) {
if (module.exports == freeExports) { // in Node.js or RingoJS v0.8.0+
freeModule.exports = punycode;
} else { // in Narwhal or RingoJS v0.7.0-
for (key in punycode) {
punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
}
}
} else { // in Rhino or a web browser
root.punycode = punycode;
}
}(commonjsGlobal));
});
var unicodeRegExp = createCommonjsModule(function (module, exports) {
(function (root, factory) {
// expose unicodeRegExp as
// - an AMD module (require)
// - a node module
{
module.exports = factory();
}
}(commonjsGlobal, function (xregexp) {
var unicodeRegExp = {};
// These are taken from the XRegExp library (see ../extractRegExpsFromXRegExp.js):
unicodeRegExp.letter = /[A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎↃↄⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々〆〱-〵〻〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛥꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ]/;
unicodeRegExp.mark = /[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u08FE\u0900-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C01-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C82\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D02\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u18A9\u1920-\u192B\u1930-\u193B\u19B0-\u19C0\u19C8\u19C9\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1DC0-\u1DE6\u1DFC-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C4\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE26]/;
unicodeRegExp.number = /[0-9²³¹¼-¾٠-٩۰-۹߀-߉०-९০-৯৴-৹੦-੯૦-૯୦-୯୲-୷௦-௲౦-౯౸-౾೦-೯൦-൵๐-๙໐-໙༠-༳၀-၉႐-႙፩-፼ᛮ-ᛰ០-៩៰-៹᠐-᠙᥆-᥏᧐-᧚᪀-᪉᪐-᪙᭐-᭙᮰-᮹᱀-᱉᱐-᱙⁰⁴-⁹₀-₉⅐-ↂↅ-↉①-⒛⓪-⓿❶-➓⳽〇〡-〩〸-〺㆒-㆕㈠-㈩㉈-㉏㉑-㉟㊀-㊉㊱-㊿꘠-꘩ꛦ-ꛯ꠰-꠵꣐-꣙꤀-꤉꧐-꧙꩐-꩙꯰-꯹0-9]/;
unicodeRegExp.punctuation = /[\u0021-\u0023\u0025-\u002A\u002C-\u002F\u003A\u003B\u003F\u0040\u005B-\u005D\u005F\u007B\u007D\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/;
unicodeRegExp.symbol = /[\u0024+<->\u005E`\u007C~¢-¦¨©¬®-±´¸×÷˂-˅˒-˟˥-˫˭˯-˿͵΄΅϶҂֏؆-؈؋؎؏۞۩۽۾߶৲৳৺৻૱୰௳-௺౿൹฿༁-༃༓༕-༗༚-༟༴༶༸྾-࿅࿇-࿌࿎࿏࿕-࿘႞႟᎐-᎙៛᥀᧞-᧿᭡-᭪᭴-᭼᾽᾿-῁῍-῏῝-῟῭-`´῾⁄⁒⁺-⁼₊-₌₠-₹℀℁℃-℆℈℉℔№-℘℞-℣℥℧℩℮℺℻⅀-⅄⅊-⅍⅏←-⌨⌫-⏳␀-␦⑀-⑊⒜-ⓩ─-⛿✁-❧➔-⟄⟇-⟥⟰-⦂⦙-⧗⧜-⧻⧾-⭌⭐-⭙⳥-⳪⺀-⺙⺛-⻳⼀-⿕⿰-⿻〄〒〓〠〶〷〾〿゛゜㆐㆑㆖-㆟㇀-㇣㈀-㈞㈪-㉇㉐㉠-㉿㊊-㊰㋀-㋾㌀-㏿䷀-䷿꒐-꓆꜀-꜖꜠꜡꞉꞊꠨-꠫꠶-꠹꩷-꩹﬩﮲-﯁﷼﷽﹢﹤-﹦﹩$+<->^`|~¢-₩│-○�]/;
unicodeRegExp.separator = /[\u0020\u00A0\u1680\u180E\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]/;
unicodeRegExp.other = /[\u0000-\u001F\u007F-\u009F\u00AD\u0378\u0379\u037F-\u0383\u038B\u038D\u03A2\u0528-\u0530\u0557\u0558\u0560\u0588\u058B-\u058E\u0590\u05C8-\u05CF\u05EB-\u05EF\u05F5-\u0605\u061C\u061D\u06DD\u070E\u070F\u074B\u074C\u07B2-\u07BF\u07FB-\u07FF\u082E\u082F\u083F\u085C\u085D\u085F-\u089F\u08A1\u08AD-\u08E3\u08FF\u0978\u0980\u0984\u098D\u098E\u0991\u0992\u09A9\u09B1\u09B3-\u09B5\u09BA\u09BB\u09C5\u09C6\u09C9\u09CA\u09CF-\u09D6\u09D8-\u09DB\u09DE\u09E4\u09E5\u09FC-\u0A00\u0A04\u0A0B-\u0A0E\u0A11\u0A12\u0A29\u0A31\u0A34\u0A37\u0A3A\u0A3B\u0A3D\u0A43-\u0A46\u0A49\u0A4A\u0A4E-\u0A50\u0A52-\u0A58\u0A5D\u0A5F-\u0A65\u0A76-\u0A80\u0A84\u0A8E\u0A92\u0AA9\u0AB1\u0AB4\u0ABA\u0ABB\u0AC6\u0ACA\u0ACE\u0ACF\u0AD1-\u0ADF\u0AE4\u0AE5\u0AF2-\u0B00\u0B04\u0B0D\u0B0E\u0B11\u0B12\u0B29\u0B31\u0B34\u0B3A\u0B3B\u0B45\u0B46\u0B49\u0B4A\u0B4E-\u0B55\u0B58-\u0B5B\u0B5E\u0B64\u0B65\u0B78-\u0B81\u0B84\u0B8B-\u0B8D\u0B91\u0B96-\u0B98\u0B9B\u0B9D\u0BA0-\u0BA2\u0BA5-\u0BA7\u0BAB-\u0BAD\u0BBA-\u0BBD\u0BC3-\u0BC5\u0BC9\u0BCE\u0BCF\u0BD1-\u0BD6\u0BD8-\u0BE5\u0BFB-\u0C00\u0C04\u0C0D\u0C11\u0C29\u0C34\u0C3A-\u0C3C\u0C45\u0C49\u0C4E-\u0C54\u0C57\u0C5A-\u0C5F\u0C64\u0C65\u0C70-\u0C77\u0C80\u0C81\u0C84\u0C8D\u0C91\u0CA9\u0CB4\u0CBA\u0CBB\u0CC5\u0CC9\u0CCE-\u0CD4\u0CD7-\u0CDD\u0CDF\u0CE4\u0CE5\u0CF0\u0CF3-\u0D01\u0D04\u0D0D\u0D11\u0D3B\u0D3C\u0D45\u0D49\u0D4F-\u0D56\u0D58-\u0D5F\u0D64\u0D65\u0D76-\u0D78\u0D80\u0D81\u0D84\u0D97-\u0D99\u0DB2\u0DBC\u0DBE\u0DBF\u0DC7-\u0DC9\u0DCB-\u0DCE\u0DD5\u0DD7\u0DE0-\u0DF1\u0DF5-\u0E00\u0E3B-\u0E3E\u0E5C-\u0E80\u0E83\u0E85\u0E86\u0E89\u0E8B\u0E8C\u0E8E-\u0E93\u0E98\u0EA0\u0EA4\u0EA6\u0EA8\u0EA9\u0EAC\u0EBA\u0EBE\u0EBF\u0EC5\u0EC7\u0ECE\u0ECF\u0EDA\u0EDB\u0EE0-\u0EFF\u0F48\u0F6D-\u0F70\u0F98\u0FBD\u0FCD\u0FDB-\u0FFF\u10C6\u10C8-\u10CC\u10CE\u10CF\u1249\u124E\u124F\u1257\u1259\u125E\u125F\u1289\u128E\u128F\u12B1\u12B6\u12B7\u12BF\u12C1\u12C6\u12C7\u12D7\u1311\u1316\u1317\u135B\u135C\u137D-\u137F\u139A-\u139F\u13F5-\u13FF\u169D-\u169F\u16F1-\u16FF\u170D\u1715-\u171F\u1737-\u173F\u1754-\u175F\u176D\u1771\u1774-\u177F\u17DE\u17DF\u17EA-\u17EF\u17FA-\u17FF\u180F\u181A-\u181F\u1878-\u187F\u18AB-\u18AF\u18F6-\u18FF\u191D-\u191F\u192C-\u192F\u193C-\u193F\u1941-\u1943\u196E\u196F\u1975-\u197F\u19AC-\u19AF\u19CA-\u19CF\u19DB-\u19DD\u1A1C\u1A1D\u1A5F\u1A7D\u1A7E\u1A8A-\u1A8F\u1A9A-\u1A9F\u1AAE-\u1AFF\u1B4C-\u1B4F\u1B7D-\u1B7F\u1BF4-\u1BFB\u1C38-\u1C3A\u1C4A-\u1C4C\u1C80-\u1CBF\u1CC8-\u1CCF\u1CF7-\u1CFF\u1DE7-\u1DFB\u1F16\u1F17\u1F1E\u1F1F\u1F46\u1F47\u1F4E\u1F4F\u1F58\u1F5A\u1F5C\u1F5E\u1F7E\u1F7F\u1FB5\u1FC5\u1FD4\u1FD5\u1FDC\u1FF0\u1FF1\u1FF5\u1FFF\u200B-\u200F\u202A-\u202E\u2060-\u206F\u2072\u2073\u208F\u209D-\u209F\u20BA-\u20CF\u20F1-\u20FF\u218A-\u218F\u23F4-\u23FF\u2427-\u243F\u244B-\u245F\u2700\u2B4D-\u2B4F\u2B5A-\u2BFF\u2C2F\u2C5F\u2CF4-\u2CF8\u2D26\u2D28-\u2D2C\u2D2E\u2D2F\u2D68-\u2D6E\u2D71-\u2D7E\u2D97-\u2D9F\u2DA7\u2DAF\u2DB7\u2DBF\u2DC7\u2DCF\u2DD7\u2DDF\u2E3C-\u2E7F\u2E9A\u2EF4-\u2EFF\u2FD6-\u2FEF\u2FFC-\u2FFF\u3040\u3097\u3098\u3100-\u3104\u312E-\u3130\u318F\u31BB-\u31BF\u31E4-\u31EF\u321F\u32FF\u4DB6-\u4DBF\u9FCD-\u9FFF\uA48D-\uA48F\uA4C7-\uA4CF\uA62C-\uA63F\uA698-\uA69E\uA6F8-\uA6FF\uA78F\uA794-\uA79F\uA7AB-\uA7F7\uA82C-\uA82F\uA83A-\uA83F\uA878-\uA87F\uA8C5-\uA8CD\uA8DA-\uA8DF\uA8FC-\uA8FF\uA954-\uA95E\uA97D-\uA97F\uA9CE\uA9DA-\uA9DD\uA9E0-\uA9FF\uAA37-\uAA3F\uAA4E\uAA4F\uAA5A\uAA5B\uAA7C-\uAA7F\uAAC3-\uAADA\uAAF7-\uAB00\uAB07\uAB08\uAB0F\uAB10\uAB17-\uAB1F\uAB27\uAB2F-\uABBF\uABEE\uABEF\uABFA-\uABFF\uD7A4-\uD7AF\uD7C7-\uD7CA\uD7FC-\uF8FF\uFA6E\uFA6F\uFADA-\uFAFF\uFB07-\uFB12\uFB18-\uFB1C\uFB37\uFB3D\uFB3F\uFB42\uFB45\uFBC2-\uFBD2\uFD40-\uFD4F\uFD90\uFD91\uFDC8-\uFDEF\uFDFE\uFDFF\uFE1A-\uFE1F\uFE27-\uFE2F\uFE53\uFE67\uFE6C-\uFE6F\uFE75\uFEFD-\uFF00\uFFBF-\uFFC1\uFFC8\uFFC9\uFFD0\uFFD1\uFFD8\uFFD9\uFFDD-\uFFDF\uFFE7\uFFEF-\uFFFB\uFFFE\uFFFF]/; // Other (control, format, private use, surrogate, and unassigned codes)
unicodeRegExp.spliceCharacterClassRegExps = function () { // ...
var args = Array.prototype.slice.call(arguments);
return new RegExp('[' + args.map(function (regExp) {
return regExp.source.replace(/^\[|\]$/g, '');
}).join("") + ']');
};
// All of the above combined, except 'separator', and 'other':
unicodeRegExp.visible = unicodeRegExp.spliceCharacterClassRegExps(
unicodeRegExp.letter,
unicodeRegExp.mark,
unicodeRegExp.number,
unicodeRegExp.punctuation,
unicodeRegExp.symbol
);
// The set of printable characters also includes space:
unicodeRegExp.printable = unicodeRegExp.spliceCharacterClassRegExps(
unicodeRegExp.visible,
unicodeRegExp.separator
);
// Helper function for removing a char from a character class regular expression:
function parseCharCode(u4, x2, literal) {
if (u4 || x2) {
return parseInt(u4 || x2, 16);
} else {
return literal.charCodeAt(0);
}
}
function charCodeToRegExpToken(charCode) {
if (charCode >= 0x20 && charCode < 0x7f) {
return String.fromCharCode(charCode);
} else {
var hexStr = charCode.toString(16);
return "\\u" + "0000".slice(hexStr.length) + hexStr;
}
}
var characterClassToken = /(?:\\u([0-9a-f]{4})|\\x([0-9a-f]{2})|([^\-]))(?:-(?:\\u([0-9a-f]{4})|\\x([0-9a-f]{2})|([^\-])))?/gi;
unicodeRegExp.removeCharacterFromCharacterClassRegExp = function (regExp, ch) {
var charCode = ch.charCodeAt(0);
return new RegExp('[' + regExp.source.replace(/^\[|\]$/g, '').replace(characterClassToken, function ($0, fromU4, fromX2, fromLiteral, toU4, toX2, toLiteral) {
var fromCharCode = parseCharCode(fromU4, fromX2, fromLiteral);
if (toU4 || toX2 || toLiteral) {
var toCharCode = parseCharCode(toU4, toX2, toLiteral);
if (charCode === fromCharCode) {
if (charCode + 1 < toCharCode) {
return charCodeToRegExpToken(charCode + 1) + '-' + charCodeToRegExpToken(toCharCode);
} else {
return charCodeToRegExpToken(toCharCode);
}
} else if (charCode === toCharCode) {
if (fromCharCode < charCode - 1) {
return charCodeToRegExpToken(fromCharCode) + '-' + charCodeToRegExpToken(charCode - 1);
} else {
// fromCharCode === toCharCode - 1, rewrite to single char
return charCodeToRegExpToken(fromCharCode);
}
} else if (charCode > fromCharCode && charCode < toCharCode) {
return charCodeToRegExpToken(fromCharCode) + (charCode > fromCharCode + 1 ? '-' + charCodeToRegExpToken(charCode - 1) : '') +
(charCode + 1 < toCharCode ? charCodeToRegExpToken(charCode + 1) + '-' : '') + charCodeToRegExpToken(toCharCode);
} else {
return $0;
}
} else {
if (charCode === fromCharCode) {
return "";
} else {
return charCodeToRegExpToken(fromCharCode);
}
}
}) + ']');
};
return unicodeRegExp;
}));
});
var purify = (function () {
var purify = {};
purify.boolean = function (rawValue, defaultValue) {
if (typeof rawValue === 'boolean') {
return rawValue;
} else if (typeof rawValue === 'string') {
var isTrue = /^(?:1|on|true|yes)$/i.test(rawValue),
isFalse = /^(?:0|off|false|no)$/i.test(rawValue);
return isTrue ? true : (isFalse ? false : defaultValue);
}
return defaultValue;
};
purify.email = purify.emailAddress = function (rawValue, defaultValue) {
// Should return an email with the domain part in its punycoded form regardless of input
var fragments,
encodedEmail,
encodedDomain;
try {
if (typeof rawValue === 'string' && validation.emailIdn.test(rawValue)) {
fragments = rawValue.split('@');
encodedDomain = fragments.length === 2 && punycode.toASCII(fragments[1]).toLowerCase();
var decodedDomain = punycode.toUnicode(encodedDomain); // Makes sure invalid domains like foo.xn--no aren't allowed
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
encodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
encodedDomain = undefined;
} finally {
encodedEmail = encodedDomain && fragments[0] + '@' + encodedDomain;
if (typeof encodedEmail === 'string' && validation.email.test(encodedEmail)) {
return encodedEmail;
} else {
return defaultValue;
}
}
};
purify.emailIdn = purify.emailAddressIdn = function (rawValue, defaultValue) {
// Should return an email with the domain part in its non-punycoded form regardless of input
var fragments,
decodedDomain,
decodedEmail;
try {
if (typeof rawValue === 'string' && validation.emailIdn.test(rawValue)) {
fragments = rawValue.split('@');
decodedDomain = fragments.length === 2 && punycode.toUnicode(fragments[1]).toLowerCase();
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
decodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
decodedDomain = undefined;
} finally {
decodedEmail = decodedDomain && fragments[0] + '@' + decodedDomain;
if (typeof decodedEmail === 'string' && validation.emailIdn.test(decodedEmail)) {
return decodedEmail;
} else {
return defaultValue;
}
}
};
purify.domain = purify.domainName = function (rawValue, defaultValue) {
// Should return a domain in its punycoded form regardless of input
var encodedDomain;
try {
if (typeof rawValue === 'string' && validation.domainIdn.test(rawValue)) {
encodedDomain = punycode.toASCII(rawValue.toLowerCase());
var decodedDomain = punycode.toUnicode(encodedDomain); // Makes sure that things like foo.xn--no aren't allowed
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
encodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
encodedDomain = undefined;
} finally {
if (typeof encodedDomain === 'string' && validation.domain.test(encodedDomain)) {
return encodedDomain;
} else {
return defaultValue;
}
}
};
purify.domainIdn = purify.domainNameIdn = function (rawValue, defaultValue) {
// Should return a domain in its non-punycoded form regardless of input
var decodedDomain;
try {
if (typeof rawValue === 'string' && validation.domainIdn.test(rawValue)) {
decodedDomain = punycode.toUnicode(rawValue.toLowerCase());
if (!(/\.[^\.]{2,}$/.test(decodedDomain))) {
decodedDomain = undefined; // Sorry, one-letter TLDs still aren't allowed
}
}
} catch (e) {
decodedDomain = undefined;
} finally {
if (typeof decodedDomain === 'string' && validation.domainIdn.test(decodedDomain)) {
return decodedDomain;
} else {
return defaultValue;
}
}
};
purify.url = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && validation.httpUrl.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
var urlWithLocalhostRegExp = new RegExp('^(?:' + validation.createHttpishUrlRegExp({scheme: /https?/, localhost: true}).source + ')$');
purify.urlWithLocalhost = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && urlWithLocalhostRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.integer = function (rawValue, defaultValue) {
var integer;
if (typeof rawValue === 'string') {
integer = parseInt(rawValue, 10);
} else if (typeof rawValue === 'number') {
integer = Math.floor(rawValue);
}
if (typeof integer === 'number' && isFinite(integer) && !isNaN(integer)) {
return integer;
} else {
return defaultValue;
}
};
purify.integerInRange = function (rawValue, lower, upper, defaultValue) {
var integer = purify.integer(rawValue);
if (typeof integer === 'number' && !isNaN(integer) && isFinite(integer) && (typeof lower === 'undefined' || integer >= lower) && (typeof upper === 'undefined' || integer <= upper)) {
return integer;
}
return defaultValue;
};
purify.positiveInteger = function (rawValue, defaultValue) {
var integer = purify.integer(rawValue);
if (typeof integer !== 'undefined' && !isNaN(integer) && isFinite(integer) && integer >= 1) {
return integer;
}
return defaultValue;
};
purify.positiveIntegerOrZero = function (rawValue, defaultValue) {
var integer = purify.integer(rawValue);
if (typeof integer !== 'undefined' && !isNaN(integer) && isFinite(integer) && integer >= 0) {
return integer;
}
return defaultValue;
};
purify.float = function (rawValue, defaultValue) {
var number;
if (typeof rawValue === 'string') {
if (/^[\-+]?[0-9]*\.?[0-9]+$/.test(rawValue)) {
number = parseFloat(rawValue);
}
} else if (typeof rawValue === 'number') {
number = rawValue;
}
if (typeof number !== 'undefined' && !isNaN(number) && isFinite(number)) {
return number;
}
return defaultValue;
};
purify.positiveFloat = function (rawValue, defaultValue) {
var number;
if (typeof rawValue === 'string') {
if (/^\+?[0-9]*\.?[0-9]+$/.test(rawValue)) {
number = parseFloat(rawValue);
}
} else if (typeof rawValue === 'number') {
number = rawValue;
}
if (typeof number !== 'undefined' && !isNaN(number) && isFinite(number) && number > 0) {
return number;
}
return defaultValue;
};
purify.positiveFloatOrZero = function (rawValue, defaultValue) {
var number;
if (typeof rawValue === 'string') {
if (/^\+?[0-9]*\.?[0-9]+$/.test(rawValue)) {
number = parseFloat(rawValue);
}
} else if (typeof rawValue === 'number') {
number = rawValue;
}
if (typeof number !== 'undefined' && !isNaN(number) && isFinite(number) && number >= 0) {
return number;
}
return defaultValue;
};
// Visible characters, full Unicode repertoire
var nonEmptyVisibleUnicodeRegExp = new RegExp('^' + unicodeRegExp.visible.source + '+$');
purify.nonEmptyVisibleUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && nonEmptyVisibleUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
// Visible characters, full Unicode repertoire
var visibleUnicodeRegExp = new RegExp('^' + unicodeRegExp.visible.source + '*$');
purify.visibleUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && visibleUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
// Visible characters + space, full Unicode repertoire
var nonEmptyPrintableUnicodeRegExp = new RegExp('^' + unicodeRegExp.printable.source + '+$');
purify.nonEmptyPrintableUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && nonEmptyPrintableUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
// Visible characters + space, full Unicode repertoire
var printableUnicodeRegExp = new RegExp('^' + unicodeRegExp.printable.source + '*$');
purify.printableUnicode = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && printableUnicodeRegExp.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.nonEmptyVisibleAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x21-\x7e]+$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.visibleAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x21-\x7e]*$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.nonEmptyPrintableAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x20-\x7e]+$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.printableAscii = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[\x20-\x7e]*$/.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.alphaNumeric = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9]*$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue) && rawValue === Math.floor(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
purify.nonEmptyAlphaNumeric = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9]+$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue) && rawValue === Math.floor(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
purify.alphaNumericWithDot = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9\.]*$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
purify.nonEmptyAlphaNumericWithDot = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && /^[a-z0-9\.]+$/i.test(rawValue)) {
return rawValue;
} else if (typeof rawValue === 'number' && isFinite(rawValue) && !isNaN(rawValue)) {
return String(rawValue);
}
return defaultValue;
};
purify.uuid = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && validation.uuid.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.upperCaseUuid = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && validation.upperCaseUuid.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.lowerCaseUuid = function (rawValue, defaultValue) {
if (typeof rawValue === 'string' && validation.lowerCaseUuid.test(rawValue)) {
return rawValue;
}
return defaultValue;
};
purify.json = function (rawValue, defaultValue) {
if (typeof rawValue === 'string') {
try {
return JSON.parse(rawValue);
} catch (e) {}
}
return defaultValue;
};
return purify;
})();
return purify;
}));
//# sourceMappingURL=purify.js.map

@@ -13,9 +13,11 @@ {

"scripts": {
"prepublish": "make test",
"prepack": "npm test && npm run build",
"build": "rollup -c",
"lint": "jshint .",
"test": "make test",
"travis": "npm run lint && NODE_ENV=development ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"coverage": "NODE_ENV=development ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot"
"pretest": "npm run build",
"test": "mocha",
"test-browser": "npm run build && karma start --single-run --browsers ${BROWSER:-ChromeHeadless}",
"coverage": "nyc --reporter=lcov --reporter=text npm test"
},
"version": "3.3.1",
"version": "3.4.0",
"engines": {

@@ -30,7 +32,15 @@ "node": ">=0.4.0"

"devDependencies": {
"coveralls": "2.11.1",
"coveralls": "^3.0.6",
"istanbul": "0.3.0",
"jshint": "2.5.2",
"mocha": "1.12.0",
"unexpected": "3.0.1"
"karma": "^4.2.0",
"karma-chrome-launcher": "^3.0.0",
"karma-mocha": "^1.3.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"rollup": "^1.19.4",
"rollup-plugin-commonjs": "^10.0.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"unexpected": "^10.40.2"
},

@@ -37,0 +47,0 @@ "main": "lib/purify.js",

purify
======
[![NPM version](https://badge.fury.io/js/purify.png)](http://badge.fury.io/js/purify)
[![Build Status](https://travis-ci.org/One-com/purify.png?branch=master)](https://travis-ci.org/One-com/purify)
[![Coverage Status](https://coveralls.io/repos/One-com/purify/badge.png)](https://coveralls.io/r/One-com/purify)
[![Dependency Status](https://david-dm.org/One-com/purify.png)](https://david-dm.org/One-com/purify)
[![NPM version](https://img.shields.io/npm/v/purify)](https://www.npmjs.com/package/purify)
[![Build Status](https://travis-ci.org/One-com/purify.svg?branch=master)](https://travis-ci.org/One-com/purify)
[![Coverage Status](https://coveralls.io/repos/github/One-com/purify/badge.svg?branch=master)](https://coveralls.io/github/One-com/purify?branch=master)
[![Dependency Status](https://david-dm.org/One-com/purify.svg)](https://david-dm.org/One-com/purify)
The library provides a number of battle tested validation functions. Each returns the
value supplied or a `defaultValue`. Mostly, you can leave `defaultValue` empty, which
will cause purify to return `undefined` in case the value doesn't pass validation.
Usage
-----
The library can be installed by simply installing `purify` from npm and can be used
body on node with `require('purify')` or as a self-contained UMD browser bundle that
can be used directly in a script tag as follows:
`<script src="./node_modules/lib/purify.js">`
Example
-------
```javascript

@@ -63,5 +76,1 @@ var app = express(),

* `.json(rawValue, defaultValue)`
Mostly, you can leave `defaultValue` empty, which will cause purify to return
`undefined` in case the value doesn't pass validation.

@@ -1,6 +0,7 @@

/*global it, describe*/
var purify = require('../lib/purify'),
unexpected = require('unexpected'),
bogusDefaultValue = {};
/*globals window, it, describe*/
var purify = typeof window !== 'undefined' ? window.purify : require('../lib/purify');
var unexpected = typeof window !== 'undefined' ? window.weknowhow.expect : require('unexpected');
var bogusDefaultValue = {};
function equalsWithEpsilon(valueToCompareTo, epsilon) {

@@ -7,0 +8,0 @@ if (typeof epsilon === 'undefined') {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet