@aiao/utils 0.0.1

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.
Files changed (134) hide show
  1. package/@browser/IdleTimer.d.ts +18 -0
  2. package/@browser/broadcast-channel-pool.d.ts +17 -0
  3. package/@browser/index.d.ts +4 -0
  4. package/@browser/leader-election.d.ts +7 -0
  5. package/@browser/perform-chunk.d.ts +9 -0
  6. package/README.md +1 -0
  7. package/array/chunk.d.ts +24 -0
  8. package/array/difference.d.ts +30 -0
  9. package/array/flatten.d.ts +24 -0
  10. package/array/flattenDeep.d.ts +25 -0
  11. package/array/index.d.ts +8 -0
  12. package/array/intersection.d.ts +29 -0
  13. package/array/needArray.d.ts +37 -0
  14. package/array/sortBy.d.ts +36 -0
  15. package/async/index.d.ts +2 -0
  16. package/async/next-tick.d.ts +28 -0
  17. package/async/sleep.d.ts +5 -0
  18. package/binary/index.d.ts +1 -0
  19. package/binary/uint8ArrayToString.d.ts +12 -0
  20. package/collection/index.d.ts +1 -0
  21. package/collection/traverseObjectKeys.d.ts +3 -0
  22. package/crypto/aesDecrypt.d.ts +8 -0
  23. package/crypto/aesEncrypt.d.ts +10 -0
  24. package/crypto/base64Decode.d.ts +6 -0
  25. package/crypto/base64Encode.d.ts +6 -0
  26. package/crypto/decodeJWTPayload.d.ts +6 -0
  27. package/crypto/index.d.ts +8 -0
  28. package/crypto/rsaDecrypt.d.ts +7 -0
  29. package/crypto/rsaEncrypt.d.ts +8 -0
  30. package/crypto/rsaGenerateKey.d.ts +5 -0
  31. package/date/canBeDate.d.ts +5 -0
  32. package/date/dateStringToDate.d.ts +7 -0
  33. package/date/dateStringWithTimezone.d.ts +11 -0
  34. package/date/formatCountdown.d.ts +12 -0
  35. package/date/formatPassTime.d.ts +10 -0
  36. package/date/index.d.ts +12 -0
  37. package/date/isISODateString.d.ts +6 -0
  38. package/date/isMSTime.d.ts +7 -0
  39. package/date/msTimeToMilliseconds.d.ts +12 -0
  40. package/date/parseTime.d.ts +9 -0
  41. package/date/stringTime.d.ts +3 -0
  42. package/date/unixTimestamp.d.ts +5 -0
  43. package/function/debounce.d.ts +2 -0
  44. package/function/emptyFunction.d.ts +4 -0
  45. package/function/index.d.ts +4 -0
  46. package/function/once.d.ts +27 -0
  47. package/function/throttle.d.ts +30 -0
  48. package/index.d.ts +18 -0
  49. package/index.js +955 -0
  50. package/indexing/fractional-indexing.d.ts +26 -0
  51. package/number/canBeNumber.d.ts +27 -0
  52. package/number/index.d.ts +6 -0
  53. package/number/numberStep.d.ts +19 -0
  54. package/number/numberStepScreenSize.d.ts +1 -0
  55. package/number/numberStrip.d.ts +21 -0
  56. package/number/toInt.d.ts +1 -0
  57. package/number/tryToNumber.d.ts +1 -0
  58. package/object/deepFreeze.d.ts +5 -0
  59. package/object/flattenPathObjectToPlainObject.d.ts +7 -0
  60. package/object/get.d.ts +23 -0
  61. package/object/getTag.d.ts +1 -0
  62. package/object/has.d.ts +20 -0
  63. package/object/index.d.ts +15 -0
  64. package/object/isEqual.d.ts +25 -0
  65. package/object/isEqualUint8Array.d.ts +1 -0
  66. package/object/omit.d.ts +24 -0
  67. package/object/omitBy.d.ts +7 -0
  68. package/object/pick.d.ts +24 -0
  69. package/object/pickBy.d.ts +1 -0
  70. package/object/plainObjectToFlattenPathObject.d.ts +8 -0
  71. package/object/set.d.ts +27 -0
  72. package/object/setWith.d.ts +12 -0
  73. package/object/toPlainObject.d.ts +1 -0
  74. package/object/zipObject.d.ts +9 -0
  75. package/package.json +20 -0
  76. package/platform/index.d.ts +1 -0
  77. package/platform/is-browser.d.ts +4 -0
  78. package/random/index.d.ts +6 -0
  79. package/random/randomArrayItem.d.ts +1 -0
  80. package/random/randomFloat.d.ts +1 -0
  81. package/random/randomInt.d.ts +7 -0
  82. package/random/randomString.d.ts +9 -0
  83. package/random/randomUintByLength.d.ts +1 -0
  84. package/random/randomUintString.d.ts +1 -0
  85. package/string/camelCase.d.ts +22 -0
  86. package/string/capitalize.d.ts +7 -0
  87. package/string/compressToBase64Url.d.ts +4 -0
  88. package/string/decompressFromBase64Url.d.ts +4 -0
  89. package/string/getWords.d.ts +1 -0
  90. package/string/index.d.ts +17 -0
  91. package/string/kebabCase.d.ts +9 -0
  92. package/string/parseChineseNumber.d.ts +1 -0
  93. package/string/queryParse.d.ts +1 -0
  94. package/string/queryStringify.d.ts +5 -0
  95. package/string/rmb.d.ts +6 -0
  96. package/string/similarity.d.ts +1 -0
  97. package/string/snakeCase.d.ts +10 -0
  98. package/string/startCase.d.ts +7 -0
  99. package/string/stringSingleline.d.ts +4 -0
  100. package/string/stringTemplate.d.ts +7 -0
  101. package/string/stringToArrayBuffer.d.ts +7 -0
  102. package/string/uncapitalize.d.ts +7 -0
  103. package/string/urlJoin.d.ts +1 -0
  104. package/tools/event.d.ts +18 -0
  105. package/tools/image.d.ts +2 -0
  106. package/tools/index.d.ts +3 -0
  107. package/tools/log.d.ts +4 -0
  108. package/type-definition/index.d.ts +1 -0
  109. package/type-definition/result-types.d.ts +11 -0
  110. package/types/AnyFunction.d.ts +20 -0
  111. package/types/DeepPartial.d.ts +48 -0
  112. package/types/index.d.ts +24 -0
  113. package/types/isArray.d.ts +19 -0
  114. package/types/isArrayBuffer.d.ts +23 -0
  115. package/types/isBoolean.d.ts +27 -0
  116. package/types/isDate.d.ts +25 -0
  117. package/types/isEmpty.d.ts +40 -0
  118. package/types/isFloat.d.ts +1 -0
  119. package/types/isFunction.d.ts +2 -0
  120. package/types/isInt.d.ts +1 -0
  121. package/types/isIntArray.d.ts +1 -0
  122. package/types/isNil.d.ts +20 -0
  123. package/types/isNumber.d.ts +29 -0
  124. package/types/isNumberArray.d.ts +1 -0
  125. package/types/isObject.d.ts +22 -0
  126. package/types/isObjectLike.d.ts +1 -0
  127. package/types/isPlainObject.d.ts +27 -0
  128. package/types/isPrimitive.d.ts +33 -0
  129. package/types/isPromise.d.ts +1 -0
  130. package/types/isRegExp.d.ts +23 -0
  131. package/types/isString.d.ts +22 -0
  132. package/types/isStringArray.d.ts +1 -0
  133. package/types/isSymbol.d.ts +1 -0
  134. package/types/isUint8Array.d.ts +25 -0
@@ -0,0 +1,11 @@
1
+ import { XOR } from 'ts-xor';
2
+ export interface SuccessResult<SuccessDataType = any> {
3
+ data: SuccessDataType;
4
+ }
5
+ export interface ErrorResult<ErrorDataType = any> {
6
+ error: ErrorDataType;
7
+ }
8
+ /**
9
+ * 结果返回类型
10
+ */
11
+ export type Result<SuccessDataType = any, ErrorDataType = any> = XOR<SuccessResult<SuccessDataType>, ErrorResult<ErrorDataType>>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 通用函数类型,可接受任意参数并返回任意类型
3
+ * 用于需要表示各种函数类型的场景,提供最大的灵活性
4
+ *
5
+ * @example
6
+ * // 匹配无参数函数
7
+ * const func1: AnyFunction = () => 'hello';
8
+ *
9
+ * @example
10
+ * // 匹配带参数函数
11
+ * const func2: AnyFunction = (a: number, b: string) => a + b;
12
+ *
13
+ * @example
14
+ * // 匹配异步函数
15
+ * const func3: AnyFunction = async () => { await Promise.resolve(); return 42; };
16
+ *
17
+ * @note 此类型提供了最大的灵活性,但牺牲了类型安全性
18
+ * @note 对于需要类型安全的场景,建议使用更具体的函数类型
19
+ */
20
+ export type AnyFunction = (...args: any[]) => any;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * 创建一个类型的深度部分类型
3
+ * 所有属性(包括嵌套对象和数组元素的属性)都变为可选
4
+ *
5
+ * @template T - 要创建深度部分类型的原始类型
6
+ * @example
7
+ * // 基本用法
8
+ * interface User {
9
+ * name: string;
10
+ * age: number;
11
+ * address: {
12
+ * street: string;
13
+ * city: string;
14
+ * };
15
+ * hobbies: string[];
16
+ * }
17
+ *
18
+ * // 深度部分类型
19
+ * const partialUser: DeepPartial<User> = {
20
+ * name: 'John',
21
+ * address: {
22
+ * street: 'Main St',
23
+ * },
24
+ * hobbies: ['reading'],
25
+ * };
26
+ *
27
+ * @example
28
+ * // 嵌套数组
29
+ * interface Data {
30
+ * items: {
31
+ * id: number;
32
+ * name: string;
33
+ * }[];
34
+ * }
35
+ *
36
+ * const partialData: DeepPartial<Data> = {
37
+ * items: [{
38
+ * id: 1,
39
+ * }],
40
+ * };
41
+ *
42
+ * @note 此类型递归地将所有属性变为可选,包括嵌套对象和数组元素
43
+ * @note 对于数组类型,会递归应用到数组元素的类型
44
+ * @note 对于只读数组,保持其只读特性的同时递归应用到元素类型
45
+ */
46
+ export declare type DeepPartial<T> = {
47
+ [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer UE> ? ReadonlyArray<DeepPartial<UE>> : DeepPartial<T[P]>;
48
+ };
@@ -0,0 +1,24 @@
1
+ export * from './AnyFunction';
2
+ export * from './DeepPartial';
3
+ export * from './isArray';
4
+ export * from './isArrayBuffer';
5
+ export * from './isBoolean';
6
+ export * from './isDate';
7
+ export * from './isEmpty';
8
+ export { isFloat } from './isFloat';
9
+ export * from './isFunction';
10
+ export * from './isInt';
11
+ export * from './isIntArray';
12
+ export * from './isNil';
13
+ export * from './isNumber';
14
+ export * from './isNumberArray';
15
+ export * from './isObject';
16
+ export * from './isObjectLike';
17
+ export * from './isPlainObject';
18
+ export { isPrimitive } from './isPrimitive';
19
+ export * from './isPromise';
20
+ export { isRegExp } from './isRegExp';
21
+ export * from './isString';
22
+ export * from './isStringArray';
23
+ export * from './isSymbol';
24
+ export { isUint8Array } from './isUint8Array';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 检查值是否为数组
3
+ * 这是对JavaScript内置Array.isArray函数的重导出
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是数组则返回true,否则返回false
7
+ * @example
8
+ * isArray([]); // 返回 true
9
+ * @example
10
+ * isArray([1, 2, 3]); // 返回 true
11
+ * @example
12
+ * isArray({}); // 返回 false(对象不是数组)
13
+ * @example
14
+ * isArray(null); // 返回 false(null不是数组)
15
+ * @example
16
+ * isArray("array"); // 返回 false(字符串不是数组)
17
+ * @note 这是对原生Array.isArray函数的直接重导出,保持与原生函数相同的行为
18
+ */
19
+ export declare const isArray: (arg: any) => arg is any[];
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 检查值是否为ArrayBuffer类型
3
+ * 使用instanceof运算符进行判断
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是ArrayBuffer则返回true,否则返回false
7
+ * @example
8
+ * isArrayBuffer(new ArrayBuffer(8)); // 返回 true
9
+ * @example
10
+ * isArrayBuffer(new ArrayBuffer(0)); // 返回 true(空的ArrayBuffer)
11
+ * @example
12
+ * isArrayBuffer([]); // 返回 false(数组不是ArrayBuffer)
13
+ * @example
14
+ * isArrayBuffer(null); // 返回 false(null不是ArrayBuffer)
15
+ * @example
16
+ * isArrayBuffer(undefined); // 返回 false(undefined不是ArrayBuffer)
17
+ * @example
18
+ * isArrayBuffer(new Uint8Array()); // 返回 false(Uint8Array不是ArrayBuffer)
19
+ * @note 函数使用instanceof运算符判断是否为ArrayBuffer实例
20
+ * @note ArrayBuffer是用于表示通用的、固定长度的原始二进制数据缓冲区
21
+ * @note 与TypedArray(如Uint8Array)的区别:ArrayBuffer是原始二进制数据,而TypedArray是对其的视图
22
+ */
23
+ export declare const isArrayBuffer: (value: unknown) => value is ArrayBuffer;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 检查值是否为布尔类型
3
+ * 支持直接布尔值、布尔对象和实现了valueOf()返回布尔值的对象
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是布尔类型则返回true,否则返回false
7
+ * @example
8
+ * isBoolean(true); // 返回 true
9
+ * @example
10
+ * isBoolean(false); // 返回 true
11
+ * @example
12
+ * isBoolean(new Boolean(true)); // 返回 true(布尔对象)
13
+ * @example
14
+ * isBoolean('true'); // 返回 false(字符串不是布尔类型)
15
+ * @example
16
+ * isBoolean(1); // 返回 false(数字1不是布尔类型)
17
+ * @example
18
+ * isBoolean(0); // 返回 false(数字0不是布尔类型)
19
+ * @example
20
+ * isBoolean(null); // 返回 false(null不是布尔类型)
21
+ * @example
22
+ * isBoolean(undefined); // 返回 false(undefined不是布尔类型)
23
+ * @note 函数使用三种方式判断:直接比较true/false、检查valueOf()返回值类型
24
+ * @note 对于布尔对象(new Boolean()),valueOf()返回其原始布尔值
25
+ * @note 与typeof的区别:typeof new Boolean(true)返回'object',但isBoolean返回true
26
+ */
27
+ export declare function isBoolean(value: any): value is boolean;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 检查值是否为Date对象
3
+ * 使用instanceof和Object.prototype.toString.call()两种方式进行判断
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是Date对象则返回true,否则返回false
7
+ * @example
8
+ * isDate(new Date()); // 返回 true
9
+ * @example
10
+ * isDate(new Date('2023-01-01')); // 返回 true
11
+ * @example
12
+ * isDate('2023-01-01'); // 返回 false(字符串不是Date对象)
13
+ * @example
14
+ * isDate(null); // 返回 false(null不是Date对象)
15
+ * @example
16
+ * isDate(undefined); // 返回 false(undefined不是Date对象)
17
+ * @example
18
+ * isDate({}); // 返回 false(普通对象不是Date对象)
19
+ * @example
20
+ * isDate(new Date('invalid date')); // 返回 true(即使是无效日期也是Date对象)
21
+ * @note 函数使用两种方式判断:instanceof和Object.prototype.toString.call()
22
+ * @note 对于无效日期(Invalid Date),函数仍返回true,因为它仍是Date对象
23
+ * @note 与isDateString的区别:此函数检查是否为Date对象,而非日期字符串
24
+ */
25
+ export declare function isDate(value: unknown): value is Date;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 检查值是否为空
3
+ * 支持多种类型的空值判断,包括null、undefined、空字符串、空数组、空对象等
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值为空则返回true,否则返回false
7
+ * @example
8
+ * isEmpty(null); // 返回 true
9
+ * @example
10
+ * isEmpty(undefined); // 返回 true
11
+ * @example
12
+ * isEmpty(''); // 返回 true(空字符串)
13
+ * @example
14
+ * isEmpty([]); // 返回 true(空数组)
15
+ * @example
16
+ * isEmpty({}); // 返回 true(空对象)
17
+ * @example
18
+ * isEmpty(0); // 返回 true(数字0)
19
+ * @example
20
+ * isEmpty(false); // 返回 true(布尔值false)
21
+ * @example
22
+ * isEmpty(new Date('invalid date')); // 返回 true(无效日期)
23
+ * @example
24
+ * isEmpty('hello'); // 返回 false(非空字符串)
25
+ * @example
26
+ * isEmpty([1, 2]); // 返回 false(非空数组)
27
+ * @example
28
+ * isEmpty({ name: 'John' }); // 返回 false(非空对象)
29
+ * @example
30
+ * isEmpty(42); // 返回 false(非零数字)
31
+ * @example
32
+ * isEmpty(() => {}); // 返回 false(函数)
33
+ * @example
34
+ * isEmpty(Symbol('foo')); // 返回 false(符号)
35
+ * @note 空值定义:null、undefined、空字符串、空数组、空对象、数字0、布尔值false、无效日期
36
+ * @note 函数和符号类型永远不会被视为空值
37
+ * @note 对于有length属性的对象(如数组、字符串),length为0时视为空
38
+ * @note 对于有size属性的对象(如Map、Set),size为0时视为空
39
+ */
40
+ export declare const isEmpty: (value: unknown) => boolean;
@@ -0,0 +1 @@
1
+ export declare const isFloat: (value: any) => value is number;
@@ -0,0 +1,2 @@
1
+ import { AnyFunction } from './AnyFunction';
2
+ export declare const isFunction: (value: any) => value is AnyFunction;
@@ -0,0 +1 @@
1
+ export declare const isInt: (value: any) => value is number;
@@ -0,0 +1 @@
1
+ export declare function isIntArray(value: unknown): value is number[];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 检查值是否为null或undefined
3
+ * 使用严格相等(===)进行比较
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是null或undefined则返回true,否则返回false
7
+ * @example
8
+ * isNil(null); // 返回 true
9
+ * @example
10
+ * isNil(undefined); // 返回 true
11
+ * @example
12
+ * isNil(0); // 返回 false(0不是null或undefined)
13
+ * @example
14
+ * isNil(''); // 返回 false(空字符串不是null或undefined)
15
+ * @example
16
+ * isNil(false); // 返回 false(false不是null或undefined)
17
+ * @note 此函数在判断null和undefined时使用严格相等运算符(===)
18
+ * @note 与isEmpty的区别:isNil仅检查null和undefined,而isEmpty还会检查空字符串、空数组等
19
+ */
20
+ export declare const isNil: (value: unknown) => value is null | undefined;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 检查值是否为有效数字(排除NaN)
3
+ * 使用Number(value) === value进行判断,确保值是数字且不是NaN
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是有效数字则返回true,否则返回false
7
+ * @example
8
+ * isNumber(123); // 返回 true
9
+ * @example
10
+ * isNumber(0); // 返回 true
11
+ * @example
12
+ * isNumber(-42); // 返回 true
13
+ * @example
14
+ * isNumber(3.14); // 返回 true
15
+ * @example
16
+ * isNumber(NaN); // 返回 false(NaN不是有效数字)
17
+ * @example
18
+ * isNumber('123'); // 返回 false(字符串不是数字)
19
+ * @example
20
+ * isNumber(null); // 返回 false(null不是数字)
21
+ * @example
22
+ * isNumber(undefined); // 返回 false(undefined不是数字)
23
+ * @example
24
+ * isNumber(new Number(123)); // 返回 false(Number对象不是数字字面量)
25
+ * @note 与typeof的区别:typeof NaN返回'number',但isNumber(NaN)返回false
26
+ * @note 函数使用try-catch块处理可能的类型转换异常
27
+ * @note 数字字面量和Infinity都会返回true(Infinity是有效数字)
28
+ */
29
+ export declare const isNumber: (value: any) => value is number;
@@ -0,0 +1 @@
1
+ export declare function isNumberArray(value: unknown): value is number[];
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 检查值是否为纯对象(通过Object构造函数创建的对象)
3
+ * 排除数组、null、日期、正则表达式等特殊对象
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是纯对象则返回true,否则返回false
7
+ * @example
8
+ * isObject({}); // 返回 true
9
+ * @example
10
+ * isObject({ a: 1 }); // 返回 true
11
+ * @example
12
+ * isObject([]); // 返回 false(数组不是纯对象)
13
+ * @example
14
+ * isObject(null); // 返回 false(null不是对象)
15
+ * @example
16
+ * isObject(new Date()); // 返回 false(日期对象不是纯对象)
17
+ * @example
18
+ * isObject(Object.create(null)); // 返回 false(没有constructor属性)
19
+ * @note 此函数使用value.constructor === Object进行判断,因此不识别通过Object.create(null)创建的对象
20
+ * @note 与isObjectLike的区别:isObjectLike仅检查值是否为非null的对象,而isObject还要求是通过Object构造函数创建的
21
+ */
22
+ export declare const isObject: (value: unknown) => value is object;
@@ -0,0 +1 @@
1
+ export declare const isObjectLike: (value: unknown) => value is object;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 检查值是否为纯对象(通过Object构造函数创建的普通对象)
3
+ * 排除数组、日期、正则表达式、Map、Set等特殊对象
4
+ *
5
+ * @param object - 要检查的值
6
+ * @returns 如果值是纯对象则返回true,否则返回false
7
+ * @example
8
+ * isPlainObject({}); // 返回 true(空对象)
9
+ * @example
10
+ * isPlainObject({ name: 'John', age: 30 }); // 返回 true(带属性的普通对象)
11
+ * @example
12
+ * isPlainObject(new Object()); // 返回 true(通过Object构造函数创建的对象)
13
+ * @example
14
+ * isPlainObject([]); // 返回 false(数组不是纯对象)
15
+ * @example
16
+ * isPlainObject(new Date()); // 返回 false(日期对象不是纯对象)
17
+ * @example
18
+ * isPlainObject(null); // 返回 false(null不是对象)
19
+ * @example
20
+ * isPlainObject(Object.create(null)); // 返回 true(原型为null的对象视为纯对象)
21
+ * @example
22
+ * isPlainObject(new Map()); // 返回 false(Map对象不是纯对象)
23
+ * @note 函数通过检查toString标签和原型链来判断是否为纯对象
24
+ * @note 与isObject的区别:isObject包含所有对象类型,而isPlainObject仅包含普通对象
25
+ * @note 原型为null的对象(Object.create(null))也被视为纯对象
26
+ */
27
+ export declare function isPlainObject(object: unknown): object is object;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 检查值是否为JavaScript原始类型
3
+ * JavaScript原始类型包括null、undefined、字符串、数字、布尔值、符号和大整数
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是原始类型则返回true,否则返回false
7
+ * @example
8
+ * isPrimitive(null); // 返回 true
9
+ * @example
10
+ * isPrimitive(undefined); // 返回 true
11
+ * @example
12
+ * isPrimitive('hello'); // 返回 true(字符串是原始类型)
13
+ * @example
14
+ * isPrimitive(123); // 返回 true(数字是原始类型)
15
+ * @example
16
+ * isPrimitive(true); // 返回 true(布尔值是原始类型)
17
+ * @example
18
+ * isPrimitive(Symbol('foo')); // 返回 true(符号是原始类型)
19
+ * @example
20
+ * isPrimitive(BigInt(123)); // 返回 true(大整数是原始类型)
21
+ * @example
22
+ * isPrimitive({}); // 返回 false(对象不是原始类型)
23
+ * @example
24
+ * isPrimitive([]); // 返回 false(数组不是原始类型)
25
+ * @example
26
+ * isPrimitive(() => {}); // 返回 false(函数不是原始类型)
27
+ * @example
28
+ * isPrimitive(new Date()); // 返回 false(日期对象不是原始类型)
29
+ * @note 函数使用typeof运算符和null检查来判断是否为原始类型
30
+ * @note 原始类型是不可变的值,没有方法和属性(尽管JavaScript允许访问它们的包装对象方法)
31
+ * @note 函数实现使用`value == null`来同时检查null和undefined
32
+ */
33
+ export declare function isPrimitive(value: unknown): value is null | undefined | string | number | boolean | symbol | bigint;
@@ -0,0 +1 @@
1
+ export declare const isPromise: <T = any>(value: any) => value is Promise<T>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 检查值是否为正则表达式类型
3
+ * 使用instanceof运算符进行判断
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是正则表达式则返回true,否则返回false
7
+ * @example
8
+ * isRegExp(/abc/); // 返回 true
9
+ * @example
10
+ * isRegExp(new RegExp('abc')); // 返回 true
11
+ * @example
12
+ * isRegExp('/abc/'); // 返回 false(字符串不是正则表达式)
13
+ * @example
14
+ * isRegExp(null); // 返回 false(null不是正则表达式)
15
+ * @example
16
+ * isRegExp(undefined); // 返回 false(undefined不是正则表达式)
17
+ * @example
18
+ * isRegExp({}); // 返回 false(普通对象不是正则表达式)
19
+ * @note 函数使用instanceof运算符判断是否为RegExp实例
20
+ * @note 正则表达式字面量和通过RegExp构造函数创建的正则表达式都会返回true
21
+ * @note 字符串形式的正则表达式(如'/abc/')不会被识别为正则表达式
22
+ */
23
+ export declare function isRegExp(value: unknown): value is RegExp;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 检查值是否为字符串类型
3
+ * 使用typeof运算符进行判断,返回布尔值
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是字符串则返回true,否则返回false
7
+ * @example
8
+ * isString('hello'); // 返回 true
9
+ * @example
10
+ * isString(''); // 返回 true(空字符串也是字符串)
11
+ * @example
12
+ * isString(123); // 返回 false(数字不是字符串)
13
+ * @example
14
+ * isString(null); // 返回 false(null不是字符串)
15
+ * @example
16
+ * isString(undefined); // 返回 false(undefined不是字符串)
17
+ * @example
18
+ * isString(new String('hello')); // 返回 false(String对象不是字符串字面量)
19
+ * @note 使用typeof运算符判断,对于String对象返回'object'而非'string'
20
+ * @note 字符串字面量和空字符串都会返回true
21
+ */
22
+ export declare function isString(value: unknown): value is string;
@@ -0,0 +1 @@
1
+ export declare const isStringArray: (value: any[]) => value is string[];
@@ -0,0 +1 @@
1
+ export declare const isSymbol: (value: any) => value is symbol;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * 检查值是否为Uint8Array类型
3
+ * 使用instanceof运算符进行判断
4
+ *
5
+ * @param value - 要检查的值
6
+ * @returns 如果值是Uint8Array则返回true,否则返回false
7
+ * @example
8
+ * isUint8Array(new Uint8Array([1, 2, 3])); // 返回 true
9
+ * @example
10
+ * isUint8Array(new Uint8Array(0)); // 返回 true(空的Uint8Array)
11
+ * @example
12
+ * isUint8Array([]); // 返回 false(数组不是Uint8Array)
13
+ * @example
14
+ * isUint8Array(null); // 返回 false(null不是Uint8Array)
15
+ * @example
16
+ * isUint8Array(undefined); // 返回 false(undefined不是Uint8Array)
17
+ * @example
18
+ * isUint8Array(new ArrayBuffer(8)); // 返回 false(ArrayBuffer不是Uint8Array)
19
+ * @example
20
+ * isUint8Array(new Uint16Array()); // 返回 false(Uint16Array不是Uint8Array)
21
+ * @note 函数使用instanceof运算符判断是否为Uint8Array实例
22
+ * @note Uint8Array是8位无符号整数类型化数组,范围为0到255
23
+ * @note 与ArrayBuffer的区别:Uint8Array是对ArrayBuffer的视图,提供了对二进制数据的特定类型访问
24
+ */
25
+ export declare const isUint8Array: (value: unknown) => value is Uint8Array;