@semi-kit/utils 1.1.10 → 1.1.12

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/README.md CHANGED
@@ -1,23 +1,23 @@
1
- # tsdown-starter
2
-
3
- A starter for creating a TypeScript package.
4
-
5
- ## Development
6
-
7
- - Install dependencies:
8
-
9
- ```bash
10
- npm install
11
- ```
12
-
13
- - Run the unit tests:
14
-
15
- ```bash
16
- npm run test
17
- ```
18
-
19
- - Build the library:
20
-
21
- ```bash
22
- npm run build
23
- ```
1
+ # tsdown-starter
2
+
3
+ A starter for creating a TypeScript package.
4
+
5
+ ## Development
6
+
7
+ - Install dependencies:
8
+
9
+ ```bash
10
+ npm install
11
+ ```
12
+
13
+ - Run the unit tests:
14
+
15
+ ```bash
16
+ npm run test
17
+ ```
18
+
19
+ - Build the library:
20
+
21
+ ```bash
22
+ npm run build
23
+ ```
package/lib/color.d.mts CHANGED
@@ -1,8 +1,30 @@
1
+ /**
2
+ * 将 Hex 颜色值转换为 RGB 格式
3
+ * @param hex - 十六进制颜色值,例如 '#ffffff' 或 'ffffff'
4
+ * @returns RGB 对象,包含 r、g、b 三个属性
5
+ * @example
6
+ * hexToRgb('#ff0000') -> { r: 255, g: 0, b: 0 }
7
+ */
1
8
  declare const hexToRgb: (hex: string) => {
2
9
  r: number;
3
10
  g: number;
4
11
  b: number;
5
12
  };
13
+ /**
14
+ * 将 RGB 颜色值转换为 Hex 格式
15
+ * @param r - 红色值 (0-255)
16
+ * @param g - 绿色值 (0-255)
17
+ * @param b - 蓝色值 (0-255)
18
+ * @returns 十六进制颜色值字符串
19
+ * @example
20
+ * rgbToHex(255, 0, 0) -> '#ff0000'
21
+ */
6
22
  declare const rgbToHex: (r: number, g: number, b: number) => string;
23
+ /**
24
+ * 随机生成一个 Hex 颜色值
25
+ * @returns 随机的十六进制颜色值字符串
26
+ * @example
27
+ * randomHex() -> '#a3c2f0'
28
+ */
7
29
  declare const randomHex: () => string;
8
30
  export { hexToRgb, randomHex, rgbToHex };
package/lib/device.d.mts CHANGED
@@ -1,6 +1,26 @@
1
+ /**
2
+ * 判断是否是安卓设备
3
+ * @returns 如果是安卓设备返回 true,否则返回 false
4
+ */
1
5
  declare const isAndroidMobile: () => boolean;
6
+ /**
7
+ * 判断是否是苹果设备
8
+ * @returns 如果是苹果设备(iPhone/iPod/iPad/Mac)返回 true,否则返回 false
9
+ */
2
10
  declare const isAppleMobile: () => boolean;
11
+ /**
12
+ * 判断是否是微信内置浏览器
13
+ * @returns 如果是微信浏览器返回 true,否则返回 false
14
+ */
3
15
  declare const isWeChatBrowser: () => boolean;
16
+ /**
17
+ * 判断是否是 QQ 内置浏览器
18
+ * @returns 如果是 QQ 浏览器返回 true,否则返回 false
19
+ */
4
20
  declare const isQQBrowser: () => boolean;
21
+ /**
22
+ * 判断是否是移动设备
23
+ * @returns 如果是移动设备返回 true,否则返回 false
24
+ */
5
25
  declare const isMobile: () => boolean;
6
26
  export { isAndroidMobile, isAppleMobile, isMobile, isQQBrowser, isWeChatBrowser };
package/lib/extra.d.mts CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * 从源对象中提取目标对象中存在的属性,省略多余参数
3
+ * @param sourceData - 源数据对象
4
+ * @param targetData - 目标数据对象,确定需要保留的属性
5
+ * @returns 只包含目标对象中存在的属性
6
+ * @example
7
+ * useOmitExtraParams({ a: 1, b: 2, c: 3 }, { a: 1 })
8
+ */
1
9
  declare const useOmitExtraParams: (sourceData: object, targetData: object) => Pick<object, never>;
10
+ /** 占位符, 表示未定义 */
2
11
  declare const __: undefined;
3
12
  export { __, useOmitExtraParams };
@@ -1,5 +1,31 @@
1
+ /**
2
+ * 存储 localStorage
3
+ * @param key - 存储键名
4
+ * @param value - 存储值,会自动转换为 JSON 字符串
5
+ * @example
6
+ * setLocalStorage('user', { name: 'John', age: 30 })
7
+ */
1
8
  declare const setLocalStorage: (key: string, value: any) => void;
9
+ /**
10
+ * 获取 localStorage 数据
11
+ * @template T - 返回数据类型
12
+ * @param key - 存储键名
13
+ * @returns 解析后的数据,不存在则返回 null
14
+ * @example
15
+ * const user = getLocalStorage<User>('user')
16
+ */
2
17
  declare const getLocalStorage: <T>(key: string) => T | null;
18
+ /**
19
+ * 删除 localStorage 指定键
20
+ * @param key - 键名
21
+ * @example
22
+ * removeLocalStorage('user')
23
+ */
3
24
  declare const removeLocalStorage: (key: string) => void;
25
+ /**
26
+ * 清空 localStorage
27
+ * @example
28
+ * clearLocalStorage()
29
+ */
4
30
  declare const clearLocalStorage: () => void;
5
31
  export { clearLocalStorage, getLocalStorage, removeLocalStorage, setLocalStorage };
package/lib/number.d.mts CHANGED
@@ -1,6 +1,45 @@
1
+ /**
2
+ * 数字千分位分隔
3
+ * @param val - 需要格式化的数字
4
+ * @returns 千分位分隔后的字符串
5
+ * @example
6
+ * formatNumberWithCommas(1234567) -> '1,234,567'
7
+ */
1
8
  declare const formatNumberWithCommas: (val: number) => string;
9
+ /**
10
+ * 生成指定范围内的随机整数
11
+ * @param min - 最小值(包含)
12
+ * @param max - 最大值(包含)
13
+ * @returns 指定范围内的随机整数
14
+ * @example
15
+ * getRandomNum(1, 10) -> 7
16
+ */
2
17
  declare const getRandomNum: (min: number, max: number) => number;
18
+ /**
19
+ * 隐藏手机号中间四位
20
+ * @param phone - 手机号,支持字符串或数字
21
+ * @returns 脱敏后的手机号
22
+ * @example
23
+ * maskedPhoneNumber('13812345678') -> '138****5678'
24
+ */
3
25
  declare const maskedPhoneNumber: (phone: string | number) => string;
26
+ /**
27
+ * 格式化手机号,添加分隔符
28
+ * @param phone - 手机号字符串
29
+ * @param separator - 分隔符,默认为 '-'
30
+ * @returns 格式化后的手机号
31
+ * @example
32
+ * formatPhoneNumber('13812345678') -> '138-1234-5678'
33
+ * formatPhoneNumber('13812345678', ' ') -> '138 1234 5678'
34
+ */
4
35
  declare const formatPhoneNumber: (phone: string, separator?: string) => string;
36
+ /**
37
+ * 判断数字是否为偶数
38
+ * @param val - 需要判断的数字
39
+ * @returns 如果是偶数返回 true,否则返回 false
40
+ * @example
41
+ * isEven(4) -> true
42
+ * isEven(3) -> false
43
+ */
5
44
  declare const isEven: (val: number) => boolean;
6
45
  export { formatNumberWithCommas, formatPhoneNumber, getRandomNum, isEven, maskedPhoneNumber };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semi-kit/utils",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "General-purpose tool function library",
5
5
  "type": "module",
6
6
  "license": "MIT",