@base-web-kits/base-tools-ts 1.4.9 → 1.4.10

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.
@@ -32,4 +32,15 @@ export declare const getObjectValue: typeof get;
32
32
  * setObjectValue(o, ['users', 1, 'name'], 'jane-doe'); // 数组路径
33
33
  */
34
34
  export declare const setObjectValue: typeof set;
35
+ /**
36
+ * 移除对象顶层值为 `undefined` 的可枚举自有字段,不改变原对象。
37
+ * - `null`、`false`、空字符串和 `0` 会被保留。
38
+ * - 即使对象中没有值为 `undefined` 的字段,也会返回新的浅拷贝;嵌套对象仍与原对象共享引用。
39
+ * @param obj 目标对象;传入 `undefined` 时返回空对象
40
+ * @returns 移除值为 `undefined` 的字段后生成的新对象
41
+ * @example
42
+ * const source = { name: 'Alice', age: undefined, enabled: false, score: 0 };
43
+ * const result = omitUndefined(source); // { name: 'Alice', enabled: false, score: 0 }
44
+ */
45
+ export declare function omitUndefined<T extends object>(obj?: T): T;
35
46
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/object/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAEtE;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,YAAM,CAAC;AAElC;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAAM,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ts/object/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAEtE;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,YAAM,CAAC;AAElC;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAAM,CAAC;AAElC;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAG1D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base-web-kits/base-tools-ts",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "sideEffects": false,
5
5
  "description": "Independent TS utilities package built from src/ts.",
6
6
  "keywords": [
@@ -27,6 +27,7 @@
27
27
  "dependencies": {
28
28
  "es-toolkit": "^1.44.0",
29
29
  "bignumber.js": "^9.1.2",
30
+ "clsx": "^2.1.1",
30
31
  "dayjs": "^1.11.19",
31
32
  "mitt": "^3.0.1"
32
33
  }
@@ -0,0 +1,3 @@
1
+ /** 根据字符串、数组和条件对象拼接 CSS 类名 */
2
+ export { clsx } from 'clsx';
3
+ export type { ClassValue } from 'clsx';
package/src/ts/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from './array';
5
5
  export * from './async';
6
6
  export * from './bean';
7
7
  export * from './buffer';
8
+ export * from './clsx';
8
9
  export * from './day';
9
10
  export * from './es-toolkit';
10
11
  export * from './number';
@@ -37,3 +37,18 @@ export const getObjectValue = get;
37
37
  * setObjectValue(o, ['users', 1, 'name'], 'jane-doe'); // 数组路径
38
38
  */
39
39
  export const setObjectValue = set;
40
+
41
+ /**
42
+ * 移除对象顶层值为 `undefined` 的可枚举自有字段,不改变原对象。
43
+ * - `null`、`false`、空字符串和 `0` 会被保留。
44
+ * - 即使对象中没有值为 `undefined` 的字段,也会返回新的浅拷贝;嵌套对象仍与原对象共享引用。
45
+ * @param obj 目标对象;传入 `undefined` 时返回空对象
46
+ * @returns 移除值为 `undefined` 的字段后生成的新对象
47
+ * @example
48
+ * const source = { name: 'Alice', age: undefined, enabled: false, score: 0 };
49
+ * const result = omitUndefined(source); // { name: 'Alice', enabled: false, score: 0 }
50
+ */
51
+ export function omitUndefined<T extends object>(obj?: T): T {
52
+ if (!obj) return {} as T;
53
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined)) as T;
54
+ }
@@ -1,5 +1,5 @@
1
1
  export * from './file';
2
- export * from './oss';
3
- export * from './param';
4
- export * from './path';
5
- export * from './qn';
2
+ export * from './oss';
3
+ export * from './param';
4
+ export * from './path';
5
+ export * from './qn';
@@ -14,7 +14,7 @@
14
14
  * // '/images/avatar.png'
15
15
  */
16
16
  export function joinUrlPath(...parts: Array<string | null | undefined>) {
17
- const values = parts.filter((part): part is string => !!part);
17
+ const values = parts.filter((part): part is string => !!part);
18
18
  if (!values.length) return '';
19
19
 
20
20
  const [first, ...rest] = values;