@clerk/shared
Version:
Internal package utils used by the Clerk SDKs
265 lines (263 loc) • 7.7 kB
JavaScript
// src/compiled/path-to-regexp/index.js
function _(r) {
for (var n = [], e = 0; e < r.length; ) {
var a = r[e];
if (a === "*" || a === "+" || a === "?") {
n.push({
type: "MODIFIER",
index: e,
value: r[e++]
});
continue;
}
if (a === "\\") {
n.push({
type: "ESCAPED_CHAR",
index: e++,
value: r[e++]
});
continue;
}
if (a === "{") {
n.push({
type: "OPEN",
index: e,
value: r[e++]
});
continue;
}
if (a === "}") {
n.push({
type: "CLOSE",
index: e,
value: r[e++]
});
continue;
}
if (a === ":") {
for (var u = "", t = e + 1; t < r.length; ) {
var c = r.charCodeAt(t);
if (c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 95) {
u += r[t++];
continue;
}
break;
}
if (!u) throw new TypeError("Missing parameter name at ".concat(e));
n.push({
type: "NAME",
index: e,
value: u
}), e = t;
continue;
}
if (a === "(") {
var o = 1, m = "", t = e + 1;
if (r[t] === "?") throw new TypeError('Pattern cannot start with "?" at '.concat(t));
for (; t < r.length; ) {
if (r[t] === "\\") {
m += r[t++] + r[t++];
continue;
}
if (r[t] === ")") {
if (o--, o === 0) {
t++;
break;
}
} else if (r[t] === "(" && (o++, r[t + 1] !== "?"))
throw new TypeError("Capturing groups are not allowed at ".concat(t));
m += r[t++];
}
if (o) throw new TypeError("Unbalanced pattern at ".concat(e));
if (!m) throw new TypeError("Missing pattern at ".concat(e));
n.push({
type: "PATTERN",
index: e,
value: m
}), e = t;
continue;
}
n.push({
type: "CHAR",
index: e,
value: r[e++]
});
}
return n.push({
type: "END",
index: e,
value: ""
}), n;
}
function F(r, n) {
n === void 0 && (n = {});
for (var e = _(r), a = n.prefixes, u = a === void 0 ? "./" : a, t = n.delimiter, c = t === void 0 ? "/#?" : t, o = [], m = 0, h = 0, p = "", f = function(l) {
if (h < e.length && e[h].type === l) return e[h++].value;
}, w = function(l) {
var v = f(l);
if (v !== void 0) return v;
var E = e[h], N = E.type, S = E.index;
throw new TypeError("Unexpected ".concat(N, " at ").concat(S, ", expected ").concat(l));
}, d = function() {
for (var l = "", v; v = f("CHAR") || f("ESCAPED_CHAR"); ) l += v;
return l;
}, M = function(l) {
for (var v = 0, E = c; v < E.length; v++) {
var N = E[v];
if (l.indexOf(N) > -1) return true;
}
return false;
}, A = function(l) {
var v = o[o.length - 1], E = l || (v && typeof v == "string" ? v : "");
if (v && !E)
throw new TypeError('Must have text between two parameters, missing text after "'.concat(v.name, '"'));
return !E || M(E) ? "[^".concat(s(c), "]+?") : "(?:(?!".concat(s(E), ")[^").concat(s(c), "])+?");
}; h < e.length; ) {
var T = f("CHAR"), x = f("NAME"), C = f("PATTERN");
if (x || C) {
var g = T || "";
u.indexOf(g) === -1 && (p += g, g = ""), p && (o.push(p), p = ""), o.push({
name: x || m++,
prefix: g,
suffix: "",
pattern: C || A(g),
modifier: f("MODIFIER") || ""
});
continue;
}
var i = T || f("ESCAPED_CHAR");
if (i) {
p += i;
continue;
}
p && (o.push(p), p = "");
var R = f("OPEN");
if (R) {
var g = d(), y = f("NAME") || "", O = f("PATTERN") || "", b = d();
w("CLOSE"), o.push({
name: y || (O ? m++ : ""),
pattern: y && !O ? A(g) : O,
prefix: g,
suffix: b,
modifier: f("MODIFIER") || ""
});
continue;
}
w("END");
}
return o;
}
function H(r, n) {
var e = [], a = P(r, e, n);
return I(a, e, n);
}
function I(r, n, e) {
e === void 0 && (e = {});
var a = e.decode, u = a === void 0 ? function(t) {
return t;
} : a;
return function(t) {
var c = r.exec(t);
if (!c) return false;
for (var o = c[0], m = c.index, h = /* @__PURE__ */ Object.create(null), p = function(w) {
if (c[w] === void 0) return "continue";
var d = n[w - 1];
d.modifier === "*" || d.modifier === "+" ? h[d.name] = c[w].split(d.prefix + d.suffix).map(function(M) {
return u(M, d);
}) : h[d.name] = u(c[w], d);
}, f = 1; f < c.length; f++)
p(f);
return {
path: o,
index: m,
params: h
};
};
}
function s(r) {
return r.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
}
function D(r) {
return r && r.sensitive ? "" : "i";
}
function $(r, n) {
if (!n) return r;
for (var e = /\((?:\?<(.*?)>)?(?!\?)/g, a = 0, u = e.exec(r.source); u; )
n.push({
name: u[1] || a++,
prefix: "",
suffix: "",
modifier: "",
pattern: ""
}), u = e.exec(r.source);
return r;
}
function W(r, n, e) {
var a = r.map(function(u) {
return P(u, n, e).source;
});
return new RegExp("(?:".concat(a.join("|"), ")"), D(e));
}
function L(r, n, e) {
return U(F(r, e), n, e);
}
function U(r, n, e) {
e === void 0 && (e = {});
for (var a = e.strict, u = a === void 0 ? false : a, t = e.start, c = t === void 0 ? true : t, o = e.end, m = o === void 0 ? true : o, h = e.encode, p = h === void 0 ? function(v) {
return v;
} : h, f = e.delimiter, w = f === void 0 ? "/#?" : f, d = e.endsWith, M = d === void 0 ? "" : d, A = "[".concat(s(M), "]|$"), T = "[".concat(s(w), "]"), x = c ? "^" : "", C = 0, g = r; C < g.length; C++) {
var i = g[C];
if (typeof i == "string") x += s(p(i));
else {
var R = s(p(i.prefix)), y = s(p(i.suffix));
if (i.pattern)
if (n && n.push(i), R || y)
if (i.modifier === "+" || i.modifier === "*") {
var O = i.modifier === "*" ? "?" : "";
x += "(?:".concat(R, "((?:").concat(i.pattern, ")(?:").concat(y).concat(R, "(?:").concat(i.pattern, "))*)").concat(y, ")").concat(O);
} else x += "(?:".concat(R, "(").concat(i.pattern, ")").concat(y, ")").concat(i.modifier);
else {
if (i.modifier === "+" || i.modifier === "*")
throw new TypeError('Can not repeat "'.concat(i.name, '" without a prefix and suffix'));
x += "(".concat(i.pattern, ")").concat(i.modifier);
}
else x += "(?:".concat(R).concat(y, ")").concat(i.modifier);
}
}
if (m) u || (x += "".concat(T, "?")), x += e.endsWith ? "(?=".concat(A, ")") : "$";
else {
var b = r[r.length - 1], l = typeof b == "string" ? T.indexOf(b[b.length - 1]) > -1 : b === void 0;
u || (x += "(?:".concat(T, "(?=").concat(A, "))?")), l || (x += "(?=".concat(T, "|").concat(A, ")"));
}
return new RegExp(x, D(e));
}
function P(r, n, e) {
return r instanceof RegExp ? $(r, n) : Array.isArray(r) ? W(r, n, e) : L(r, n, e);
}
// src/pathToRegexp.ts
var pathToRegexp = (path) => {
try {
return P(path);
} catch (e) {
throw new Error(
`Invalid path: ${path}.
Consult the documentation of path-to-regexp here: https://github.com/pillarjs/path-to-regexp/tree/6.x
${e.message}`
);
}
};
function match(str, options) {
try {
return H(str, options);
} catch (e) {
throw new Error(
`Invalid path and options: Consult the documentation of path-to-regexp here: https://github.com/pillarjs/path-to-regexp/tree/6.x
${e.message}`
);
}
}
export {
pathToRegexp,
match
};
//# sourceMappingURL=chunk-JJHTUJGL.mjs.map