@gx-design-vue/pro-utils 0.2.0-beta.8 → 0.2.0-beta.81

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.
@@ -0,0 +1,20 @@
1
+ export default class Base64 {
2
+ _keyStr: string;
3
+ constructor();
4
+ _utf8_encode(string: string): string;
5
+ _utf8_decode(utftext: string): string;
6
+ /**
7
+ * @Author gx12358
8
+ * @DateTime 2024/12/21
9
+ * @lastTime 2024/12/21
10
+ * @description 加密方法
11
+ */
12
+ encode(input: string): string;
13
+ /**
14
+ * @Author gx12358
15
+ * @DateTime 2024/12/21
16
+ * @lastTime 2024/12/21
17
+ * @description 解密
18
+ */
19
+ decode(input: string): string;
20
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Deeply clones the given object.
3
+ *
4
+ * You can customize the deep cloning process using the `cloneValue` function.
5
+ * The function takes the current value `value`, the property name `key`, and the entire object `obj` as arguments.
6
+ * If the function returns a value, that value is used;
7
+ * if it returns `undefined`, the default cloning method is used.
8
+ *
9
+ * @template T - The type of the object.
10
+ * @param {T} obj - The object to clone.
11
+ * @param {Function} [cloneValue] - A function to customize the cloning process.
12
+ * @returns {T} - A deep clone of the given object.
13
+ *
14
+ * @example
15
+ * // Clone a primitive value
16
+ * const num = 29;
17
+ * const clonedNum = cloneDeepWith(num);
18
+ * console.log(clonedNum); // 29
19
+ * console.log(clonedNum === num); // true
20
+ *
21
+ * @example
22
+ * // Clone an object with a customizer
23
+ * const obj = { a: 1, b: 2 };
24
+ * const clonedObj = cloneDeepWith(obj, (value) => {
25
+ * if (typeof value === 'number') {
26
+ * return value * 2; // Double the number
27
+ * }
28
+ * });
29
+ * console.log(clonedObj); // { a: 2, b: 4 }
30
+ * console.log(clonedObj === obj); // false
31
+ *
32
+ * @example
33
+ * // Clone an array with a customizer
34
+ * const arr = [1, 2, 3];
35
+ * const clonedArr = cloneDeepWith(arr, (value) => {
36
+ * return value + 1; // Increment each value
37
+ * });
38
+ * console.log(clonedArr); // [2, 3, 4]
39
+ * console.log(clonedArr === arr); // false
40
+ */
41
+ export declare function cloneDeepWith<T>(obj: T, cloneValue: (value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any): T;
42
+ export declare function cloneDeepWithImpl<T>(valueToClone: any, keyToClone: PropertyKey | undefined, objectToClone: T, stack?: Map<any, any>, cloneValue?: ((value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any) | undefined): T;
43
+ export declare function copyProperties<T>(target: any, source: any, objectToClone?: T, stack?: Map<any, any> | undefined, cloneValue?: ((value: any, key: PropertyKey | undefined, obj: T, stack: Map<any, any>) => any) | undefined): void;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Creates a deep clone of the given object.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to clone.
6
+ * @returns {T} - A deep clone of the given object.
7
+ *
8
+ * @example
9
+ * // Clone a primitive values
10
+ * const num = 29;
11
+ * const clonedNum = clone(num);
12
+ * console.log(clonedNum); // 29
13
+ * console.log(clonedNum === num); // true
14
+ *
15
+ * @example
16
+ * // Clone an array
17
+ * const arr = [1, 2, 3];
18
+ * const clonedArr = clone(arr);
19
+ * console.log(clonedArr); // [1, 2, 3]
20
+ * console.log(clonedArr === arr); // false
21
+ *
22
+ * @example
23
+ * // Clone an array with nested objects
24
+ * const arr = [1, { a: 1 }, [1, 2, 3]];
25
+ * const clonedArr = clone(arr);
26
+ * arr[1].a = 2;
27
+ * console.log(arr); // [2, { a: 2 }, [1, 2, 3]]
28
+ * console.log(clonedArr); // [1, { a: 1 }, [1, 2, 3]]
29
+ * console.log(clonedArr === arr); // false
30
+ *
31
+ * @example
32
+ * // Clone an object
33
+ * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };
34
+ * const clonedObj = clone(obj);
35
+ * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }
36
+ * console.log(clonedObj === obj); // false
37
+ *
38
+ * @example
39
+ * // Clone an object with nested objects
40
+ * const obj = { a: 1, b: { c: 1 } };
41
+ * const clonedObj = clone(obj);
42
+ * obj.b.c = 2;
43
+ * console.log(obj); // { a: 1, b: { c: 2 } }
44
+ * console.log(clonedObj); // { a: 1, b: { c: 1 } }
45
+ * console.log(clonedObj === obj); // false
46
+ */
47
+ export declare function cloneDeep<T>(obj: T): T;
@@ -0,0 +1,3 @@
1
+ type DeepValueOf<T, K> = K extends `${infer First}:${infer Rest}` ? First extends keyof T ? Rest extends '' ? T[First] : DeepValueOf<T[First], Rest> : undefined : K extends keyof T ? T[K] : undefined;
2
+ export declare function getValueFromObjectByKey<T extends object, K extends string | string[] = string>(object: T, key: K): DeepValueOf<T, K extends string ? K : string> | undefined;
3
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,17 +1,26 @@
1
- import isServer from './isServer';
2
- import { isScroll, getScrollContainer, isInContainer } from './scroll';
1
+ import Base64 from './base64';
3
2
  import classNames from './classNames';
4
- import scrollTo from './scroll/scrollTo';
3
+ import { getValueFromObjectByKey } from './getValueFromObjectByKey';
4
+ import isServer from './isServer';
5
+ import { getScrollContainer, isInContainer, isScroll } from './scroll';
5
6
  import getScroll from './scroll/getScroll';
7
+ import scrollTo from './scroll/scrollTo';
6
8
  import throttleByAnimationFrame from './scroll/throttleByAnimationFrame';
7
- import globalConfig from './utils/config';
8
- export * from './merge';
9
- export * from './isDeepEqualReact';
9
+ export * from './cloneDeep';
10
+ export * from './cloneDeep/cloneDeepWith';
10
11
  export * from './isBrowser';
12
+ export * from './isDeepEqualReact';
13
+ export * from './isImg';
14
+ export * from './isNil';
15
+ export * from './isUrl';
16
+ export * from './merge';
17
+ export * from './merge/mergeWith';
18
+ export * from './merge/useDeepMege';
19
+ export * from './nanoid';
11
20
  export * from './omitBoolean';
12
21
  export * from './omitUndefined';
22
+ export * from './omitUndefinedAndEmptyArr';
13
23
  export * from './slots';
14
- export * from './utils';
15
- export * from './utils/validate';
16
24
  export * from './typings';
17
- export { isServer, globalConfig, classNames, isScroll, isInContainer, getScrollContainer, scrollTo, getScroll, throttleByAnimationFrame };
25
+ export * from './utils';
26
+ export { Base64, classNames, getScroll, getScrollContainer, getValueFromObjectByKey, isInContainer, isScroll, isServer, scrollTo, throttleByAnimationFrame };
@@ -0,0 +1,2 @@
1
+ /** 判断是否是图片链接 */
2
+ export declare function isImg(path: string): boolean;
@@ -0,0 +1 @@
1
+ export declare const isNil: (value: any) => value is null | undefined;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 判断是不是一个 url
3
+ * @param {string|undefined} path
4
+ * @returns boolean
5
+ */
6
+ export declare const isUrl: (path: string | undefined) => boolean;
@@ -3,5 +3,48 @@
3
3
  * @param {any[]} ...rest
4
4
  * @returns T
5
5
  */
6
- declare const merge: <T>(...rest: any[]) => T;
7
- export { merge };
6
+ declare const merge: <T = any>(...rest: any[]) => T;
7
+ /**
8
+ * Merges the properties of the source object into a deep clone of the target object.
9
+ * Unlike `merge`, This function does not modify the original target object.
10
+ *
11
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
12
+ *
13
+ * - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged.
14
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
15
+ *
16
+ * Note that this function does not mutate the target object.
17
+ *
18
+ * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
19
+ * @param {S} source - The source object whose properties will be merged into the cloned target object.
20
+ * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
21
+ *
22
+ * @template T - Type of the target object.
23
+ * @template S - Type of the source object.
24
+ *
25
+ * @example
26
+ * const target = { a: 1, b: { x: 1, y: 2 } };
27
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
28
+ *
29
+ * const result = toMerged(target, source);
30
+ * console.log(result);
31
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
32
+ *
33
+ * @example
34
+ * const target = { a: [1, 2], b: { x: 1 } };
35
+ * const source = { a: [3], b: { y: 2 } };
36
+ *
37
+ * const result = toMerged(target, source);
38
+ * console.log(result);
39
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
40
+ *
41
+ * @example
42
+ * const target = { a: null };
43
+ * const source = { a: [1, 2, 3] };
44
+ *
45
+ * const result = toMerged(target, source);
46
+ * console.log(result);
47
+ * // Output: { a: [1, 2, 3] }
48
+ */
49
+ declare function deepMerge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
50
+ export { deepMerge, merge };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Merges the properties of the source object into the target object.
3
+ *
4
+ * You can provide a custom `merge` function to control how properties are merged. It should return the value to be set in the target object.
5
+ *
6
+ * If it returns `undefined`, a default deep merge will be applied for arrays and objects:
7
+ *
8
+ * - If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged.
9
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
10
+ *
11
+ * Note that this function mutates the target object.
12
+ *
13
+ * @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
14
+ * @param {S} source - The source object whose properties will be merged into the target object.
15
+ * @param {(targetValue: any, sourceValue: any, key: string, target: T, source: S) => any} merge - A custom merge function that defines how properties should be combined. It receives the following arguments:
16
+ * - `targetValue`: The current value of the property in the target object.
17
+ * - `sourceValue`: The value of the property in the source object.
18
+ * - `key`: The key of the property being merged.
19
+ * - `target`: The target object.
20
+ * - `source`: The source object.
21
+ *
22
+ * @returns {T & S} The updated target object with properties from the source object merged in.
23
+ *
24
+ * @template T - Type of the target object.
25
+ * @template S - Type of the source object.
26
+ *
27
+ * @example
28
+ * const target = { a: 1, b: 2 };
29
+ * const source = { b: 3, c: 4 };
30
+ *
31
+ * mergeWith(target, source, (targetValue, sourceValue) => {
32
+ * if (typeof targetValue === 'number' && typeof sourceValue === 'number') {
33
+ * return targetValue + sourceValue;
34
+ * }
35
+ * });
36
+ * // Returns { a: 1, b: 5, c: 4 }
37
+ * @example
38
+ * const target = { a: [1], b: [2] };
39
+ * const source = { a: [3], b: [4] };
40
+ *
41
+ * const result = mergeWith(target, source, (objValue, srcValue) => {
42
+ * if (Array.isArray(objValue)) {
43
+ * return objValue.concat(srcValue);
44
+ * }
45
+ * });
46
+ *
47
+ * expect(result).toEqual({ a: [1, 3], b: [2, 4] });
48
+ */
49
+ export declare function mergeWith<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S, merge: (targetValue: any, sourceValue: any, key: string, target: T, source: S) => any): T & S;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Merges the properties of the source object into a deep clone of the target object.
3
+ * Unlike `merge`, This function does not modify the original target object.
4
+ *
5
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
6
+ *
7
+ * - If a property in the source object is an array or object and the corresponding property in the target object is also an array or object, they will be merged.
8
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
9
+ *
10
+ * Note that this function does not mutate the target object.
11
+ *
12
+ * @param {T} target - The target object to be cloned and merged into. This object is not modified directly.
13
+ * @param {S} source - The source object whose properties will be merged into the cloned target object.
14
+ * @returns {T & S} A new object with properties from the source object merged into a deep clone of the target object.
15
+ *
16
+ * @template T - Type of the target object.
17
+ * @template S - Type of the source object.
18
+ *
19
+ * @example
20
+ * const target = { a: 1, b: { x: 1, y: 2 } };
21
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
22
+ *
23
+ * const result = toMerged(target, source);
24
+ * console.log(result);
25
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
26
+ *
27
+ * @example
28
+ * const target = { a: [1, 2], b: { x: 1 } };
29
+ * const source = { a: [3], b: { y: 2 } };
30
+ *
31
+ * const result = toMerged(target, source);
32
+ * console.log(result);
33
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
34
+ *
35
+ * @example
36
+ * const target = { a: null };
37
+ * const source = { a: [1, 2, 3] };
38
+ *
39
+ * const result = toMerged(target, source);
40
+ * console.log(result);
41
+ * // Output: { a: [1, 2, 3] }
42
+ */
43
+ export declare function useDeepMerge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 生成uuid,如果不支持 randomUUID,就用 genNanoid
3
+ *
4
+ * @returns string
5
+ */
6
+ export declare const nanoid: () => string;
@@ -1,5 +1,2 @@
1
- type OmitUndefined<T> = {
2
- [P in keyof T]: NonNullable<T[P]>;
3
- };
4
- export declare const omitUndefined: <T>(obj: T) => OmitUndefined<T>;
5
- export {};
1
+ import type { OmitUndefined } from '../typings';
2
+ export declare const omitUndefined: <T extends Record<string, any>>(obj: T) => OmitUndefined<T>;
@@ -0,0 +1 @@
1
+ export declare const omitUndefinedAndEmptyArr: <T extends Record<string, any>>(obj: T) => T;