This commit is contained in:
zhujingjing 2024-01-30 11:09:07 +08:00
parent 69de163826
commit 392b2c571f
Signed by: karlcw
GPG Key ID: B11805D3A0F5C671
8 changed files with 57 additions and 47 deletions

View File

@ -30,4 +30,4 @@ export declare function assignRecords<T extends Record<string, any>>(...arrays:
* @param sources
* @returns
*/
export declare const extend: <T extends Record<string, any>>(target: T, ...sources: (T | undefined)[]) => T;
export declare const extendRecord: <T extends Record<string, any>>(target: T, ...sources: (T | undefined)[]) => T;

4
lib/index.d.ts vendored
View File

@ -1,5 +1,5 @@
import { withRecord, assignRecords, RecordClearMode } from "./commons/record-util";
import { withRecord, assignRecords, RecordClearMode, extendRecord } from "./commons/record-util";
import { stringTokenizer, equalsIgnoreCase, includeIgnoreCase, strLength, strMonospacePad } from "./commons/str-utils";
import { getFileExt, getFileFullName, getFileNameWithoutExt, getFileInfo } from "./commons/file-util";
import { Optional } from "./commons/optional";
export { Optional, RecordClearMode, assignRecords, equalsIgnoreCase, getFileExt, getFileFullName as getFileName, getFileInfo, getFileNameWithoutExt, includeIgnoreCase, strLength, strMonospacePad, stringTokenizer, withRecord, };
export { Optional, RecordClearMode, assignRecords, equalsIgnoreCase, extendRecord, getFileExt, getFileFullName as getFileName, getFileInfo, getFileNameWithoutExt, includeIgnoreCase, strLength, strMonospacePad, stringTokenizer, withRecord, };

View File

@ -1,5 +1,5 @@
var h = /* @__PURE__ */ ((e) => (e[e.delete = 2] = "delete", e[e.reset = 1] = "reset", e))(h || {});
const m = (e) => ({
const p = (e) => ({
clear: function(t = 2) {
t === 1 ? Object.keys(e).forEach((n) => {
e[n] = void 0;
@ -14,49 +14,56 @@ const m = (e) => ({
), Object.assign(e, t);
}
});
function p(...e) {
function m(...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;
let r = n ?? function(s, i) {
return s === 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), []);
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), []);
},
path: function(...n) {
return this.test((s, r) => n.every((i) => s[i] === r[i]));
return this.test((r, s) => n.every((i) => r[i] === s[i]));
}
};
}
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;
};
function I(e, t, n) {
const s = t, r = n || t;
const r = t, s = 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;
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;
}
return u < i.length && f.push(r(i.slice(u), !1)), f;
return o < i.length && f.push(s(i.slice(o), !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) => {
const E = (e, t) => {
for (let n = 0; n < e.length; n++) {
let s = e[n];
if (a(s, t))
let r = e[n];
if (a(r, 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);
}, d = (e) => e.replaceAll(/[\u4e00-\u9fa5]/g, "--").length, y = (e, t, n = " ") => {
const r = t - (d(e) - e.length);
return e.padEnd(r, n);
};
function b(e) {
const t = e.lastIndexOf(".");
@ -66,22 +73,22 @@ function x(e) {
let t = e.lastIndexOf("/");
return t === -1 && (t = e.lastIndexOf("\\"), t === -1) ? e : e.substring(t + 1);
}
function y(e) {
function N(e) {
const t = x(e), n = t.lastIndexOf(".");
return n === -1 ? t : t.substring(0, n);
}
function N(e, t = "win32") {
function w(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,
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,
fileNameNoExt: f,
fileExtName: i,
fullPath: e,
pathOnly: s
pathOnly: r
};
}
const c = {
@ -100,8 +107,8 @@ const c = {
orElse(n) {
return t(e) ? n : e;
},
then(n, s) {
t(e) ? s && s() : n(e);
then(n, r) {
t(e) ? r && r() : n(e);
},
ifPresent(n) {
e != null && n(e);
@ -124,16 +131,17 @@ const c = {
export {
c as Optional,
h as RecordClearMode,
p as assignRecords,
m as assignRecords,
a as equalsIgnoreCase,
O as extendRecord,
b as getFileExt,
N as getFileInfo,
w as getFileInfo,
x as getFileName,
y as getFileNameWithoutExt,
O as includeIgnoreCase,
N as getFileNameWithoutExt,
E as includeIgnoreCase,
d as strLength,
E as strMonospacePad,
y as strMonospacePad,
I as stringTokenizer,
m as withRecord
p as withRecord
};
//# sourceMappingURL=index.es.js.map

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,2 @@
(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r["ez-common-ts"]={}))})(this,function(r){"use strict";var o=(e=>(e[e.delete=2]="delete",e[e.reset=1]="reset",e))(o||{});const O=e=>({clear:function(n=2){n===1?Object.keys(e).forEach(t=>{e[t]=void 0}):n===2&&Object.keys(e).forEach(t=>{delete e[t]})},replace:function(n){this.clear(2),Object.assign(e,n)}});function E(...e){let n=e??[];return{test:function(t){if(n.length<=1)return n.length===1?n[0]:[];let f=t??function(i,s){return i===s};return n.reduce((i,s)=>(s&&s.length>0&&(i.length===0?i.push(...s):s.forEach(u=>{i.some(l=>f(l,u))||i.push(u)})),i),[])},path:function(...t){return this.test((f,i)=>t.every(s=>f[s]===i[s]))}}}function b(e,n,t){const f=n,i=t||n;return function(s){const u=[],c=s.matchAll(e);let l=0;for(const d of c){const I=s.slice(l,d.index);I&&u.push(i(I,!1)),u.push(f(d[0],!0)),l=d.index+d[0].length}return l<s.length&&u.push(i(s.slice(l),!1)),u}}function a(e,n){return typeof e=="string"&&typeof n=="string"?e.toLowerCase()===n.toLowerCase():e===void 0&&n===void 0}const x=(e,n)=>{for(let t=0;t<e.length;t++){let f=e[t];if(a(f,n))return!0}return!1},h=e=>e.replaceAll(/[\u4e00-\u9fa5]/g,"--").length,y=(e,n,t=" ")=>{const f=n-(h(e)-e.length);return e.padEnd(f,t)};function p(e){const n=e.lastIndexOf(".");return n===-1?"":e.substring(n+1)}function m(e){let n=e.lastIndexOf("/");return n===-1&&(n=e.lastIndexOf("\\"),n===-1)?e:e.substring(n+1)}function F(e){const n=m(e),t=n.lastIndexOf(".");return t===-1?n:n.substring(0,t)}function N(e,n="win32"){const t=n==="win32"?"\\":"/";let f,i,s,u;const c=e.lastIndexOf(t);c===-1?(f="",i=e):(f=e.substring(0,c+1),i=e.substring(c+1));const l=i.lastIndexOf(".");return l===-1?(s="",u=i):(s=i.substring(l+1),u=i.substring(0,l)),{fileName:i,fileNameNoExt:u,fileExtName:s,fullPath:e,pathOnly:f}}const g={of(e){function n(t){return t==null}return{get(){return e},orElse(t){return n(e)?t:e},then(t,f){n(e)?f&&f():t(e)},ifPresent(t){e!=null&&t(e)},isPresent(){return!n(e)},filter(t){return n(e)||t(e)?this:g.of(void 0)},map(t){return e==null?g.of(void 0):g.of(t(e))},flatMap(t){return t(e)}}}};r.Optional=g,r.RecordClearMode=o,r.assignRecords=E,r.equalsIgnoreCase=a,r.getFileExt=p,r.getFileInfo=N,r.getFileName=m,r.getFileNameWithoutExt=F,r.includeIgnoreCase=x,r.strLength=h,r.strMonospacePad=y,r.stringTokenizer=b,r.withRecord=O,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
(function(s,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(s=typeof globalThis<"u"?globalThis:s||self,l(s["ez-common-ts"]={}))})(this,function(s){"use strict";var l=(e=>(e[e.delete=2]="delete",e[e.reset=1]="reset",e))(l||{});const O=e=>({clear:function(n=2){n===1?Object.keys(e).forEach(t=>{e[t]=void 0}):n===2&&Object.keys(e).forEach(t=>{delete e[t]})},replace:function(n){this.clear(2),Object.assign(e,n)}});function y(...e){let n=e??[];return{test:function(t){if(n.length<=1)return n.length===1?n[0]:[];let i=t??function(r,f){return r===f};return n.reduce((r,f)=>(f&&f.length>0&&(r.length===0?r.push(...f):f.forEach(o=>{r.some(u=>i(u,o))||r.push(o)})),r),[])},path:function(...t){return this.test((i,r)=>t.every(f=>i[f]===r[f]))}}}const x=(e,...n)=>{for(const t of n)if(t!==void 0)for(const i in t)t.hasOwnProperty(i)&&t[i]!=null&&(e[i]=t[i]);return e};function E(e,n,t){const i=n,r=t||n;return function(f){const o=[],c=f.matchAll(e);let u=0;for(const g of c){const I=f.slice(u,g.index);I&&o.push(r(I,!1)),o.push(i(g[0],!0)),u=g.index+g[0].length}return u<f.length&&o.push(r(f.slice(u),!1)),o}}function a(e,n){return typeof e=="string"&&typeof n=="string"?e.toLowerCase()===n.toLowerCase():e===void 0&&n===void 0}const b=(e,n)=>{for(let t=0;t<e.length;t++){let i=e[t];if(a(i,n))return!0}return!1},h=e=>e.replaceAll(/[\u4e00-\u9fa5]/g,"--").length,p=(e,n,t=" ")=>{const i=n-(h(e)-e.length);return e.padEnd(i,t)};function F(e){const n=e.lastIndexOf(".");return n===-1?"":e.substring(n+1)}function m(e){let n=e.lastIndexOf("/");return n===-1&&(n=e.lastIndexOf("\\"),n===-1)?e:e.substring(n+1)}function N(e){const n=m(e),t=n.lastIndexOf(".");return t===-1?n:n.substring(0,t)}function w(e,n="win32"){const t=n==="win32"?"\\":"/";let i,r,f,o;const c=e.lastIndexOf(t);c===-1?(i="",r=e):(i=e.substring(0,c+1),r=e.substring(c+1));const u=r.lastIndexOf(".");return u===-1?(f="",o=r):(f=r.substring(u+1),o=r.substring(0,u)),{fileName:r,fileNameNoExt:o,fileExtName:f,fullPath:e,pathOnly:i}}const d={of(e){function n(t){return t==null}return{get(){return e},orElse(t){return n(e)?t:e},then(t,i){n(e)?i&&i():t(e)},ifPresent(t){e!=null&&t(e)},isPresent(){return!n(e)},filter(t){return n(e)||t(e)?this:d.of(void 0)},map(t){return e==null?d.of(void 0):d.of(t(e))},flatMap(t){return t(e)}}}};s.Optional=d,s.RecordClearMode=l,s.assignRecords=y,s.equalsIgnoreCase=a,s.extendRecord=x,s.getFileExt=F,s.getFileInfo=w,s.getFileName=m,s.getFileNameWithoutExt=N,s.includeIgnoreCase=b,s.strLength=h,s.strMonospacePad=p,s.stringTokenizer=E,s.withRecord=O,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=index.umd.js.map

File diff suppressed because one or more lines are too long

View File

@ -82,7 +82,7 @@ export function assignRecords<T extends Record<string, any>>(...arrays: T[][]) {
* @param sources
* @returns
*/
export const extend = <T extends Record<string, any>>(
export const extendRecord = <T extends Record<string, any>>(
// 目标对象
target: T,
// 其他对象参数

View File

@ -2,6 +2,7 @@ import {
withRecord,
assignRecords,
RecordClearMode,
extendRecord,
} from "./commons/record-util";
import {
stringTokenizer,
@ -23,6 +24,7 @@ export {
RecordClearMode,
assignRecords,
equalsIgnoreCase,
extendRecord,
getFileExt,
getFileFullName as getFileName,
getFileInfo,