pen-it 1.0.6 → 1.0.8

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.
@@ -2,22 +2,12 @@
2
2
  * 判断一个值是否为数组
3
3
  * @param value - 要判断的值
4
4
  * @returns 如果是数组返回 true,否则返回 false
5
- * @example
6
- * isArray([1, 2, 3])
7
- * // => true
8
- * isArray("hello")
9
- * // => false
10
5
  */
11
6
  export declare const isArray: (value: any) => boolean;
12
7
  /**
13
8
  * 判断一个值是否为对象(但不是数组)
14
9
  * @param value - 要判断的值
15
10
  * @returns 如果是对象且不是数组返回 true,否则返回 false
16
- * @example
17
- * isObject({ a: 1 })
18
- * // => true
19
- * isObject([1, 2])
20
- * // => false
21
11
  */
22
12
  export declare const isObject: (value: any) => boolean;
23
13
  /**
@@ -25,205 +15,124 @@ export declare const isObject: (value: any) => boolean;
25
15
  * @param val - 要判断的数据
26
16
  * @param type - 数据类型字符串,如 "Array"、"Function"
27
17
  * @returns 如果数据是指定类型返回 true
28
- * @example
29
- * is([], "Array")
30
- * // => true
31
18
  */
32
19
  export declare const is: (val: unknown, type: string) => boolean;
33
20
  /**
34
21
  * 判断一个值是否为函数
35
22
  * @param val - 要判断的数据
36
23
  * @returns 如果是函数返回 true
37
- * @example
38
- * isFunction(() => {})
39
- * // => true
40
24
  */
41
25
  export declare const isFunction: (val: any) => val is Function;
42
26
  /**
43
27
  * 判断一个值是否为 Date 对象
44
28
  * @param val - 要判断的数据
45
29
  * @returns 如果是 Date 对象返回 true
46
- * @example
47
- * isDate(new Date())
48
- * // => true
49
30
  */
50
31
  export declare const isDate: (val: any) => val is Date;
51
32
  /**
52
33
  * 判断一个值是否为数字(NaN 和 Infinity 也视为数字)
53
34
  * @param val - 要判断的数据
54
35
  * @returns 如果是数字返回 true
55
- * @example
56
- * isNumber(42)
57
- * // => true
58
- * isNumber("42")
59
- * // => false
60
36
  */
61
37
  export declare const isNumber: (val: any) => val is number;
62
38
  /**
63
39
  * 判断一个值是否为整数
64
40
  * @param val - 要判断的数据
65
41
  * @returns 如果是整数返回 true
66
- * @example
67
- * isInt(42)
68
- * // => true
69
- * isInt(3.14)
70
- * // => false
71
42
  */
72
43
  export declare const isInt: (val: any) => val is number;
73
44
  /**
74
45
  * 判断一个值是否为浮点数(有限小数)
75
46
  * @param val - 要判断的数据
76
47
  * @returns 如果是浮点数返回 true
77
- * @example
78
- * isFloat(3.14)
79
- * // => true
80
- * isFloat(42)
81
- * // => false
82
48
  */
83
49
  export declare const isFloat: (val: any) => val is number;
84
50
  /**
85
51
  * 判断一个值是否为异步函数
86
52
  * @param val - 要判断的数据
87
53
  * @returns 如果是异步函数返回 true
88
- * @example
89
- * isAsyncFunction(async () => {})
90
- * // => true
91
54
  */
92
55
  export declare const isAsyncFunction: (val: unknown) => val is (...args: any[]) => Promise<any>;
93
56
  /**
94
57
  * 判断一个值是否为 Promise
95
58
  * @param value - 要判断的数据
96
59
  * @returns 如果是 Promise 返回 true
97
- * @example
98
- * isPromise(Promise.resolve())
99
- * // => true
100
60
  */
101
61
  export declare const isPromise: (value: any) => value is Promise<any>;
102
62
  /**
103
63
  * 判断一个值是否为字符串
104
64
  * @param val - 要判断的数据
105
65
  * @returns 如果是字符串返回 true
106
- * @example
107
- * isString("hello")
108
- * // => true
109
- * isString(42)
110
- * // => false
111
66
  */
112
67
  export declare const isString: (val: unknown) => val is string;
113
68
  /**
114
69
  * 判断一个值是否为布尔值
115
70
  * @param val - 要判断的数据
116
71
  * @returns 如果是布尔值返回 true
117
- * @example
118
- * isBoolean(true)
119
- * // => true
120
- * isBoolean(1)
121
- * // => false
122
72
  */
123
73
  export declare const isBoolean: (val: unknown) => val is boolean;
124
74
  /**
125
75
  * 判断是否为 PC 端(浏览器环境)
126
76
  * @returns 如果在浏览器环境中返回 true
127
- * @example
128
- * isPC()
129
- * // => true(在浏览器中)
130
77
  */
131
78
  export declare const isPC: () => boolean;
132
79
  /**
133
80
  * 判断一个值是否为 window 对象
134
81
  * @param val - 要判断的数据
135
82
  * @returns 如果是 window 对象返回 true
136
- * @example
137
- * isWindow(window)
138
- * // => true(在浏览器中)
139
83
  */
140
84
  export declare const isWindow: (val: any) => val is Window;
141
85
  /**
142
86
  * 判断一个值是否为 DOM 元素
143
87
  * @param val - 要判断的数据
144
88
  * @returns 如果是 DOM 元素返回 true
145
- * @example
146
- * isElement(document.body)
147
- * // => true
148
89
  */
149
90
  export declare const isElement: (val: unknown) => val is Element;
150
91
  /**
151
92
  * 判断一个值是否为 null
152
93
  * @param val - 要判断的数据
153
94
  * @returns 如果是 null 返回 true
154
- * @example
155
- * isNull(null)
156
- * // => true
157
95
  */
158
96
  export declare const isNull: (val: unknown) => val is null;
159
97
  /**
160
98
  * 判断一个值是否为十六进制颜色
161
99
  * @param str - 要判断的字符串
162
100
  * @returns 如果是有效的十六进制颜色值返回 true
163
- * @example
164
- * isHexColor("#fff")
165
- * // => true
166
- * isHexColor("#ff0000")
167
- * // => true
168
101
  */
169
102
  export declare const isHexColor: (str: string) => boolean;
170
103
  /**
171
104
  * 判断设备是否为 iOS
172
105
  * @returns 如果是 iOS 设备返回 true
173
- * @example
174
- * isIOS()
175
- * // => true(在 iPhone/iPad 上)
176
106
  */
177
107
  export declare const isIOS: () => boolean;
178
108
  /**
179
109
  * 判断一个值是否为有效的电子邮件
180
110
  * @param email - 要判断的字符串
181
111
  * @returns 如果是有效的电子邮件地址返回 true
182
- * @example
183
- * isValidEmail("test@example.com")
184
- * // => true
185
112
  */
186
113
  export declare const isValidEmail: (email: string) => boolean;
187
114
  /**
188
115
  * 判断一个值是否已定义(不是 undefined)
189
116
  * @param val - 要判断的数据
190
117
  * @returns 如果不是 undefined 返回 true
191
- * @example
192
- * isDef("hello")
193
- * // => true
194
- * isDef(undefined)
195
- * // => false
196
118
  */
197
119
  export declare const isDef: <T>(val: T | undefined) => val is T;
198
120
  /**
199
121
  * 判断一个值是否为 undefined
200
122
  * @param val - 要判断的数据
201
123
  * @returns 如果是 undefined 返回 true
202
- * @example
203
- * isUnDef(undefined)
204
- * // => true
205
124
  */
206
125
  export declare const isUnDef: <T>(val: T | undefined) => val is undefined;
207
126
  /**
208
127
  * 判断一个值是否为 null 或 undefined
209
128
  * @param val - 要判断的数据
210
129
  * @returns 如果是 null 或 undefined 返回 true
211
- * @example
212
- * isNullOrUnDef(null)
213
- * // => true
214
- * isNullOrUnDef(undefined)
215
- * // => true
216
- * isNullOrUnDef("hello")
217
- * // => false
218
130
  */
219
131
  export declare const isNullOrUnDef: <T>(val: T | null | undefined) => val is null | undefined;
220
132
  /**
221
133
  * 判断一个值是否为 symbol
222
134
  * @param value - 要判断的数据
223
135
  * @returns 如果是 symbol 返回 true
224
- * @example
225
- * isSymbol(Symbol("foo"))
226
- * // => true
227
136
  */
228
137
  export declare const isSymbol: (value: any) => value is symbol;
229
138
  /**
@@ -231,11 +140,6 @@ export declare const isSymbol: (value: any) => value is symbol;
231
140
  * 原始类型包括:number、string、boolean、symbol、bigint、undefined、null
232
141
  * @param value - 要判断的值
233
142
  * @returns 如果是原始类型返回 true
234
- * @example
235
- * isPrimitive(42)
236
- * // => true
237
- * isPrimitive({})
238
- * // => false
239
143
  */
240
144
  export declare const isPrimitive: (value: any) => boolean;
241
145
  /**
@@ -243,13 +147,6 @@ export declare const isPrimitive: (value: any) => boolean;
243
147
  * 空值包括:null、undefined、空字符串、空数组、空对象、空 Map/Set、无效 Date
244
148
  * @param value - 要判断的数据
245
149
  * @returns 如果为空返回 true
246
- * @example
247
- * isEmpty("")
248
- * // => true
249
- * isEmpty([])
250
- * // => true
251
- * isEmpty(0)
252
- * // => false
253
150
  */
254
151
  export declare const isEmpty: (value: any) => boolean;
255
152
  /**
@@ -257,19 +154,6 @@ export declare const isEmpty: (value: any) => boolean;
257
154
  * 支持:字符串、数组、对象、Map、Set、类型化数组
258
155
  * @param value - 要检查的值
259
156
  * @returns 如果为空返回 true
260
- * @example
261
- * isEmptySv("")
262
- * // => true
263
- * isEmptySv(null)
264
- * // => true
265
- * isEmptySv([])
266
- * // => true
267
- * isEmptySv({})
268
- * // => true
269
- * isEmptySv(new Set())
270
- * // => true
271
- * isEmptySv(new Map())
272
- * // => true
273
157
  */
274
158
  export declare function isEmptySv(value: string | object | null | undefined): boolean;
275
159
  /**
@@ -277,10 +161,5 @@ export declare function isEmptySv(value: string | object | null | undefined): bo
277
161
  * @param x - 要比较的第一个值
278
162
  * @param y - 要比较的第二个值
279
163
  * @returns 如果值深度相等返回 true
280
- * @example
281
- * isEqual({ a: 1 }, { a: 1 })
282
- * // => true
283
- * isEqual({ a: 1 }, { a: 2 })
284
- * // => false
285
164
  */
286
165
  export declare const isEqual: <T>(x: T, y: T) => boolean;
@@ -2,29 +2,20 @@
2
2
  * 获取 localStorage
3
3
  * @param key - 存储键名
4
4
  * @returns 解析后的值,解析失败则返回原始字符串,键不存在返回 null
5
- * @example
6
- * localGet("user")
7
- * // => { name: "张三" }
8
5
  */
9
6
  export declare const localGet: <T = any>(key: string) => T | null;
10
7
  /**
11
8
  * 设置 localStorage
12
9
  * @param key - 存储键名
13
10
  * @param value - 存储值(会自动 JSON 序列化)
14
- * @example
15
- * localSet("user", { name: "张三" })
16
11
  */
17
12
  export declare const localSet: (key: string, value: unknown) => void;
18
13
  /**
19
14
  * 移除指定 localStorage
20
15
  * @param key - 存储键名
21
- * @example
22
- * localRm("user")
23
16
  */
24
17
  export declare const localRm: (key: string) => void;
25
18
  /**
26
19
  * 清除所有 localStorage
27
- * @example
28
- * localClear()
29
20
  */
30
21
  export declare const localClear: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pen-it",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "用笔锚定记忆中的前端常用工具函数,一个轻量级的前端实用程序库,支持类型检查、日期/数字格式化、字符串操作、数据存储、深度克隆、数组操作、Cookie 以及浏览器 API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -21,23 +21,15 @@
21
21
  "dist"
22
22
  ],
23
23
  "keywords": [
24
+ "pen-it",
24
25
  "utils",
25
- "utilities",
26
- "toolkit",
27
- "helpers",
28
- "frontend",
29
- "typescript",
30
- "type-checking",
31
- "date-format",
32
- "number-format",
33
- "deep-clone",
34
- "string-manipulation",
35
- "array-operations",
26
+ "function",
27
+ "copy",
36
28
  "cookie",
37
- "localstorage",
38
- "browser-api",
39
- "debounce",
40
- "throttle"
29
+ "format",
30
+ "data types",
31
+ "storage",
32
+ "browser"
41
33
  ],
42
34
  "author": "newborn_calf",
43
35
  "license": "MIT",