@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.
- package/@browser/IdleTimer.d.ts +18 -0
- package/@browser/broadcast-channel-pool.d.ts +17 -0
- package/@browser/index.d.ts +4 -0
- package/@browser/leader-election.d.ts +7 -0
- package/@browser/perform-chunk.d.ts +9 -0
- package/README.md +1 -0
- package/array/chunk.d.ts +24 -0
- package/array/difference.d.ts +30 -0
- package/array/flatten.d.ts +24 -0
- package/array/flattenDeep.d.ts +25 -0
- package/array/index.d.ts +8 -0
- package/array/intersection.d.ts +29 -0
- package/array/needArray.d.ts +37 -0
- package/array/sortBy.d.ts +36 -0
- package/async/index.d.ts +2 -0
- package/async/next-tick.d.ts +28 -0
- package/async/sleep.d.ts +5 -0
- package/binary/index.d.ts +1 -0
- package/binary/uint8ArrayToString.d.ts +12 -0
- package/collection/index.d.ts +1 -0
- package/collection/traverseObjectKeys.d.ts +3 -0
- package/crypto/aesDecrypt.d.ts +8 -0
- package/crypto/aesEncrypt.d.ts +10 -0
- package/crypto/base64Decode.d.ts +6 -0
- package/crypto/base64Encode.d.ts +6 -0
- package/crypto/decodeJWTPayload.d.ts +6 -0
- package/crypto/index.d.ts +8 -0
- package/crypto/rsaDecrypt.d.ts +7 -0
- package/crypto/rsaEncrypt.d.ts +8 -0
- package/crypto/rsaGenerateKey.d.ts +5 -0
- package/date/canBeDate.d.ts +5 -0
- package/date/dateStringToDate.d.ts +7 -0
- package/date/dateStringWithTimezone.d.ts +11 -0
- package/date/formatCountdown.d.ts +12 -0
- package/date/formatPassTime.d.ts +10 -0
- package/date/index.d.ts +12 -0
- package/date/isISODateString.d.ts +6 -0
- package/date/isMSTime.d.ts +7 -0
- package/date/msTimeToMilliseconds.d.ts +12 -0
- package/date/parseTime.d.ts +9 -0
- package/date/stringTime.d.ts +3 -0
- package/date/unixTimestamp.d.ts +5 -0
- package/function/debounce.d.ts +2 -0
- package/function/emptyFunction.d.ts +4 -0
- package/function/index.d.ts +4 -0
- package/function/once.d.ts +27 -0
- package/function/throttle.d.ts +30 -0
- package/index.d.ts +18 -0
- package/index.js +955 -0
- package/indexing/fractional-indexing.d.ts +26 -0
- package/number/canBeNumber.d.ts +27 -0
- package/number/index.d.ts +6 -0
- package/number/numberStep.d.ts +19 -0
- package/number/numberStepScreenSize.d.ts +1 -0
- package/number/numberStrip.d.ts +21 -0
- package/number/toInt.d.ts +1 -0
- package/number/tryToNumber.d.ts +1 -0
- package/object/deepFreeze.d.ts +5 -0
- package/object/flattenPathObjectToPlainObject.d.ts +7 -0
- package/object/get.d.ts +23 -0
- package/object/getTag.d.ts +1 -0
- package/object/has.d.ts +20 -0
- package/object/index.d.ts +15 -0
- package/object/isEqual.d.ts +25 -0
- package/object/isEqualUint8Array.d.ts +1 -0
- package/object/omit.d.ts +24 -0
- package/object/omitBy.d.ts +7 -0
- package/object/pick.d.ts +24 -0
- package/object/pickBy.d.ts +1 -0
- package/object/plainObjectToFlattenPathObject.d.ts +8 -0
- package/object/set.d.ts +27 -0
- package/object/setWith.d.ts +12 -0
- package/object/toPlainObject.d.ts +1 -0
- package/object/zipObject.d.ts +9 -0
- package/package.json +20 -0
- package/platform/index.d.ts +1 -0
- package/platform/is-browser.d.ts +4 -0
- package/random/index.d.ts +6 -0
- package/random/randomArrayItem.d.ts +1 -0
- package/random/randomFloat.d.ts +1 -0
- package/random/randomInt.d.ts +7 -0
- package/random/randomString.d.ts +9 -0
- package/random/randomUintByLength.d.ts +1 -0
- package/random/randomUintString.d.ts +1 -0
- package/string/camelCase.d.ts +22 -0
- package/string/capitalize.d.ts +7 -0
- package/string/compressToBase64Url.d.ts +4 -0
- package/string/decompressFromBase64Url.d.ts +4 -0
- package/string/getWords.d.ts +1 -0
- package/string/index.d.ts +17 -0
- package/string/kebabCase.d.ts +9 -0
- package/string/parseChineseNumber.d.ts +1 -0
- package/string/queryParse.d.ts +1 -0
- package/string/queryStringify.d.ts +5 -0
- package/string/rmb.d.ts +6 -0
- package/string/similarity.d.ts +1 -0
- package/string/snakeCase.d.ts +10 -0
- package/string/startCase.d.ts +7 -0
- package/string/stringSingleline.d.ts +4 -0
- package/string/stringTemplate.d.ts +7 -0
- package/string/stringToArrayBuffer.d.ts +7 -0
- package/string/uncapitalize.d.ts +7 -0
- package/string/urlJoin.d.ts +1 -0
- package/tools/event.d.ts +18 -0
- package/tools/image.d.ts +2 -0
- package/tools/index.d.ts +3 -0
- package/tools/log.d.ts +4 -0
- package/type-definition/index.d.ts +1 -0
- package/type-definition/result-types.d.ts +11 -0
- package/types/AnyFunction.d.ts +20 -0
- package/types/DeepPartial.d.ts +48 -0
- package/types/index.d.ts +24 -0
- package/types/isArray.d.ts +19 -0
- package/types/isArrayBuffer.d.ts +23 -0
- package/types/isBoolean.d.ts +27 -0
- package/types/isDate.d.ts +25 -0
- package/types/isEmpty.d.ts +40 -0
- package/types/isFloat.d.ts +1 -0
- package/types/isFunction.d.ts +2 -0
- package/types/isInt.d.ts +1 -0
- package/types/isIntArray.d.ts +1 -0
- package/types/isNil.d.ts +20 -0
- package/types/isNumber.d.ts +29 -0
- package/types/isNumberArray.d.ts +1 -0
- package/types/isObject.d.ts +22 -0
- package/types/isObjectLike.d.ts +1 -0
- package/types/isPlainObject.d.ts +27 -0
- package/types/isPrimitive.d.ts +33 -0
- package/types/isPromise.d.ts +1 -0
- package/types/isRegExp.d.ts +23 -0
- package/types/isString.d.ts +22 -0
- package/types/isStringArray.d.ts +1 -0
- package/types/isSymbol.d.ts +1 -0
- package/types/isUint8Array.d.ts +25 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 因为原来库编译有问题,拷贝原来来用 https://github.com/rocicorp/fractional-indexing
|
|
3
|
+
*/
|
|
4
|
+
export declare const BASE_62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
5
|
+
/**
|
|
6
|
+
* @param a
|
|
7
|
+
* @param b
|
|
8
|
+
* @param digits
|
|
9
|
+
* @return {string}
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateKeyBetween(a: string | null | undefined, b: string | null | undefined, digits?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* same preconditions as generateKeysBetween.
|
|
14
|
+
* n >= 0.
|
|
15
|
+
* Returns an array of n distinct keys in sorted order.
|
|
16
|
+
* If a and b are both null, returns [a0, a1, ...]
|
|
17
|
+
* If one or the other is null, returns consecutive "integer"
|
|
18
|
+
* keys. Otherwise, returns relatively short keys between
|
|
19
|
+
* a and b.
|
|
20
|
+
* @param a
|
|
21
|
+
* @param b
|
|
22
|
+
* @param n
|
|
23
|
+
* @param digits
|
|
24
|
+
* @return {string[]}
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateKeysBetween(a: string | null | undefined, b: string | null | undefined, n: number, digits?: string): string[];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查值是否可以安全地转换为数字
|
|
3
|
+
* 使用parseFloat()进行转换尝试,对于可以解析为有效数字的值返回true
|
|
4
|
+
* 特别注意:空字符串('')、true、false等特殊值的处理
|
|
5
|
+
*
|
|
6
|
+
* @param value - 要检查的值,可以是任何类型
|
|
7
|
+
* @returns 如果值可以转换为数字则返回true,否则返回false
|
|
8
|
+
* @example
|
|
9
|
+
* canBeNumber('123'); // 返回 true
|
|
10
|
+
* @example
|
|
11
|
+
* canBeNumber('123.45'); // 返回 true
|
|
12
|
+
* @example
|
|
13
|
+
* canBeNumber(' 123 '); // 返回 true(忽略首尾空格)
|
|
14
|
+
* @example
|
|
15
|
+
* canBeNumber('abc'); // 返回 false
|
|
16
|
+
* @example
|
|
17
|
+
* canBeNumber('12a3'); // 返回 false
|
|
18
|
+
* @example
|
|
19
|
+
* canBeNumber(null); // 返回 false
|
|
20
|
+
* @example
|
|
21
|
+
* canBeNumber(undefined); // 返回 false
|
|
22
|
+
* @example
|
|
23
|
+
* canBeNumber(''); // 返回 false(空字符串不能转换为数字)
|
|
24
|
+
* @note 与isNumber()不同,该函数检查的是值是否可以被转换为数字,而非值本身是否是数字类型
|
|
25
|
+
* @note 对于BigInt类型值(如123n),会返回false,因为parseFloat无法处理BigInt
|
|
26
|
+
*/
|
|
27
|
+
export declare const canBeNumber: (value: any) => boolean;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { canBeNumber } from './canBeNumber';
|
|
2
|
+
export { numberStep } from './numberStep';
|
|
3
|
+
export { numberStepScreenSize } from './numberStepScreenSize';
|
|
4
|
+
export { numberStrip } from './numberStrip';
|
|
5
|
+
export { toInt } from './toInt';
|
|
6
|
+
export { tryToNumber } from './tryToNumber';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将数值向上取整到最接近的步长倍数
|
|
3
|
+
* 常用于表单控件、网格布局等需要按固定间隔取值的场景
|
|
4
|
+
*
|
|
5
|
+
* @param value - 需要取整的数值
|
|
6
|
+
* @param step - 步长间隔,必须为正数
|
|
7
|
+
* @returns 向上取整后的数值,是step的整数倍
|
|
8
|
+
* @example
|
|
9
|
+
* numberStep(7, 5); // 返回 10(5的2倍)
|
|
10
|
+
* @example
|
|
11
|
+
* numberStep(5, 5); // 返回 5(5的1倍)
|
|
12
|
+
* @example
|
|
13
|
+
* numberStep(3.2, 2); // 返回 4(2的2倍)
|
|
14
|
+
* @example
|
|
15
|
+
* numberStep(0.5, 1); // 返回 1(1的1倍)
|
|
16
|
+
* @note 实现原理:value除以step后向上取整,再乘以step
|
|
17
|
+
* @warning step必须为正数,否则可能导致非预期结果或除以零错误
|
|
18
|
+
*/
|
|
19
|
+
export declare const numberStep: (value: number, step: number) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const numberStepScreenSize: (value: number, step?: number, devicePixelRatio?: number) => number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 去除数字的无用小数位,解决浮点数精度问题
|
|
3
|
+
* 通过限制有效数字位数来消除JavaScript浮点数运算产生的微小误差
|
|
4
|
+
* 例如:0.1 + 0.2 通常得到 0.30000000000000004,使用本函数可得到 0.3
|
|
5
|
+
*
|
|
6
|
+
* @param value - 需要处理的数字
|
|
7
|
+
* @param [precision=12] - 有效数字位数,默认为12位(范围1-21)
|
|
8
|
+
* @returns 处理后的数字,去除了无用的小数位
|
|
9
|
+
* @example
|
|
10
|
+
* numberStrip(0.1 + 0.2); // 返回 0.3(解决浮点数精度问题)
|
|
11
|
+
* @example
|
|
12
|
+
* numberStrip(1.2345); // 返回 1.2345(默认12位有效数字)
|
|
13
|
+
* @example
|
|
14
|
+
* numberStrip(12345.6789, 6); // 返回 12345.7(6位有效数字)
|
|
15
|
+
* @example
|
|
16
|
+
* numberStrip(0.0000012345); // 返回 0.0000012345
|
|
17
|
+
* @note 有效数字位数(precision)控制整体数字精度,而非仅小数部分
|
|
18
|
+
* @note 默认精度12位适用于大多数场景,可根据需要调整,但不应超过21位
|
|
19
|
+
* @note 内部使用Number.toPrecision()实现,然后通过parseFloat()转换回数字
|
|
20
|
+
*/
|
|
21
|
+
export declare const numberStrip: (value: number, precision?: number) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toInt: (value: unknown) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const tryToNumber: (value: any) => number;
|
package/object/get.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 安全地从对象中获取嵌套属性,支持复杂路径解析
|
|
3
|
+
* 通过路径字符串访问对象的深层属性,当路径不存在时返回默认值
|
|
4
|
+
* 支持多种路径格式:点表示法、方括号表示法和逗号分隔的数组路径
|
|
5
|
+
*
|
|
6
|
+
* @template T - 返回值的类型
|
|
7
|
+
* @param obj - 要查询的对象,可以是任何类型
|
|
8
|
+
* @param path - 属性路径字符串,支持格式如 'a.b[0].c' 或 'a,b,c'
|
|
9
|
+
* @param [defaultValue] - 可选,当路径不存在时返回的默认值
|
|
10
|
+
* @returns 路径对应的属性值,或默认值,或undefined
|
|
11
|
+
* @example
|
|
12
|
+
* const obj = { a: { b: { c: 1 } } };
|
|
13
|
+
* get(obj, 'a.b.c'); // 返回 1
|
|
14
|
+
* @example
|
|
15
|
+
* get(obj, 'a.b.d', 'default'); // 返回 'default'(路径不存在)
|
|
16
|
+
* @example
|
|
17
|
+
* get([{ name: 'test' }], '[0].name'); // 返回 'test'(数组访问)
|
|
18
|
+
* @example
|
|
19
|
+
* get({ a: [{ b: 'value' }] }, 'a,0,b'); // 返回 'value'(逗号分隔路径)
|
|
20
|
+
* @note 路径解析支持多种分隔符:逗号(,)、方括号([])和点(.)
|
|
21
|
+
* @note 如果对象在路径的任何环节为null/undefined,将返回默认值
|
|
22
|
+
*/
|
|
23
|
+
export declare const get: <T = any>(obj: any, path: string, defaultValue?: any) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getTag: (value: unknown) => string;
|
package/object/has.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查对象是否包含指定的嵌套属性(仅检查自有属性)
|
|
3
|
+
* 支持通过点表示法访问嵌套属性,如'a.b.c'
|
|
4
|
+
* 如果对象为null/undefined或任何父属性不存在,返回false
|
|
5
|
+
*
|
|
6
|
+
* @param obj - 要检查的对象,可以是任何类型
|
|
7
|
+
* @param key - 属性路径字符串,支持嵌套路径如'a.b.c'
|
|
8
|
+
* @returns 如果对象包含指定的自有属性则返回true,否则返回false
|
|
9
|
+
* @example
|
|
10
|
+
* has({ a: { b: 1 } }, 'a.b'); // 返回 true
|
|
11
|
+
* @example
|
|
12
|
+
* has({ a: 1 }, 'a'); // 返回 true
|
|
13
|
+
* @example
|
|
14
|
+
* has({ a: {} }, 'a.b'); // 返回 false(属性不存在)
|
|
15
|
+
* @example
|
|
16
|
+
* has(null, 'a'); // 返回 false(对象为null)
|
|
17
|
+
* @note 使用Object.hasOwnProperty检查属性,不考虑继承属性
|
|
18
|
+
* @note 支持任意深度的嵌套属性检查
|
|
19
|
+
*/
|
|
20
|
+
export declare const has: (obj: any, key: string) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { deepFreeze } from './deepFreeze';
|
|
2
|
+
export * from './flattenPathObjectToPlainObject';
|
|
3
|
+
export * from './get';
|
|
4
|
+
export * from './has';
|
|
5
|
+
export * from './isEqual';
|
|
6
|
+
export * from './isEqualUint8Array';
|
|
7
|
+
export * from './omit';
|
|
8
|
+
export * from './omitBy';
|
|
9
|
+
export * from './pick';
|
|
10
|
+
export * from './pickBy';
|
|
11
|
+
export * from './plainObjectToFlattenPathObject';
|
|
12
|
+
export * from './set';
|
|
13
|
+
export * from './setWith';
|
|
14
|
+
export * from './toPlainObject';
|
|
15
|
+
export * from './zipObject';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 深度比较两个值是否相等,支持多种数据类型和复杂结构
|
|
3
|
+
* 递归比较对象的属性和数组的元素,处理特殊类型如RegExp、Uint8Array和NaN
|
|
4
|
+
* 与===不同,此函数认为NaN等于NaN,并且会比较对象的原型和自有属性
|
|
5
|
+
*
|
|
6
|
+
* @param a - 要比较的第一个值
|
|
7
|
+
* @param b - 要比较的第二个值
|
|
8
|
+
* @returns 如果两个值深度相等则返回true,否则返回false
|
|
9
|
+
* @example
|
|
10
|
+
* isEqual(1, 1); // 返回 true
|
|
11
|
+
* @example
|
|
12
|
+
* isEqual({ a: 1 }, { a: 1 }); // 返回 true(对象深度比较)
|
|
13
|
+
* @example
|
|
14
|
+
* isEqual([1, 2, 3], [1, 2, 3]); // 返回 true(数组比较)
|
|
15
|
+
* @example
|
|
16
|
+
* isEqual(NaN, NaN); // 返回 true(特殊处理NaN)
|
|
17
|
+
* @example
|
|
18
|
+
* isEqual(/abc/i, /abc/i); // 返回 true(正则表达式比较)
|
|
19
|
+
* @example
|
|
20
|
+
* isEqual(new Uint8Array([1,2]), new Uint8Array([1,2])); // 返回 true(Uint8Array比较)
|
|
21
|
+
* @note 比较对象时会检查构造函数和自有属性,不考虑原型链上的属性
|
|
22
|
+
* @note 循环引用对象可能导致无限递归
|
|
23
|
+
* @note 函数不支持比较函数、Promise等引用类型的内部状态
|
|
24
|
+
*/
|
|
25
|
+
export declare const isEqual: (a: any, b: any) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEqualUint8Array(u8_1: Uint8Array, u8_2: Uint8Array): boolean;
|
package/object/omit.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从对象中排除指定的属性,创建并返回一个新对象
|
|
3
|
+
* 包含源对象的所有自有属性,除了指定要排除的属性
|
|
4
|
+
* 当输入对象为null/undefined时返回空对象,当排除列表为空时返回原对象的浅拷贝
|
|
5
|
+
*
|
|
6
|
+
* @template T - 输入对象的类型
|
|
7
|
+
* @template Keys - 要排除的属性键集合类型
|
|
8
|
+
* @param obj - 源对象,如果为null/undefined则返回空对象
|
|
9
|
+
* @param keys - 要排除的属性键数组
|
|
10
|
+
* @returns 排除指定属性后的新对象
|
|
11
|
+
* @example
|
|
12
|
+
* omit({ a: 1, b: 2, c: 3 }, ['b']);
|
|
13
|
+
* // 返回 { a: 1, c: 3 }
|
|
14
|
+
* @example
|
|
15
|
+
* omit({ name: 'John', age: 30, email: 'john@example.com' }, ['age', 'email']);
|
|
16
|
+
* // 返回 { name: 'John' }
|
|
17
|
+
* @example
|
|
18
|
+
* omit({ a: 1 }, []); // 返回 { a: 1 }(排除空数组)
|
|
19
|
+
* @example
|
|
20
|
+
* omit(null, ['a']); // 返回 {}(输入为null)
|
|
21
|
+
* @note 函数会创建源对象的浅拷贝,原对象不会被修改
|
|
22
|
+
* @note 只排除自有属性,继承属性不受影响
|
|
23
|
+
*/
|
|
24
|
+
export declare const omit: <T extends Record<string, any>, Keys extends keyof T>(obj: T, keys: Keys[]) => Omit<T, Keys>;
|
package/object/pick.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 从对象中选取指定的属性,创建并返回一个新对象
|
|
3
|
+
* 只包含指定的自有属性,忽略继承属性和不存在的属性
|
|
4
|
+
* 当输入对象为null/undefined时,返回空对象
|
|
5
|
+
*
|
|
6
|
+
* @template T - 输入对象的类型
|
|
7
|
+
* @template Keys - 要选取的属性键集合类型
|
|
8
|
+
* @param obj - 源对象,如果为null/undefined则返回空对象
|
|
9
|
+
* @param keys - 要选取的属性键数组
|
|
10
|
+
* @returns 只包含选取属性的新对象
|
|
11
|
+
* @example
|
|
12
|
+
* pick({ a: 1, b: 2, c: 3 }, ['a', 'c']);
|
|
13
|
+
* // 返回 { a: 1, c: 3 }
|
|
14
|
+
* @example
|
|
15
|
+
* pick({ name: 'John', age: 30 }, ['name']);
|
|
16
|
+
* // 返回 { name: 'John' }
|
|
17
|
+
* @example
|
|
18
|
+
* pick(null, ['a', 'b']); // 返回 {}
|
|
19
|
+
* @example
|
|
20
|
+
* pick({ a: 1 }, ['b']); // 返回 {}(属性不存在)
|
|
21
|
+
* @note 只选取对象的自有属性,不包括继承的属性
|
|
22
|
+
* @note 对于不存在的属性,会被忽略而不会出现在结果中
|
|
23
|
+
*/
|
|
24
|
+
export declare function pick<T extends object, Keys extends keyof T>(obj: T, keys: Keys[]): Pick<T, Keys>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pickBy<T extends Record<string, any>>(object: T, fn: (value: any, key: string) => boolean): T;
|
package/object/set.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare function setBase(object: Record<string, any>, path: string, value: any, fun?: (currentValue: any, key: string, object: any) => any): Record<string, any>;
|
|
2
|
+
/**
|
|
3
|
+
* 设置对象中指定路径的属性值,自动创建不存在的嵌套路径
|
|
4
|
+
* 支持点表示法和方括号表示法的路径,根据下一个路径段类型自动创建数组或对象
|
|
5
|
+
* 例如:路径'a[0].b'会创建数组和对象结构
|
|
6
|
+
*
|
|
7
|
+
* @template T - 输入对象的类型
|
|
8
|
+
* @param object - 要修改的对象,会被原地修改
|
|
9
|
+
* @param path - 属性路径字符串,支持格式如 'a.b[0].c' 或 'a[1].b'
|
|
10
|
+
* @param value - 要设置的值
|
|
11
|
+
* @returns 修改后的对象(与输入对象是同一引用)
|
|
12
|
+
* @example
|
|
13
|
+
* const obj = {};
|
|
14
|
+
* set(obj, 'a.b.c', 1);
|
|
15
|
+
* // obj 变为 { a: { b: { c: 1 } } }
|
|
16
|
+
* @example
|
|
17
|
+
* const arr = [];
|
|
18
|
+
* set(arr, '[0].name', 'test');
|
|
19
|
+
* // arr 变为 [{ name: 'test' }]
|
|
20
|
+
* @example
|
|
21
|
+
* set({ a: 1 }, 'a.b', 2);
|
|
22
|
+
* // 返回 { a: { b: 2 } }(覆盖原属性值)
|
|
23
|
+
* @note 函数会原地修改输入对象,而非创建新对象
|
|
24
|
+
* @note 路径中的数字索引会创建数组,其他情况创建普通对象
|
|
25
|
+
* @note 空路径段(如'a..b')会被忽略
|
|
26
|
+
*/
|
|
27
|
+
export declare function set(object: Record<string, any>, path: string, value: any): Record<string, any>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 这个方法类似 set 除了它接受一个 customFun 决定如何设置对象路径的值。
|
|
3
|
+
* 如果 fun 返回 undefined 将会有它的处理方法代替。
|
|
4
|
+
* customFun 会传入3个参数:(nsValue, key, nsObject)
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @param object
|
|
8
|
+
* @param path
|
|
9
|
+
* @param value
|
|
10
|
+
* @param customFun
|
|
11
|
+
*/
|
|
12
|
+
export declare function setWith(object: Record<string, any>, path: string, value: any, customFun: (currentValue: any, key: string, object: string) => any): Record<string, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toPlainObject: (value: any) => Record<string, any>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建一个对象,将映射指定键值
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* const zipped = zipObject(['a', 'b'], [1, 2]) // { a: 1, b: 2 }
|
|
6
|
+
* const zipped = zipObject(['a', 'b'], (k, i) => k + i) // { a: 'a0', b: 'b1' }
|
|
7
|
+
* const zipped = zipObject(['a', 'b'], 1) // { a: 1, b: 1 }
|
|
8
|
+
*/
|
|
9
|
+
export declare function zipObject<K extends string | number | symbol, V>(keys: K[], values: V | ((key: K, idx: number) => V) | V[]): Record<K, V>;
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aiao/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"ms": "^2.1.3",
|
|
7
|
+
"type-fest": "^4.41.0",
|
|
8
|
+
"fastest-levenshtein": "^1.0.16",
|
|
9
|
+
"ts-xor": "^1.3.0",
|
|
10
|
+
"rxjs": "~7.8.2"
|
|
11
|
+
},
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./index.js",
|
|
15
|
+
"types": "./index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { IS_BROWSER } from './is-browser';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { randomArrayItem } from './randomArrayItem';
|
|
2
|
+
export { randomFloat } from './randomFloat';
|
|
3
|
+
export { randomInt } from './randomInt';
|
|
4
|
+
export { randomString } from './randomString';
|
|
5
|
+
export { randomUintByLength } from './randomUintByLength';
|
|
6
|
+
export { randomUintString } from './randomUintString';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomArrayItem: (array: any[]) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomFloat: (min?: number, max?: number) => number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const ZERO = "0";
|
|
2
|
+
export declare const NUMBER_WITHOUT_ZERO = "123456789";
|
|
3
|
+
export declare const NUMBERS: string;
|
|
4
|
+
export declare const LOWER_LETTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
5
|
+
export declare const UPPER_LETTERS: string;
|
|
6
|
+
export declare const LETTERS: string;
|
|
7
|
+
export declare const SAFE_URL = "_-";
|
|
8
|
+
export declare const URL_ALL: string;
|
|
9
|
+
export declare const randomString: (size?: number, alphabet?: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomUintByLength: (length?: number) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomUintString: (length?: number) => string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将字符串转换为驼峰命名格式
|
|
3
|
+
* 驼峰命名规则:首字母小写,后续每个单词首字母大写,单词间无分隔符
|
|
4
|
+
* 支持处理包含连字符(-)、下划线(_)、空格或大小写混合的字符串
|
|
5
|
+
*
|
|
6
|
+
* @param str - 输入字符串,可以包含各种分隔符或混合大小写
|
|
7
|
+
* @returns 转换后的驼峰式字符串
|
|
8
|
+
* @example
|
|
9
|
+
* camelCase('hello-world'); // 返回 'helloWorld'
|
|
10
|
+
* @example
|
|
11
|
+
* camelCase('Hello_World'); // 返回 'helloWorld'
|
|
12
|
+
* @example
|
|
13
|
+
* camelCase('hello world'); // 返回 'helloWorld'
|
|
14
|
+
* @example
|
|
15
|
+
* camelCase('HelloWorld'); // 返回 'helloWorld'
|
|
16
|
+
* @example
|
|
17
|
+
* camelCase(' hello--world '); // 返回 'helloWorld'(自动去除首尾空格)
|
|
18
|
+
* @example
|
|
19
|
+
* camelCase(''); // 返回 ''(空字符串输入返回空字符串)
|
|
20
|
+
* @note 内部使用getWords()函数拆分单词,使用capitalize()函数处理单词首字母
|
|
21
|
+
*/
|
|
22
|
+
export declare function camelCase(str: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getWords: (str: string) => string[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { camelCase } from './camelCase';
|
|
2
|
+
export * from './capitalize';
|
|
3
|
+
export { compressToBase64Url } from './compressToBase64Url';
|
|
4
|
+
export { decompressFromBase64Url } from './decompressFromBase64Url';
|
|
5
|
+
export { kebabCase } from './kebabCase';
|
|
6
|
+
export { parseChineseNumber } from './parseChineseNumber';
|
|
7
|
+
export { queryParse } from './queryParse';
|
|
8
|
+
export { queryStringify } from './queryStringify';
|
|
9
|
+
export { rmbUppercase } from './rmb';
|
|
10
|
+
export { similarity } from './similarity';
|
|
11
|
+
export { snakeCase } from './snakeCase';
|
|
12
|
+
export { startCase } from './startCase';
|
|
13
|
+
export { stringSingleline } from './stringSingleline';
|
|
14
|
+
export { stringTemplate } from './stringTemplate';
|
|
15
|
+
export { stringToArrayBuffer } from './stringToArrayBuffer';
|
|
16
|
+
export * from './uncapitalize';
|
|
17
|
+
export { urlJoin } from './urlJoin';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseChineseNumber(s: string): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const queryParse: (query: string) => any;
|
package/string/rmb.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function similarity(a: string, b: string): number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const urlJoin: (...paths: Array<string | number>) => string;
|
package/tools/event.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Event {
|
|
2
|
+
type: string;
|
|
3
|
+
}
|
|
4
|
+
export interface CustomEvents {
|
|
5
|
+
[eventName: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export type EventListener<T> = (event: T) => void;
|
|
8
|
+
/**
|
|
9
|
+
* 自定义事件调度器
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class EventDispatcher<Events extends CustomEvents = CustomEvents> {
|
|
12
|
+
#private;
|
|
13
|
+
addEventListener<T extends keyof Events>(type: T, listener: EventListener<Events[T]>): void;
|
|
14
|
+
hasEventListener<T extends keyof Events>(type: T, listener: EventListener<Events[T]>): boolean;
|
|
15
|
+
removeEventListener<T extends keyof Events>(type: T, listener: EventListener<Events[T]>): void;
|
|
16
|
+
dispatchEvent(event: Events[keyof Events]): void;
|
|
17
|
+
removeAllEventListener(): void;
|
|
18
|
+
}
|
package/tools/image.d.ts
ADDED
package/tools/index.d.ts
ADDED
package/tools/log.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './result-types';
|