ez-common-ts/lib/index.es.js
2024-01-29 00:10:57 +08:00

140 lines
3.4 KiB
JavaScript

var h = /* @__PURE__ */ ((e) => (e[e.delete = 2] = "delete", e[e.reset = 1] = "reset", e))(h || {});
const m = (e) => ({
clear: function(t = 2) {
t === 1 ? Object.keys(e).forEach((n) => {
e[n] = void 0;
}) : t === 2 && Object.keys(e).forEach((n) => {
delete e[n];
});
},
replace: function(t) {
this.clear(
2
/* delete */
), Object.assign(e, t);
}
});
function p(...e) {
let t = e ?? [];
return {
test: function(n) {
if (t.length <= 1)
return t.length === 1 ? t[0] : [];
let s = n ?? function(r, i) {
return r === i;
};
return t.reduce((r, i) => (i && i.length > 0 && (r.length === 0 ? r.push(...i) : i.forEach((f) => {
r.some((u) => s(u, f)) || r.push(f);
})), r), []);
},
path: function(...n) {
return this.test((s, r) => n.every((i) => s[i] === r[i]));
}
};
}
function I(e, t, n) {
const s = t, r = n || t;
return function(i) {
const f = [], l = i.matchAll(e);
let u = 0;
for (const o of l) {
const g = i.slice(u, o.index);
g && f.push(r(g, !1)), f.push(s(o[0], !0)), u = o.index + o[0].length;
}
return u < i.length && f.push(r(i.slice(u), !1)), f;
};
}
function a(e, t) {
return typeof e == "string" && typeof t == "string" ? e.toLowerCase() === t.toLowerCase() : e === void 0 && t === void 0;
}
const O = (e, t) => {
for (let n = 0; n < e.length; n++) {
let s = e[n];
if (a(s, t))
return !0;
}
return !1;
}, d = (e) => e.replaceAll(/[\u4e00-\u9fa5]/g, "--").length, E = (e, t, n = " ") => {
const s = t - (d(e) - e.length);
return e.padEnd(s, n);
};
function b(e) {
const t = e.lastIndexOf(".");
return t === -1 ? "" : e.substring(t + 1);
}
function x(e) {
let t = e.lastIndexOf("/");
return t === -1 && (t = e.lastIndexOf("\\"), t === -1) ? e : e.substring(t + 1);
}
function y(e) {
const t = x(e), n = t.lastIndexOf(".");
return n === -1 ? t : t.substring(0, n);
}
function N(e, t = "win32") {
const n = t === "win32" ? "\\" : "/";
let s, r, i, f;
const l = e.lastIndexOf(n);
l === -1 ? (s = "", r = e) : (s = e.substring(0, l + 1), r = e.substring(l + 1));
const u = r.lastIndexOf(".");
return u === -1 ? (i = "", f = r) : (i = r.substring(u + 1), f = r.substring(0, u)), {
fileName: r,
fileNameNoExt: f,
fileExtName: i,
fullPath: e,
pathOnly: s
};
}
const c = {
/**
* Creates an optional of the specified value. The value may be undefined or null.
* @return OptionalInstance<T>
*/
of(e) {
function t(n) {
return n == null;
}
return {
get() {
return e;
},
orElse(n) {
return t(e) ? n : e;
},
then(n, s) {
t(e) ? s && s() : n(e);
},
ifPresent(n) {
e != null && n(e);
},
isPresent() {
return !t(e);
},
filter(n) {
return t(e) || n(e) ? this : c.of(void 0);
},
map(n) {
return e == null ? c.of(void 0) : c.of(n(e));
},
flatMap(n) {
return n(e);
}
};
}
};
export {
c as Optional,
h as RecordClearMode,
p as assignRecords,
a as equalsIgnoreCase,
b as getFileExt,
N as getFileInfo,
x as getFileName,
y as getFileNameWithoutExt,
O as includeIgnoreCase,
d as strLength,
E as strMonospacePad,
I as stringTokenizer,
m as withRecord
};
//# sourceMappingURL=index.es.js.map