ez-common-ts/lib/index.es.js

140 lines
3.4 KiB
JavaScript
Raw Normal View History

2024-01-29 00:10:57 +08:00
var h = /* @__PURE__ */ ((e) => (e[e.delete = 2] = "delete", e[e.reset = 1] = "reset", e))(h || {});
const m = (e) => ({
2023-11-11 15:30:11 +08:00
clear: function(t = 2) {
2024-01-28 18:33:16 +08:00
t === 1 ? Object.keys(e).forEach((n) => {
e[n] = void 0;
}) : t === 2 && Object.keys(e).forEach((n) => {
delete e[n];
2023-11-11 21:28:01 +08:00
});
2023-11-11 15:30:11 +08:00
},
replace: function(t) {
this.clear(
2023-11-11 21:28:01 +08:00
2
/* delete */
2023-11-11 15:30:11 +08:00
), Object.assign(e, t);
}
});
2024-01-29 00:10:57 +08:00
function p(...e) {
2023-11-11 21:28:01 +08:00
let t = e ?? [];
return {
2024-01-28 18:33:16 +08:00
test: function(n) {
2023-11-11 21:28:01 +08:00
if (t.length <= 1)
return t.length === 1 ? t[0] : [];
2024-01-29 00:10:57 +08:00
let s = n ?? function(r, i) {
return r === i;
2023-11-11 21:28:01 +08:00
};
2024-01-29 00:10:57 +08:00
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), []);
2023-11-11 21:28:01 +08:00
},
2024-01-28 18:33:16 +08:00
path: function(...n) {
2024-01-29 00:10:57 +08:00
return this.test((s, r) => n.every((i) => s[i] === r[i]));
2023-11-10 16:35:59 +08:00
}
2023-11-11 21:28:01 +08:00
};
}
2024-01-28 18:33:16 +08:00
function I(e, t, n) {
2024-01-29 00:10:57 +08:00
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;
2023-11-11 21:28:01 +08:00
}
2024-01-29 00:10:57 +08:00
return u < i.length && f.push(r(i.slice(u), !1)), f;
2023-11-10 16:35:59 +08:00
};
}
2024-01-29 00:10:57 +08:00
function a(e, t) {
2023-11-11 16:13:36 +08:00
return typeof e == "string" && typeof t == "string" ? e.toLowerCase() === t.toLowerCase() : e === void 0 && t === void 0;
}
2024-01-28 18:33:16 +08:00
const O = (e, t) => {
for (let n = 0; n < e.length; n++) {
2024-01-29 00:10:57 +08:00
let s = e[n];
if (a(s, t))
2023-11-11 16:13:36 +08:00
return !0;
}
return !1;
2024-01-29 00:10:57 +08:00
}, d = (e) => e.replaceAll(/[\u4e00-\u9fa5]/g, "--").length, E = (e, t, n = " ") => {
const s = t - (d(e) - e.length);
return e.padEnd(s, n);
2023-11-11 16:13:36 +08:00
};
2024-01-29 00:10:57 +08:00
function b(e) {
2023-11-12 21:58:32 +08:00
const t = e.lastIndexOf(".");
return t === -1 ? "" : e.substring(t + 1);
}
2023-11-14 16:17:22 +08:00
function x(e) {
2023-11-12 21:58:32 +08:00
let t = e.lastIndexOf("/");
return t === -1 && (t = e.lastIndexOf("\\"), t === -1) ? e : e.substring(t + 1);
}
2024-01-29 00:10:57 +08:00
function y(e) {
2024-01-28 18:33:16 +08:00
const t = x(e), n = t.lastIndexOf(".");
return n === -1 ? t : t.substring(0, n);
2023-11-14 16:17:22 +08:00
}
2024-01-29 00:10:57 +08:00
function N(e, t = "win32") {
2024-01-28 18:33:16 +08:00
const n = t === "win32" ? "\\" : "/";
2024-01-29 00:10:57 +08:00
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,
2023-11-14 16:17:22 +08:00
fullPath: e,
2024-01-29 00:10:57 +08:00
pathOnly: s
2023-11-14 16:17:22 +08:00
};
}
2024-01-29 00:10:57 +08:00
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);
}
};
}
};
2023-11-10 16:35:59 +08:00
export {
2024-01-29 00:10:57 +08:00
c as Optional,
h as RecordClearMode,
p as assignRecords,
a as equalsIgnoreCase,
b as getFileExt,
N as getFileInfo,
2023-11-14 16:17:22 +08:00
x as getFileName,
2024-01-29 00:10:57 +08:00
y as getFileNameWithoutExt,
2024-01-28 18:33:16 +08:00
O as includeIgnoreCase,
2024-01-29 00:10:57 +08:00
d as strLength,
E as strMonospacePad,
2024-01-28 18:33:16 +08:00
I as stringTokenizer,
2024-01-29 00:10:57 +08:00
m as withRecord
2023-11-10 16:35:59 +08:00
};
//# sourceMappingURL=index.es.js.map