diff --git a/benchmark/suite.js b/benchmark/suite.js new file mode 100644 index 0000000..284301d --- /dev/null +++ b/benchmark/suite.js @@ -0,0 +1,126 @@ +import vm from 'node:vm'; +import benchmark from 'benchmark'; +import psl from '../index.js'; + +const runSuite = ({ module, version }) => new Promise((resolve, reject) => { + const suite = new benchmark.Suite(version); + + suite.add('psl#isValid', { + fn: () => { + module.isValid('google.com'); + } + }); + + suite.add('psl#parse', { + fn: () => { + module.parse('google.com'); + } + }); + + suite.add('psl#parse invalid domain', { + fn: () => { + module.parse('google.comp'); + } + }); + + suite.on('error', reject); + + suite.on('complete', () => { + resolve(suite.map(test => ({ version, ...test }))); + }); + + suite.run({ async: true }); +}); + +const runSuites = (suites) => { + const recurse = async (remaining, memo) => { + if (!remaining.length) { + return memo; + } + + return recurse(remaining.slice(1), memo.concat(await runSuite(remaining[0]))); + }; + + return recurse(suites, []) +}; + +const printResults = (results, compareToVersion) => { + const parsedResults = results.map(result => ({ + version: result.version, + name: result.name, + 'ops/sec': parseInt(result.hz.toFixed(result.hz < 100 ? 2 : 0), 10), + '\xb1 %': parseFloat(result.stats.rme.toFixed(2), 10), + 'runs sampled': result.stats.sample.length, + })); + + console.table(parsedResults.reduce( + (memo, { version, name, ...rest }) => ({ + ...memo, + [`[${version}] ${name}`]: rest, + }), + {}, + )); + + const resultsByFunc = parsedResults.reduce( + (memo, result) => ({ + ...memo, + [result.name]: { + ...memo[result.name], + [result.version]: result['ops/sec'], + }, + }), + {}, + ); + + const resultsByFuncSummary = Object.keys(resultsByFunc).reduce( + (memo, name) => { + const sourceOpsXSec = parseInt(resultsByFunc[name].source, 10); + const compareToOpsXSec = parseInt(resultsByFunc[name][compareToVersion], 10); + const diff = ( + sourceOpsXSec > compareToOpsXSec + ? `${(sourceOpsXSec / compareToOpsXSec).toFixed(2)}x up` + : `${(compareToOpsXSec / sourceOpsXSec).toFixed(2)}x down` + ); + + return memo.concat({ + name, + ...resultsByFunc[name], + diff, + }); + }, + [], + ); + + console.table(resultsByFuncSummary.reduce( + (memo, { name, ...rest }) => ({ ...memo, [name]: rest }), + {}, + )); +}; + +const fetchModule = async (version) => { + const url = `https://unpkg.com/psl@${version}/dist/psl.mjs`; + const response = await fetch(url); + const text = await response.text(); + const mod = new vm.SourceTextModule(text); + + await mod.link(() => { }); + await mod.evaluate(); + + return mod.namespace; +}; + +const main = async () => { + const compareToVersion = 'v1.13.0'; + + const results = await runSuites([ + { module: psl, version: 'source' }, + { module: await fetchModule(compareToVersion), version: compareToVersion }, + ]); + + printResults(results, compareToVersion); +}; + +main().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/dist/psl.cjs b/dist/psl.cjs index 8b464f2..bed0447 100644 --- a/dist/psl.cjs +++ b/dist/psl.cjs @@ -1 +1 @@ -"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function H(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}const b=2147483647,p=36,q=1,y=26,N=38,R=700,O=72,S=128,I="-",V=/^xn--/,W=/[^\0-\x7F]/,P=/[\x2E\u3002\uFF0E\uFF61]/g,G={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},z=p-q,u=Math.floor,x=String.fromCharCode;function h(a){throw new RangeError(G[a])}function U(a,s){const e=[];let o=a.length;for(;o--;)e[o]=s(a[o]);return e}function C(a,s){const e=a.split("@");let o="";e.length>1&&(o=e[0]+"@",a=e[1]),a=a.replace(P,".");const i=a.split("."),n=U(i,s).join(".");return o+n}function L(a){const s=[];let e=0;const o=a.length;for(;e=55296&&i<=56319&&eString.fromCodePoint(...a),J=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:p},_=function(a,s){return a+22+75*(a<26)-((s!=0)<<5)},T=function(a,s,e){let o=0;for(a=e?u(a/R):a>>1,a+=u(a/s);a>z*y>>1;o+=p)a=u(a/z);return u(o+(z+1)*a/(a+N))},D=function(a){const s=[],e=a.length;let o=0,i=S,n=O,r=a.lastIndexOf(I);r<0&&(r=0);for(let t=0;t=128&&h("not-basic"),s.push(a.charCodeAt(t));for(let t=r>0?r+1:0;t=e&&h("invalid-input");const l=J(a.charCodeAt(t++));l>=p&&h("invalid-input"),l>u((b-o)/c)&&h("overflow"),o+=l*c;const j=k<=n?q:k>=n+y?y:k-n;if(lu(b/w)&&h("overflow"),c*=w}const g=s.length+1;n=T(o-m,g,m==0),u(o/g)>b-i&&h("overflow"),i+=u(o/g),o%=g,s.splice(o++,0,i)}return String.fromCodePoint(...s)},E=function(a){const s=[];a=L(a);const e=a.length;let o=S,i=0,n=O;for(const m of a)m<128&&s.push(x(m));const r=s.length;let t=r;for(r&&s.push(I);t=o&&cu((b-i)/g)&&h("overflow"),i+=(m-o)*g,o=m;for(const c of a)if(cb&&h("overflow"),c===o){let k=i;for(let l=p;;l+=p){const j=l<=n?q:l>=n+y?y:l-n;if(k255)return"DOMAIN_TOO_LONG";for(var e=s.split("."),o,i=0;i63)return"LABEL_TOO_LONG";if(o.charAt(0)==="-")return"LABEL_STARTS_WITH_DASH";if(o.charAt(o.length-1)==="-")return"LABEL_ENDS_WITH_DASH";if(!/^[a-z0-9\-_]+$/.test(o))return"LABEL_INVALID_CHARS"}};const f=function(a){if(typeof a!="string")throw new TypeError("Domain name must be a string.");var s=a.slice(0).toLowerCase();s.charAt(s.length-1)==="."&&(s=s.slice(0,s.length-1));var e=d.validate(s);if(e)return{input:a,error:{message:B[e],code:e}};var o={input:a,tld:null,sld:null,domain:null,subdomain:null,listed:!1},i=s.split(".");if(i[i.length-1]==="local")return o;var n=function(){return/xn--/.test(s)&&(o.domain&&(o.domain=v.toASCII(o.domain)),o.subdomain&&(o.subdomain=v.toASCII(o.subdomain))),o},r=d.findRule(s);if(!r)return i.length<2?o:(o.tld=i.pop(),o.sld=i.pop(),o.domain=[o.sld,o.tld].join("."),i.length&&(o.subdomain=i.pop()),n());o.listed=!0;var t=r.suffix.split("."),m=i.slice(0,i.length-t.length);return r.exception&&m.push(t.shift()),o.tld=t.join("."),!m.length||(r.wildcard&&(t.unshift(m.pop()),o.tld=t.join(".")),!m.length)||(o.sld=m.pop(),o.domain=[o.sld,o.tld].join("."),m.length&&(o.subdomain=m.join("."))),n()},M=function(a){return a&&f(a).domain||null},F=function(a){var s=f(a);return!!(s.domain&&s.listed)},aa={parse:f,get:M,isValid:F};exports.default=aa;exports.errorCodes=B;exports.get=M;exports.isValid=F;exports.parse=f; +"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function H(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}const j=2147483647,p=36,q=1,w=26,N=38,R=700,C=72,O=128,I="-",V=/^xn--/,P=/[^\0-\x7F]/,G=/[\x2E\u3002\uFF0E\uFF61]/g,W={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},z=p-q,u=Math.floor,x=String.fromCharCode;function h(a){throw new RangeError(W[a])}function $(a,s){const e=[];let o=a.length;for(;o--;)e[o]=s(a[o]);return e}function S(a,s){const e=a.split("@");let o="";e.length>1&&(o=e[0]+"@",a=e[1]),a=a.replace(G,".");const i=a.split("."),n=$(i,s).join(".");return o+n}function L(a){const s=[];let e=0;const o=a.length;for(;e=55296&&i<=56319&&eString.fromCodePoint(...a),J=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:p},_=function(a,s){return a+22+75*(a<26)-((s!=0)<<5)},D=function(a,s,e){let o=0;for(a=e?u(a/R):a>>1,a+=u(a/s);a>z*w>>1;o+=p)a=u(a/z);return u(o+(z+1)*a/(a+N))},T=function(a){const s=[],e=a.length;let o=0,i=O,n=C,r=a.lastIndexOf(I);r<0&&(r=0);for(let t=0;t=128&&h("not-basic"),s.push(a.charCodeAt(t));for(let t=r>0?r+1:0;t=e&&h("invalid-input");const l=J(a.charCodeAt(t++));l>=p&&h("invalid-input"),l>u((j-o)/c)&&h("overflow"),o+=l*c;const d=k<=n?q:k>=n+w?w:k-n;if(lu(j/b)&&h("overflow"),c*=b}const g=s.length+1;n=D(o-m,g,m==0),u(o/g)>j-i&&h("overflow"),i+=u(o/g),o%=g,s.splice(o++,0,i)}return String.fromCodePoint(...s)},E=function(a){const s=[];a=L(a);const e=a.length;let o=O,i=0,n=C;for(const m of a)m<128&&s.push(x(m));const r=s.length;let t=r;for(r&&s.push(I);t=o&&cu((j-i)/g)&&h("overflow"),i+=(m-o)*g,o=m;for(const c of a)if(cj&&h("overflow"),c===o){let k=i;for(let l=p;;l+=p){const d=l<=n?q:l>=n+w?w:l-n;if(k{const e=s.replace(/^(\*\.|\!)/,""),o=y.toASCII(e),i=s.charAt(0);if(a.has(o))throw new Error(`Multiple rules found for ${s} (${o})`);return a.set(o,{rule:s,suffix:e,punySuffix:o,wildcard:i==="*",exception:i==="!"}),a},new Map);v.findRule=function(a){for(var s=y.toASCII(a),e=s.split("."),o=0;o255)return"DOMAIN_TOO_LONG";for(var e=s.split("."),o,i=0;i63)return"LABEL_TOO_LONG";if(o.charAt(0)==="-")return"LABEL_STARTS_WITH_DASH";if(o.charAt(o.length-1)==="-")return"LABEL_ENDS_WITH_DASH";if(!/^[a-z0-9\-_]+$/.test(o))return"LABEL_INVALID_CHARS"}};const f=function(a){if(typeof a!="string")throw new TypeError("Domain name must be a string.");var s=a.slice(0).toLowerCase();s.charAt(s.length-1)==="."&&(s=s.slice(0,s.length-1));var e=v.validate(s);if(e)return{input:a,error:{message:B[e],code:e}};var o={input:a,tld:null,sld:null,domain:null,subdomain:null,listed:!1},i=s.split(".");if(i[i.length-1]==="local")return o;var n=function(){return/xn--/.test(s)&&(o.domain&&(o.domain=y.toASCII(o.domain)),o.subdomain&&(o.subdomain=y.toASCII(o.subdomain))),o},r=v.findRule(s);if(!r)return i.length<2?o:(o.tld=i.pop(),o.sld=i.pop(),o.domain=[o.sld,o.tld].join("."),i.length&&(o.subdomain=i.pop()),n());o.listed=!0;var t=r.suffix.split("."),m=i.slice(0,i.length-t.length);return r.exception&&m.push(t.shift()),o.tld=t.join("."),!m.length||(r.wildcard&&(t.unshift(m.pop()),o.tld=t.join(".")),!m.length)||(o.sld=m.pop(),o.domain=[o.sld,o.tld].join("."),m.length&&(o.subdomain=m.join("."))),n()},M=function(a){return a&&f(a).domain||null},F=function(a){var s=f(a);return!!(s.domain&&s.listed)},oa={parse:f,get:M,isValid:F};exports.default=oa;exports.errorCodes=B;exports.get=M;exports.isValid=F;exports.parse=f; diff --git a/dist/psl.mjs b/dist/psl.mjs index 9c36343..9d5131d 100644 --- a/dist/psl.mjs +++ b/dist/psl.mjs @@ -1,7 +1,7 @@ function B(a) { return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a; } -const b = 2147483647, p = 36, x = 1, y = 26, F = 38, H = 700, O = 72, I = 128, S = "-", N = /^xn--/, M = /[^\0-\x7F]/, R = /[\x2E\u3002\uFF0E\uFF61]/g, V = { +const j = 2147483647, p = 36, x = 1, w = 26, M = 38, F = 700, C = 72, I = 128, O = "-", H = /^xn--/, N = /[^\0-\x7F]/, R = /[\x2E\u3002\uFF0E\uFF61]/g, V = { overflow: "Overflow: input needs wider integers to process", "not-basic": "Illegal input >= 0x80 (not a basic code point)", "invalid-input": "Invalid input" @@ -9,21 +9,21 @@ const b = 2147483647, p = 36, x = 1, y = 26, F = 38, H = 700, O = 72, I = 128, S function h(a) { throw new RangeError(V[a]); } -function W(a, s) { +function P(a, s) { const e = []; let o = a.length; for (; o--; ) e[o] = s(a[o]); return e; } -function C(a, s) { +function L(a, s) { const e = a.split("@"); let o = ""; e.length > 1 && (o = e[0] + "@", a = e[1]), a = a.replace(R, "."); - const i = a.split("."), n = W(i, s).join("."); + const i = a.split("."), n = P(i, s).join("."); return o + n; } -function L(a) { +function S(a) { const s = []; let e = 0; const o = a.length; @@ -37,18 +37,18 @@ function L(a) { } return s; } -const G = (a) => String.fromCodePoint(...a), P = function(a) { +const G = (a) => String.fromCodePoint(...a), W = function(a) { return a >= 48 && a < 58 ? 26 + (a - 48) : a >= 65 && a < 91 ? a - 65 : a >= 97 && a < 123 ? a - 97 : p; }, _ = function(a, s) { return a + 22 + 75 * (a < 26) - ((s != 0) << 5); }, D = function(a, s, e) { let o = 0; - for (a = e ? u(a / H) : a >> 1, a += u(a / s); a > f * y >> 1; o += p) + for (a = e ? u(a / F) : a >> 1, a += u(a / s); a > f * w >> 1; o += p) a = u(a / f); - return u(o + (f + 1) * a / (a + F)); + return u(o + (f + 1) * a / (a + M)); }, T = function(a) { const s = [], e = a.length; - let o = 0, i = I, n = O, r = a.lastIndexOf(S); + let o = 0, i = I, n = C, r = a.lastIndexOf(O); r < 0 && (r = 0); for (let t = 0; t < r; ++t) a.charCodeAt(t) >= 128 && h("not-basic"), s.push(a.charCodeAt(t)); @@ -56,57 +56,57 @@ const G = (a) => String.fromCodePoint(...a), P = function(a) { const m = o; for (let c = 1, k = p; ; k += p) { t >= e && h("invalid-input"); - const l = P(a.charCodeAt(t++)); - l >= p && h("invalid-input"), l > u((b - o) / c) && h("overflow"), o += l * c; - const j = k <= n ? x : k >= n + y ? y : k - n; - if (l < j) + const l = W(a.charCodeAt(t++)); + l >= p && h("invalid-input"), l > u((j - o) / c) && h("overflow"), o += l * c; + const d = k <= n ? x : k >= n + w ? w : k - n; + if (l < d) break; - const w = p - j; - c > u(b / w) && h("overflow"), c *= w; + const b = p - d; + c > u(j / b) && h("overflow"), c *= b; } const g = s.length + 1; - n = D(o - m, g, m == 0), u(o / g) > b - i && h("overflow"), i += u(o / g), o %= g, s.splice(o++, 0, i); + n = D(o - m, g, m == 0), u(o / g) > j - i && h("overflow"), i += u(o / g), o %= g, s.splice(o++, 0, i); } return String.fromCodePoint(...s); }, E = function(a) { const s = []; - a = L(a); + a = S(a); const e = a.length; - let o = I, i = 0, n = O; + let o = I, i = 0, n = C; for (const m of a) m < 128 && s.push(z(m)); const r = s.length; let t = r; - for (r && s.push(S); t < e; ) { - let m = b; + for (r && s.push(O); t < e; ) { + let m = j; for (const c of a) c >= o && c < m && (m = c); const g = t + 1; - m - o > u((b - i) / g) && h("overflow"), i += (m - o) * g, o = m; + m - o > u((j - i) / g) && h("overflow"), i += (m - o) * g, o = m; for (const c of a) - if (c < o && ++i > b && h("overflow"), c === o) { + if (c < o && ++i > j && h("overflow"), c === o) { let k = i; for (let l = p; ; l += p) { - const j = l <= n ? x : l >= n + y ? y : l - n; - if (k < j) + const d = l <= n ? x : l >= n + w ? w : l - n; + if (k < d) break; - const w = k - j, A = p - j; + const b = k - d, A = p - d; s.push( - z(_(j + w % A, 0)) - ), k = u(w / A); + z(_(d + b % A, 0)) + ), k = u(b / A); } s.push(z(_(k, 0))), n = D(i, g, t === r), i = 0, ++t; } ++i, ++o; } return s.join(""); -}, U = function(a) { - return C(a, function(s) { - return N.test(s) ? T(s.slice(4).toLowerCase()) : s; - }); }, $ = function(a) { - return C(a, function(s) { - return M.test(s) ? "xn--" + E(s) : s; + return L(a, function(s) { + return H.test(s) ? T(s.slice(4).toLowerCase()) : s; + }); +}, U = function(a) { + return L(a, function(s) { + return N.test(s) ? "xn--" + E(s) : s; }); }, J = { /** @@ -123,16 +123,16 @@ const G = (a) => String.fromCodePoint(...a), P = function(a) { * @type Object */ ucs2: { - decode: L, + decode: S, encode: G }, decode: T, encode: E, - toASCII: $, - toUnicode: U + toASCII: U, + toUnicode: $ }; var K = J; -const v = /* @__PURE__ */ B(K), Q = [ +const y = /* @__PURE__ */ B(K), Q = [ "ac", "com.ac", "edu.ac", @@ -9903,26 +9903,31 @@ const v = /* @__PURE__ */ B(K), Q = [ "virtualserver.io", "enterprisecloud.nu" ]; -var d = {}; -d.rules = Q.map(function(a) { - return { - rule: a, - suffix: a.replace(/^(\*\.|\!)/, ""), - punySuffix: -1, - wildcard: a.charAt(0) === "*", - exception: a.charAt(0) === "!" - }; -}); -d.endsWith = function(a, s) { - return a.indexOf(s, a.length - s.length) !== -1; -}; -d.findRule = function(a) { - var s = v.toASCII(a); - return d.rules.reduce(function(e, o) { - return o.punySuffix === -1 && (o.punySuffix = v.toASCII(o.suffix)), !d.endsWith(s, "." + o.punySuffix) && s !== o.punySuffix ? e : o; - }, null); +var v = {}; +const X = Q.reduce( + (a, s) => { + const e = s.replace(/^(\*\.|\!)/, ""), o = y.toASCII(e), i = s.charAt(0); + if (a.has(o)) + throw new Error(`Multiple rules found for ${s} (${o})`); + return a.set(o, { + rule: s, + suffix: e, + punySuffix: o, + wildcard: i === "*", + exception: i === "!" + }), a; + }, + /* @__PURE__ */ new Map() +); +v.findRule = function(a) { + for (var s = y.toASCII(a), e = s.split("."), o = 0; o < e.length; o++) { + var i = e.slice(o).join("."), n = X.get(i); + if (n) + return n; + } + return null; }; -const X = { +const Y = { DOMAIN_TOO_SHORT: "Domain name too short.", DOMAIN_TOO_LONG: "Domain name too long. It should be no more than 255 chars.", LABEL_STARTS_WITH_DASH: "Domain name label can not start with a dash.", @@ -9931,8 +9936,8 @@ const X = { LABEL_TOO_SHORT: "Domain name label should be at least 1 character long.", LABEL_INVALID_CHARS: "Domain name label can only contain alphanumeric characters or dashes." }; -d.validate = function(a) { - var s = v.toASCII(a); +v.validate = function(a) { + var s = y.toASCII(a); if (s.length < 1) return "DOMAIN_TOO_SHORT"; if (s.length > 255) @@ -9955,12 +9960,12 @@ const q = function(a) { throw new TypeError("Domain name must be a string."); var s = a.slice(0).toLowerCase(); s.charAt(s.length - 1) === "." && (s = s.slice(0, s.length - 1)); - var e = d.validate(s); + var e = v.validate(s); if (e) return { input: a, error: { - message: X[e], + message: Y[e], code: e } }; @@ -9975,23 +9980,23 @@ const q = function(a) { if (i[i.length - 1] === "local") return o; var n = function() { - return /xn--/.test(s) && (o.domain && (o.domain = v.toASCII(o.domain)), o.subdomain && (o.subdomain = v.toASCII(o.subdomain))), o; - }, r = d.findRule(s); + return /xn--/.test(s) && (o.domain && (o.domain = y.toASCII(o.domain)), o.subdomain && (o.subdomain = y.toASCII(o.subdomain))), o; + }, r = v.findRule(s); if (!r) return i.length < 2 ? o : (o.tld = i.pop(), o.sld = i.pop(), o.domain = [o.sld, o.tld].join("."), i.length && (o.subdomain = i.pop()), n()); o.listed = !0; var t = r.suffix.split("."), m = i.slice(0, i.length - t.length); return r.exception && m.push(t.shift()), o.tld = t.join("."), !m.length || (r.wildcard && (t.unshift(m.pop()), o.tld = t.join(".")), !m.length) || (o.sld = m.pop(), o.domain = [o.sld, o.tld].join("."), m.length && (o.subdomain = m.join("."))), n(); -}, Y = function(a) { - return a && q(a).domain || null; }, Z = function(a) { + return a && q(a).domain || null; +}, aa = function(a) { var s = q(a); return !!(s.domain && s.listed); -}, aa = { parse: q, get: Y, isValid: Z }; +}, oa = { parse: q, get: Z, isValid: aa }; export { - aa as default, - X as errorCodes, - Y as get, - Z as isValid, + oa as default, + Y as errorCodes, + Z as get, + aa as isValid, q as parse }; diff --git a/dist/psl.umd.cjs b/dist/psl.umd.cjs index 2faa485..394d0f7 100644 --- a/dist/psl.umd.cjs +++ b/dist/psl.umd.cjs @@ -1 +1 @@ -(function(p,y){typeof exports=="object"&&typeof module!="undefined"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(p=typeof globalThis!="undefined"?globalThis:p||self,y(p.psl={}))})(this,function(p){"use strict";function y(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}const w=2147483647,u=36,q=1,v=26,R=38,V=700,S=72,I=128,O="-",W=/^xn--/,P=/[^\0-\x7F]/,G=/[\x2E\u3002\uFF0E\uFF61]/g,U={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},A=u-q,k=Math.floor,_=String.fromCharCode;function h(a){throw new RangeError(U[a])}function $(a,s){const e=[];let o=a.length;for(;o--;)e[o]=s(a[o]);return e}function C(a,s){const e=a.split("@");let o="";e.length>1&&(o=e[0]+"@",a=e[1]),a=a.replace(G,".");const i=a.split("."),n=$(i,s).join(".");return o+n}function L(a){const s=[];let e=0;const o=a.length;for(;e=55296&&i<=56319&&eString.fromCodePoint(...a),K=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:u},T=function(a,s){return a+22+75*(a<26)-((s!=0)<<5)},D=function(a,s,e){let o=0;for(a=e?k(a/V):a>>1,a+=k(a/s);a>A*v>>1;o+=u)a=k(a/A);return k(o+(A+1)*a/(a+R))},E=function(a){const s=[],e=a.length;let o=0,i=I,n=S,r=a.lastIndexOf(O);r<0&&(r=0);for(let t=0;t=128&&h("not-basic"),s.push(a.charCodeAt(t));for(let t=r>0?r+1:0;t=e&&h("invalid-input");const g=K(a.charCodeAt(t++));g>=u&&h("invalid-input"),g>k((w-o)/c)&&h("overflow"),o+=g*c;const b=l<=n?q:l>=n+v?v:l-n;if(gk(w/z)&&h("overflow"),c*=z}const j=s.length+1;n=D(o-m,j,m==0),k(o/j)>w-i&&h("overflow"),i+=k(o/j),o%=j,s.splice(o++,0,i)}return String.fromCodePoint(...s)},B=function(a){const s=[];a=L(a);const e=a.length;let o=I,i=0,n=S;for(const m of a)m<128&&s.push(_(m));const r=s.length;let t=r;for(r&&s.push(O);t=o&&ck((w-i)/j)&&h("overflow"),i+=(m-o)*j,o=m;for(const c of a)if(cw&&h("overflow"),c===o){let l=i;for(let g=u;;g+=u){const b=g<=n?q:g>=n+v?v:g-n;if(l255)return"DOMAIN_TOO_LONG";for(var e=s.split("."),o,i=0;i63)return"LABEL_TOO_LONG";if(o.charAt(0)==="-")return"LABEL_STARTS_WITH_DASH";if(o.charAt(o.length-1)==="-")return"LABEL_ENDS_WITH_DASH";if(!/^[a-z0-9\-_]+$/.test(o))return"LABEL_INVALID_CHARS"}};const x=function(a){if(typeof a!="string")throw new TypeError("Domain name must be a string.");var s=a.slice(0).toLowerCase();s.charAt(s.length-1)==="."&&(s=s.slice(0,s.length-1));var e=d.validate(s);if(e)return{input:a,error:{message:M[e],code:e}};var o={input:a,tld:null,sld:null,domain:null,subdomain:null,listed:!1},i=s.split(".");if(i[i.length-1]==="local")return o;var n=function(){return/xn--/.test(s)&&(o.domain&&(o.domain=f.toASCII(o.domain)),o.subdomain&&(o.subdomain=f.toASCII(o.subdomain))),o},r=d.findRule(s);if(!r)return i.length<2?o:(o.tld=i.pop(),o.sld=i.pop(),o.domain=[o.sld,o.tld].join("."),i.length&&(o.subdomain=i.pop()),n());o.listed=!0;var t=r.suffix.split("."),m=i.slice(0,i.length-t.length);return r.exception&&m.push(t.shift()),o.tld=t.join("."),!m.length||(r.wildcard&&(t.unshift(m.pop()),o.tld=t.join(".")),!m.length)||(o.sld=m.pop(),o.domain=[o.sld,o.tld].join("."),m.length&&(o.subdomain=m.join("."))),n()},F=function(a){return a&&x(a).domain||null},H=function(a){var s=x(a);return!!(s.domain&&s.listed)},Y={parse:x,get:F,isValid:H};p.default=Y,p.errorCodes=M,p.get=F,p.isValid=H,p.parse=x,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); +(function(p,w){typeof exports=="object"&&typeof module!="undefined"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(p=typeof globalThis!="undefined"?globalThis:p||self,w(p.psl={}))})(this,function(p){"use strict";function w(a){return a&&a.__esModule&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a}const b=2147483647,u=36,q=1,y=26,R=38,V=700,C=72,I=128,O="-",P=/^xn--/,G=/[^\0-\x7F]/,W=/[\x2E\u3002\uFF0E\uFF61]/g,U={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},A=u-q,k=Math.floor,_=String.fromCharCode;function h(a){throw new RangeError(U[a])}function $(a,s){const e=[];let o=a.length;for(;o--;)e[o]=s(a[o]);return e}function S(a,s){const e=a.split("@");let o="";e.length>1&&(o=e[0]+"@",a=e[1]),a=a.replace(W,".");const i=a.split("."),n=$(i,s).join(".");return o+n}function L(a){const s=[];let e=0;const o=a.length;for(;e=55296&&i<=56319&&eString.fromCodePoint(...a),K=function(a){return a>=48&&a<58?26+(a-48):a>=65&&a<91?a-65:a>=97&&a<123?a-97:u},T=function(a,s){return a+22+75*(a<26)-((s!=0)<<5)},D=function(a,s,e){let o=0;for(a=e?k(a/V):a>>1,a+=k(a/s);a>A*y>>1;o+=u)a=k(a/A);return k(o+(A+1)*a/(a+R))},E=function(a){const s=[],e=a.length;let o=0,i=I,n=C,r=a.lastIndexOf(O);r<0&&(r=0);for(let t=0;t=128&&h("not-basic"),s.push(a.charCodeAt(t));for(let t=r>0?r+1:0;t=e&&h("invalid-input");const g=K(a.charCodeAt(t++));g>=u&&h("invalid-input"),g>k((b-o)/c)&&h("overflow"),o+=g*c;const j=l<=n?q:l>=n+y?y:l-n;if(gk(b/f)&&h("overflow"),c*=f}const d=s.length+1;n=D(o-m,d,m==0),k(o/d)>b-i&&h("overflow"),i+=k(o/d),o%=d,s.splice(o++,0,i)}return String.fromCodePoint(...s)},B=function(a){const s=[];a=L(a);const e=a.length;let o=I,i=0,n=C;for(const m of a)m<128&&s.push(_(m));const r=s.length;let t=r;for(r&&s.push(O);t=o&&ck((b-i)/d)&&h("overflow"),i+=(m-o)*d,o=m;for(const c of a)if(cb&&h("overflow"),c===o){let l=i;for(let g=u;;g+=u){const j=g<=n?q:g>=n+y?y:g-n;if(l{const e=s.replace(/^(\*\.|\!)/,""),o=v.toASCII(e),i=s.charAt(0);if(a.has(o))throw new Error(`Multiple rules found for ${s} (${o})`);return a.set(o,{rule:s,suffix:e,punySuffix:o,wildcard:i==="*",exception:i==="!"}),a},new Map);z.findRule=function(a){for(var s=v.toASCII(a),e=s.split("."),o=0;o255)return"DOMAIN_TOO_LONG";for(var e=s.split("."),o,i=0;i63)return"LABEL_TOO_LONG";if(o.charAt(0)==="-")return"LABEL_STARTS_WITH_DASH";if(o.charAt(o.length-1)==="-")return"LABEL_ENDS_WITH_DASH";if(!/^[a-z0-9\-_]+$/.test(o))return"LABEL_INVALID_CHARS"}};const x=function(a){if(typeof a!="string")throw new TypeError("Domain name must be a string.");var s=a.slice(0).toLowerCase();s.charAt(s.length-1)==="."&&(s=s.slice(0,s.length-1));var e=z.validate(s);if(e)return{input:a,error:{message:M[e],code:e}};var o={input:a,tld:null,sld:null,domain:null,subdomain:null,listed:!1},i=s.split(".");if(i[i.length-1]==="local")return o;var n=function(){return/xn--/.test(s)&&(o.domain&&(o.domain=v.toASCII(o.domain)),o.subdomain&&(o.subdomain=v.toASCII(o.subdomain))),o},r=z.findRule(s);if(!r)return i.length<2?o:(o.tld=i.pop(),o.sld=i.pop(),o.domain=[o.sld,o.tld].join("."),i.length&&(o.subdomain=i.pop()),n());o.listed=!0;var t=r.suffix.split("."),m=i.slice(0,i.length-t.length);return r.exception&&m.push(t.shift()),o.tld=t.join("."),!m.length||(r.wildcard&&(t.unshift(m.pop()),o.tld=t.join(".")),!m.length)||(o.sld=m.pop(),o.domain=[o.sld,o.tld].join("."),m.length&&(o.subdomain=m.join("."))),n()},F=function(a){return a&&x(a).domain||null},H=function(a){var s=x(a);return!!(s.domain&&s.listed)},Z={parse:x,get:F,isValid:H};p.default=Z,p.errorCodes=M,p.get=F,p.isValid=H,p.parse=x,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); diff --git a/index.js b/index.js index ca13a41..9f1ed72 100644 --- a/index.js +++ b/index.js @@ -2,32 +2,34 @@ import Punycode from 'punycode/punycode.js'; import rules from './data/rules.js'; - var internals = {}; // // Parse rules from file. // -internals.rules = rules.map(function (rule) { - - return { - rule: rule, - suffix: rule.replace(/^(\*\.|\!)/, ''), - punySuffix: -1, - wildcard: rule.charAt(0) === '*', - exception: rule.charAt(0) === '!' - }; -}); +const rulesByPunySuffix = rules.reduce( + (map, rule) => { + const suffix = rule.replace(/^(\*\.|\!)/, ''); + const punySuffix = Punycode.toASCII(suffix); + const firstChar = rule.charAt(0); + + if (map.has(punySuffix)) { + throw new Error(`Multiple rules found for ${rule} (${punySuffix})`); + } + map.set(punySuffix, { + rule, + suffix, + punySuffix, + wildcard: firstChar === '*', + exception: firstChar === '!' + }); -// -// Check if given string ends with `suffix`. -// -internals.endsWith = function (str, suffix) { - - return str.indexOf(suffix, str.length - suffix.length) !== -1; -}; + return map; + }, + new Map(), +); // @@ -36,25 +38,15 @@ internals.endsWith = function (str, suffix) { internals.findRule = function (domain) { var punyDomain = Punycode.toASCII(domain); - return internals.rules.reduce(function (memo, rule) { - - if (rule.punySuffix === -1) { - rule.punySuffix = Punycode.toASCII(rule.suffix); - } - if (!internals.endsWith(punyDomain, '.' + rule.punySuffix) && punyDomain !== rule.punySuffix) { - return memo; + var punyDomainChunks = punyDomain.split('.'); + for (var i = 0; i < punyDomainChunks.length; i++) { + var suffix = punyDomainChunks.slice(i).join('.'); + var matchingRules = rulesByPunySuffix.get(suffix); + if (matchingRules) { + return matchingRules; } - // This has been commented out as it never seems to run. This is because - // sub tlds always appear after their parents and we never find a shorter - // match. - //if (memo) { - // var memoSuffix = Punycode.toASCII(memo.suffix); - // if (memoSuffix.length >= punySuffix.length) { - // return memo; - // } - //} - return rule; - }, null); + } + return null; }; @@ -206,6 +198,7 @@ export const parse = function (input) { if (domainParts.length) { parsed.subdomain = domainParts.pop(); } + return handlePunycode(); } diff --git a/package-lock.json b/package-lock.json index 974be7a..fcb3245 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@eslint/js": "^9.15.0", "@playwright/test": "^1.49.0", "@types/eslint__js": "^8.42.3", + "benchmark": "^2.1.4", "browserstack-node-sdk": "^1.34.23", "eslint": "^9.15.0", "mocha": "^10.8.2", @@ -45,278 +46,6 @@ "kuler": "^2.0.0" } }, - "node_modules/@esbuild/aix-ppc64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", - "integrity": "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "aix" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-arm": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.21.5.tgz", - "integrity": "sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.21.5.tgz", - "integrity": "sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.21.5.tgz", - "integrity": "sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/darwin-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz", - "integrity": "sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.21.5.tgz", - "integrity": "sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.5.tgz", - "integrity": "sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.21.5.tgz", - "integrity": "sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.21.5.tgz", - "integrity": "sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.21.5.tgz", - "integrity": "sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.21.5.tgz", - "integrity": "sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.21.5.tgz", - "integrity": "sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.21.5.tgz", - "integrity": "sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.21.5.tgz", - "integrity": "sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.21.5.tgz", - "integrity": "sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.21.5.tgz", - "integrity": "sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@esbuild/linux-x64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz", @@ -334,108 +63,6 @@ "node": ">=12" } }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz", - "integrity": "sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz", - "integrity": "sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz", - "integrity": "sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.21.5.tgz", - "integrity": "sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.21.5.tgz", - "integrity": "sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz", - "integrity": "sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz", @@ -1087,188 +714,6 @@ "dev": true, "license": "BSD-3-Clause" }, - "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.27.3.tgz", - "integrity": "sha512-EzxVSkIvCFxUd4Mgm4xR9YXrcp976qVaHnqom/Tgm+vU79k4vV4eYTjmRvGfeoW8m9LVcsAy/lGjcgVegKEhLQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ] - }, - "node_modules/@rollup/rollup-android-arm64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.27.3.tgz", - "integrity": "sha512-LJc5pDf1wjlt9o/Giaw9Ofl+k/vLUaYsE2zeQGH85giX2F+wn/Cg8b3c5CDP3qmVmeO5NzwVUzQQxwZvC2eQKw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ] - }, - "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.27.3.tgz", - "integrity": "sha512-OuRysZ1Mt7wpWJ+aYKblVbJWtVn3Cy52h8nLuNSzTqSesYw1EuN6wKp5NW/4eSre3mp12gqFRXOKTcN3AI3LqA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.27.3.tgz", - "integrity": "sha512-xW//zjJMlJs2sOrCmXdB4d0uiilZsOdlGQIC/jjmMWT47lkLLoB1nsNhPUcnoqyi5YR6I4h+FjBpILxbEy8JRg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@rollup/rollup-freebsd-arm64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.27.3.tgz", - "integrity": "sha512-58E0tIcwZ+12nK1WiLzHOD8I0d0kdrY/+o7yFVPRHuVGY3twBwzwDdTIBGRxLmyjciMYl1B/U515GJy+yn46qw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ] - }, - "node_modules/@rollup/rollup-freebsd-x64": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.27.3.tgz", - "integrity": "sha512-78fohrpcVwTLxg1ZzBMlwEimoAJmY6B+5TsyAZ3Vok7YabRBUvjYTsRXPTjGEvv/mfgVBepbW28OlMEz4w8wGA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ] - }, - "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.27.3.tgz", - "integrity": "sha512-h2Ay79YFXyQi+QZKo3ISZDyKaVD7uUvukEHTOft7kh00WF9mxAaxZsNs3o/eukbeKuH35jBvQqrT61fzKfAB/Q==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.27.3.tgz", - "integrity": "sha512-Sv2GWmrJfRY57urktVLQ0VKZjNZGogVtASAgosDZ1aUB+ykPxSi3X1nWORL5Jk0sTIIwQiPH7iE3BMi9zGWfkg==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.27.3.tgz", - "integrity": "sha512-FPoJBLsPW2bDNWjSrwNuTPUt30VnfM8GPGRoLCYKZpPx0xiIEdFip3dH6CqgoT0RnoGXptaNziM0WlKgBc+OWQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.27.3.tgz", - "integrity": "sha512-TKxiOvBorYq4sUpA0JT+Fkh+l+G9DScnG5Dqx7wiiqVMiRSkzTclP35pE6eQQYjP4Gc8yEkJGea6rz4qyWhp3g==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.27.3.tgz", - "integrity": "sha512-v2M/mPvVUKVOKITa0oCFksnQQ/TqGrT+yD0184/cWHIu0LoIuYHwox0Pm3ccXEz8cEQDLk6FPKd1CCm+PlsISw==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.27.3.tgz", - "integrity": "sha512-LdrI4Yocb1a/tFVkzmOE5WyYRgEBOyEhWYJe4gsDWDiwnjYKjNs7PS6SGlTDB7maOHF4kxevsuNBl2iOcj3b4A==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.27.3.tgz", - "integrity": "sha512-d4wVu6SXij/jyiwPvI6C4KxdGzuZOvJ6y9VfrcleHTwo68fl8vZC5ZYHsCVPUi4tndCfMlFniWgwonQ5CUpQcA==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, "node_modules/@rollup/rollup-linux-x64-gnu": { "version": "4.27.3", "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.27.3.tgz", @@ -1283,62 +728,6 @@ "linux" ] }, - "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.27.3.tgz", - "integrity": "sha512-nBXOfJds8OzUT1qUreT/en3eyOXd2EH5b0wr2bVB5999qHdGKkzGzIyKYaKj02lXk6wpN71ltLIaQpu58YFBoQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.27.3.tgz", - "integrity": "sha512-ogfbEVQgIZOz5WPWXF2HVb6En+kWzScuxJo/WdQTqEgeyGkaa2ui5sQav9Zkr7bnNCLK48uxmmK0TySm22eiuw==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ] - }, - "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.27.3.tgz", - "integrity": "sha512-ecE36ZBMLINqiTtSNQ1vzWc5pXLQHlf/oqGp/bSbi7iedcjcNb6QbCBNG73Euyy2C+l/fn8qKWEwxr+0SSfs3w==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ] - }, - "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.27.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.27.3.tgz", - "integrity": "sha512-vliZLrDmYKyaUoMzEbMTg2JkerfBjn03KmAw9CykO0Zzkzoyd7o3iZNam/TpyWNjNT+Cz2iO3P9Smv2wgrR+Eg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ] - }, "node_modules/@sindresorhus/is": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", @@ -2106,6 +1495,17 @@ "node": ">=10.0.0" } }, + "node_modules/benchmark": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", + "integrity": "sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "lodash": "^4.17.4", + "platform": "^1.3.3" + } + }, "node_modules/bignumber.js": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", @@ -3895,21 +3295,6 @@ "dev": true, "license": "ISC" }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -6395,6 +5780,13 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/platform": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz", + "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg==", + "dev": true, + "license": "MIT" + }, "node_modules/playwright": { "version": "1.49.0", "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.49.0.tgz", @@ -6427,21 +5819,6 @@ "node": ">=18" } }, - "node_modules/playwright/node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/possible-typed-array-names": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", diff --git a/package.json b/package.json index 9206542..b009c57 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "update-rules": "./scripts/update-rules.js", "build": "vite build", "postbuild": "ln -s ./psl.umd.cjs dist/psl.js && ln -s ./psl.umd.cjs dist/psl.min.js", + "benchmark": "node --experimental-vm-modules --no-warnings benchmark/suite.js", "changelog": "git log $(git describe --tags --abbrev=0)..HEAD --oneline --format=\"%h %s (%an <%ae>)\"" }, "keywords": [ @@ -38,6 +39,7 @@ "@eslint/js": "^9.15.0", "@playwright/test": "^1.49.0", "@types/eslint__js": "^8.42.3", + "benchmark": "^2.1.4", "browserstack-node-sdk": "^1.34.23", "eslint": "^9.15.0", "mocha": "^10.8.2", @@ -45,4 +47,4 @@ "typescript-eslint": "^8.15.0", "vite": "^5.4.11" } -} +} \ No newline at end of file