dlzn-ui 1.14.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -58,5 +58,5 @@
58
58
  "**/*.css"
59
59
  ],
60
60
  "type": "module",
61
- "version": "1.14.0"
61
+ "version": "1.16.0"
62
62
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description: 判断是否为空值,一般用于表单填写时的判断
3
+ * @example 0 和 false 是合法值
4
+ * @example 空格不是合法值
5
+ */
6
+ export declare function isFalsy(val: any): val is '' | null | undefined;
7
+ /**
8
+ * @description: 判断是否为有效的数字字符串
9
+ */
10
+ export declare function isValidNumberString(val: any): val is string;
@@ -0,0 +1,14 @@
1
+ import { validNumberStringReg as e } from "../const/others.mjs";
2
+ //#region src/utils/boolean.ts
3
+ function t(e) {
4
+ return [
5
+ "",
6
+ null,
7
+ void 0
8
+ ].includes(e) || typeof e == "string" && e.trim() === "";
9
+ }
10
+ function n(t) {
11
+ return typeof t == "string" && e.test(t);
12
+ }
13
+ //#endregion
14
+ export { t as isFalsy, n as isValidNumberString };
package/utils/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './boolean';
1
2
  export * from './number';
2
3
  export * from './string';
3
4
  export * from './tool';
5
+ export * from './tree';
package/utils/index.mjs CHANGED
@@ -1,4 +1,6 @@
1
- import { formatSecondsToChinese as e } from "./number.mjs";
2
- import { getFilenameFromUrl as t, queryStringToObject as n } from "./string.mjs";
3
- import { aesDecrypt as r, aesEncrypt as i, saveAs as a } from "./tool.mjs";
4
- export { r as aesDecrypt, i as aesEncrypt, e as formatSecondsToChinese, t as getFilenameFromUrl, n as queryStringToObject, a as saveAs };
1
+ import { isFalsy as e, isValidNumberString as t } from "./boolean.mjs";
2
+ import { formatNumber as n, formatSecondsToChinese as r } from "./number.mjs";
3
+ import { getFilenameFromUrl as i, queryStringToObject as a, stringDisplay as o } from "./string.mjs";
4
+ import { aesDecrypt as s, aesEncrypt as c, saveAs as l } from "./tool.mjs";
5
+ import { flatArrToTree as u, treeToFlatArr as d } from "./tree.mjs";
6
+ export { s as aesDecrypt, c as aesEncrypt, u as flatArrToTree, n as formatNumber, r as formatSecondsToChinese, i as getFilenameFromUrl, e as isFalsy, t as isValidNumberString, a as queryStringToObject, l as saveAs, o as stringDisplay, d as treeToFlatArr };
package/utils/number.d.ts CHANGED
@@ -1,7 +1,12 @@
1
+ type FormatNumberConfig = ConstructorParameters<typeof Intl.NumberFormat>[1] & {
2
+ roundingMode?: 'ceil' | 'expand' | 'floor' | 'halfCeil' | 'halfEven' | 'halfExpand' | 'halfFloor' | 'halfTrunc' | 'trunc';
3
+ trailingZeroDisplay?: 'auto' | 'stripIfInteger';
4
+ };
5
+ export declare function formatNumber(n: any, config?: FormatNumberConfig): string;
1
6
  /**
2
7
  * @description: 将秒数转换为中文
3
8
  * @param {number} seconds
4
9
  * @return {string}
5
10
  */
6
- declare function formatSecondsToChinese(seconds: number): string;
7
- export { formatSecondsToChinese };
11
+ export declare function formatSecondsToChinese(seconds: number): string;
12
+ export {};
package/utils/number.mjs CHANGED
@@ -1,5 +1,27 @@
1
+ import { isValidNumberString as e } from "./boolean.mjs";
1
2
  //#region src/utils/number.ts
2
- function e(e) {
3
+ function t(t, n) {
4
+ if (typeof t != "number" && typeof t != "string" || typeof t == "string" && e(t) === !1 || typeof t == "number" && Number.isFinite(t) === !1) return "";
5
+ let r = Number(t), i = {
6
+ currency: "CNY",
7
+ currencyDisplay: "symbol",
8
+ localeMatcher: "lookup",
9
+ maximumFractionDigits: 2,
10
+ minimumFractionDigits: 0,
11
+ notation: "standard",
12
+ numberingSystem: "latn",
13
+ style: "decimal",
14
+ trailingZeroDisplay: "stripIfInteger",
15
+ useGrouping: !0,
16
+ ...n ?? {}
17
+ };
18
+ try {
19
+ return new Intl.NumberFormat("zh-CN", i).format(r);
20
+ } catch (e) {
21
+ return console.error(e?.message ?? "格式化数字失败"), String(r);
22
+ }
23
+ }
24
+ function n(e) {
3
25
  let t = "", n = Math.floor(e / 3600);
4
26
  n > 0 && (t += `${n}时`);
5
27
  let r = Math.floor(e % 3600 / 60);
@@ -8,4 +30,4 @@ function e(e) {
8
30
  return i > 0 && (t += `${i}秒`), t;
9
31
  }
10
32
  //#endregion
11
- export { e as formatSecondsToChinese };
33
+ export { t as formatNumber, n as formatSecondsToChinese };
package/utils/string.d.ts CHANGED
@@ -4,6 +4,11 @@
4
4
  * @param {boolean} withExt 是否包含扩展名
5
5
  * @return {string}
6
6
  */
7
- declare function getFilenameFromUrl(url: string, withExt?: boolean): string;
8
- declare function queryStringToObject(queryString: string): Record<string, any>;
9
- export { getFilenameFromUrl, queryStringToObject };
7
+ export declare function getFilenameFromUrl(url: string, withExt?: boolean): string;
8
+ export declare function queryStringToObject(queryString: string): Record<string, any>;
9
+ /**
10
+ * @description: 将值转换为字符串,如果值为 null 或 undefined,则返回空字符串
11
+ * @example String(123n) -> '123' BigInt
12
+ * @return {string}
13
+ */
14
+ export declare function stringDisplay(val: any): string;
package/utils/string.mjs CHANGED
@@ -10,5 +10,8 @@ function e(e, t = !1) {
10
10
  function t(e) {
11
11
  return Object.fromEntries(new URLSearchParams(e));
12
12
  }
13
+ function n(e) {
14
+ return [null, void 0].includes(e) ? "" : String(e);
15
+ }
13
16
  //#endregion
14
- export { e as getFilenameFromUrl, t as queryStringToObject };
17
+ export { e as getFilenameFromUrl, t as queryStringToObject, n as stringDisplay };
package/utils/tool.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { default as FileSaver } from 'file-saver';
2
- declare function aesDecrypt(word: string, keyWord: string): Promise<string>;
3
- declare function aesEncrypt(word: string, keyWord: string): Promise<string>;
4
- declare function saveAs(arg1: Parameters<typeof FileSaver.saveAs>[0], arg2?: Parameters<typeof FileSaver.saveAs>[1], arg3?: FileSaver.FileSaverOptions): Promise<void>;
5
- export { aesDecrypt, aesEncrypt, saveAs };
2
+ export declare function aesDecrypt(word: string, keyWord: string): Promise<string>;
3
+ export declare function aesEncrypt(word: string, keyWord: string): Promise<string>;
4
+ export declare function saveAs(arg1: Parameters<typeof FileSaver.saveAs>[0], arg2?: Parameters<typeof FileSaver.saveAs>[1], arg3?: FileSaver.FileSaverOptions): Promise<void>;
@@ -0,0 +1,26 @@
1
+ interface TreeNode {
2
+ [key: string]: any;
3
+ children?: TreeNode[];
4
+ }
5
+ /**
6
+ * 将扁平数组转换为树形结构
7
+ * @param data 扁平数据数组
8
+ * @param options 配置选项
9
+ * @param options.childrenKey 子节点键名
10
+ * @param options.idKey 节点ID键名
11
+ * @param options.parentKey 节点父ID键名
12
+ * @param options.rootParentId 根节点ID键名
13
+ * @returns 树形结构数组
14
+ */
15
+ export declare function flatArrToTree(data: Record<string, any>[], options?: {
16
+ childrenKey?: string;
17
+ idKey?: string;
18
+ parentKey?: string;
19
+ rootParentId?: null | string;
20
+ }): TreeNode[];
21
+ export declare function treeToFlatArr(tree: TreeNode[], options?: {
22
+ idKey?: string;
23
+ includeLevel?: boolean;
24
+ includeParent?: boolean;
25
+ }): Record<string, any>[];
26
+ export {};
package/utils/tree.mjs ADDED
@@ -0,0 +1,36 @@
1
+ //#region src/utils/tree.ts
2
+ function e(e, t = {}) {
3
+ let { childrenKey: n = "children", idKey: r = "id", parentKey: i = "parentId", rootParentId: a = null } = t;
4
+ if (!Array.isArray(e)) throw TypeError("flatArrToTree: 输入参数 data 必须是数组");
5
+ if (e.length === 0) return [];
6
+ let o = [], s = /* @__PURE__ */ new Map();
7
+ for (let t of e) {
8
+ let e = t[r];
9
+ if (e == null) {
10
+ console.warn(`flatArrToTree: 数据项缺少 ${r} 属性`, t);
11
+ continue;
12
+ }
13
+ let n = {
14
+ ...t,
15
+ children: []
16
+ };
17
+ s.has(e) && console.warn(`flatArrToTree: 检测到重复的 ${r}: ${e}`), s.set(e, n);
18
+ }
19
+ for (let [e, t] of s) {
20
+ let e = t[i];
21
+ e == null || e === a || !s.has(e) ? o.push(t) : s.get(e)[n].push(t);
22
+ }
23
+ return o;
24
+ }
25
+ function t(e, t) {
26
+ let { idKey: n = "id", includeLevel: r = !1, includeParent: i = !1 } = t ?? {}, a = [];
27
+ function o(e, t = 0, s = null) {
28
+ Array.isArray(e) && e.forEach((e) => {
29
+ let { children: c, ...l } = e;
30
+ r && (l.level = t), i && (l.parentId = s), a.push(l), Array.isArray(c) && o(c, t + 1, e[n]);
31
+ });
32
+ }
33
+ return o(e), a;
34
+ }
35
+ //#endregion
36
+ export { e as flatArrToTree, t as treeToFlatArr };