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

148 lines
3.5 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 || {});
2024-01-30 11:09:07 +08:00
const p = (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-30 11:09:07 +08:00
function m(...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-30 11:09:07 +08:00
let r = n ?? function(s, i) {
return s === i;
2023-11-11 21:28:01 +08:00
};
2024-01-30 11:09:07 +08:00
return t.reduce((s, i) => (i && i.length > 0 && (s.length === 0 ? s.push(...i) : i.forEach((f) => {
s.some((o) => r(o, f)) || s.push(f);
})), s), []);
2023-11-11 21:28:01 +08:00
},
2024-01-28 18:33:16 +08:00
path: function(...n) {
2024-01-30 11:09:07 +08:00
return this.test((r, s) => n.every((i) => r[i] === s[i]));
2023-11-10 16:35:59 +08:00
}
2023-11-11 21:28:01 +08:00
};
}
2024-01-30 11:09:07 +08:00
const O = (e, ...t) => {
for (const n of t)
if (n !== void 0)
for (const r in n)
n.hasOwnProperty(r) && n[r] != null && (e[r] = n[r]);
return e;
};
2024-01-28 18:33:16 +08:00
function I(e, t, n) {
2024-01-30 11:09:07 +08:00
const r = t, s = n || t;
2024-01-29 00:10:57 +08:00
return function(i) {
2024-01-30 11:09:07 +08:00
const f = [], u = i.matchAll(e);
let o = 0;
for (const l of u) {
const g = i.slice(o, l.index);
g && f.push(s(g, !1)), f.push(r(l[0], !0)), o = l.index + l[0].length;
2023-11-11 21:28:01 +08:00
}
2024-01-30 11:09:07 +08:00
return o < i.length && f.push(s(i.slice(o), !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-30 11:09:07 +08:00
const E = (e, t) => {
2024-01-28 18:33:16 +08:00
for (let n = 0; n < e.length; n++) {
2024-01-30 11:09:07 +08:00
let r = e[n];
if (a(r, t))
2023-11-11 16:13:36 +08:00
return !0;
}
return !1;
2024-01-30 11:09:07 +08:00
}, d = (e) => e.replaceAll(/[\u4e00-\u9fa5]/g, "--").length, y = (e, t, n = " ") => {
const r = t - (d(e) - e.length);
return e.padEnd(r, 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-30 11:09:07 +08:00
function N(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-30 11:09:07 +08:00
function w(e, t = "win32") {
2024-01-28 18:33:16 +08:00
const n = t === "win32" ? "\\" : "/";
2024-01-30 11:09:07 +08:00
let r, s, i, f;
const u = e.lastIndexOf(n);
u === -1 ? (r = "", s = e) : (r = e.substring(0, u + 1), s = e.substring(u + 1));
const o = s.lastIndexOf(".");
return o === -1 ? (i = "", f = s) : (i = s.substring(o + 1), f = s.substring(0, o)), {
fileName: s,
2024-01-29 00:10:57 +08:00
fileNameNoExt: f,
fileExtName: i,
2023-11-14 16:17:22 +08:00
fullPath: e,
2024-01-30 11:09:07 +08:00
pathOnly: r
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;
},
2024-01-30 11:09:07 +08:00
then(n, r) {
t(e) ? r && r() : n(e);
2024-01-29 00:10:57 +08:00
},
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,
2024-01-30 11:09:07 +08:00
m as assignRecords,
2024-01-29 00:10:57 +08:00
a as equalsIgnoreCase,
2024-01-30 11:09:07 +08:00
O as extendRecord,
2024-01-29 00:10:57 +08:00
b as getFileExt,
2024-01-30 11:09:07 +08:00
w as getFileInfo,
2023-11-14 16:17:22 +08:00
x as getFileName,
2024-01-30 11:09:07 +08:00
N as getFileNameWithoutExt,
E as includeIgnoreCase,
2024-01-29 00:10:57 +08:00
d as strLength,
2024-01-30 11:09:07 +08:00
y as strMonospacePad,
2024-01-28 18:33:16 +08:00
I as stringTokenizer,
2024-01-30 11:09:07 +08:00
p as withRecord
2023-11-10 16:35:59 +08:00
};
//# sourceMappingURL=index.es.js.map