laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
114 lines (113 loc) • 3.36 kB
JavaScript
"use client";
const w = { basename: c, dirname: u, extname: g, join: h, sep: "/" };
function c(t, n) {
if (n !== void 0 && typeof n != "string")
throw new TypeError('"ext" argument must be a string');
s(t);
let e = 0, l = -1, i = t.length, f;
if (n === void 0 || n.length === 0 || n.length > t.length) {
for (; i--; )
if (t.codePointAt(i) === 47) {
if (f) {
e = i + 1;
break;
}
} else l < 0 && (f = !0, l = i + 1);
return l < 0 ? "" : t.slice(e, l);
}
if (n === t)
return "";
let o = -1, r = n.length - 1;
for (; i--; )
if (t.codePointAt(i) === 47) {
if (f) {
e = i + 1;
break;
}
} else
o < 0 && (f = !0, o = i + 1), r > -1 && (t.codePointAt(i) === n.codePointAt(r--) ? r < 0 && (l = i) : (r = -1, l = o));
return e === l ? l = o : l < 0 && (l = t.length), t.slice(e, l);
}
function u(t) {
if (s(t), t.length === 0)
return ".";
let n = -1, e = t.length, l;
for (; --e; )
if (t.codePointAt(e) === 47) {
if (l) {
n = e;
break;
}
} else l || (l = !0);
return n < 0 ? t.codePointAt(0) === 47 ? "/" : "." : n === 1 && t.codePointAt(0) === 47 ? "//" : t.slice(0, n);
}
function g(t) {
s(t);
let n = t.length, e = -1, l = 0, i = -1, f = 0, o;
for (; n--; ) {
const r = t.codePointAt(n);
if (r === 47) {
if (o) {
l = n + 1;
break;
}
continue;
}
e < 0 && (o = !0, e = n + 1), r === 46 ? i < 0 ? i = n : f !== 1 && (f = 1) : i > -1 && (f = -1);
}
return i < 0 || e < 0 || // We saw a non-dot character immediately before the dot.
f === 0 || // The (right-most) trimmed path component is exactly `..`.
f === 1 && i === e - 1 && i === l + 1 ? "" : t.slice(i, e);
}
function h(...t) {
let n = -1, e;
for (; ++n < t.length; )
s(t[n]), t[n] && (e = e === void 0 ? t[n] : e + "/" + t[n]);
return e === void 0 ? "." : P(e);
}
function P(t) {
s(t);
const n = t.codePointAt(0) === 47;
let e = A(t, !n);
return e.length === 0 && !n && (e = "."), e.length > 0 && t.codePointAt(t.length - 1) === 47 && (e += "/"), n ? "/" + e : e;
}
function A(t, n) {
let e = "", l = 0, i = -1, f = 0, o = -1, r, d;
for (; ++o <= t.length; ) {
if (o < t.length)
r = t.codePointAt(o);
else {
if (r === 47)
break;
r = 47;
}
if (r === 47) {
if (!(i === o - 1 || f === 1)) if (i !== o - 1 && f === 2) {
if (e.length < 2 || l !== 2 || e.codePointAt(e.length - 1) !== 46 || e.codePointAt(e.length - 2) !== 46) {
if (e.length > 2) {
if (d = e.lastIndexOf("/"), d !== e.length - 1) {
d < 0 ? (e = "", l = 0) : (e = e.slice(0, d), l = e.length - 1 - e.lastIndexOf("/")), i = o, f = 0;
continue;
}
} else if (e.length > 0) {
e = "", l = 0, i = o, f = 0;
continue;
}
}
n && (e = e.length > 0 ? e + "/.." : "..", l = 2);
} else
e.length > 0 ? e += "/" + t.slice(i + 1, o) : e = t.slice(i + 1, o), l = o - i - 1;
i = o, f = 0;
} else r === 46 && f > -1 ? f++ : f = -1;
}
return e;
}
function s(t) {
if (typeof t != "string")
throw new TypeError(
"Path must be a string. Received " + JSON.stringify(t)
);
}
export {
w as minpath
};