| 1 | type CloneWithCustomizer<T, R> = (value: T, key: number | string | undefined, object: any, stack: any) => R;
|
|---|
| 2 | /**
|
|---|
| 3 | * Creates a shallow clone of a value with customizer that returns a specific result type.
|
|---|
| 4 | *
|
|---|
| 5 | * @template T - The type of the value to clone.
|
|---|
| 6 | * @template R - The result type extending primitive types or objects.
|
|---|
| 7 | * @param {T} value - The value to clone.
|
|---|
| 8 | * @param {CloneWithCustomizer<T, R>} customizer - The function to customize cloning.
|
|---|
| 9 | * @returns {R} Returns the cloned value.
|
|---|
| 10 | *
|
|---|
| 11 | * @example
|
|---|
| 12 | * const obj = { a: 1, b: 2 };
|
|---|
| 13 | * const cloned = cloneWith(obj, (value) => {
|
|---|
| 14 | * if (typeof value === 'object') {
|
|---|
| 15 | * return JSON.parse(JSON.stringify(value));
|
|---|
| 16 | * }
|
|---|
| 17 | * });
|
|---|
| 18 | * // => { a: 1, b: 2 }
|
|---|
| 19 | */
|
|---|
| 20 | declare function cloneWith<T, R extends object | string | number | boolean | null>(value: T, customizer: CloneWithCustomizer<T, R>): R;
|
|---|
| 21 | /**
|
|---|
| 22 | * Creates a shallow clone of a value with optional customizer.
|
|---|
| 23 | *
|
|---|
| 24 | * @template T - The type of the value to clone.
|
|---|
| 25 | * @template R - The result type.
|
|---|
| 26 | * @param {T} value - The value to clone.
|
|---|
| 27 | * @param {CloneWithCustomizer<T, R | undefined>} customizer - The function to customize cloning.
|
|---|
| 28 | * @returns {R | T} Returns the cloned value or the customized result.
|
|---|
| 29 | *
|
|---|
| 30 | * @example
|
|---|
| 31 | * const obj = { a: 1, b: 2 };
|
|---|
| 32 | * const cloned = cloneWith(obj, (value) => {
|
|---|
| 33 | * if (typeof value === 'number') {
|
|---|
| 34 | * return value * 2;
|
|---|
| 35 | * }
|
|---|
| 36 | * });
|
|---|
| 37 | * // => { a: 2, b: 4 }
|
|---|
| 38 | */
|
|---|
| 39 | declare function cloneWith<T, R>(value: T, customizer: CloneWithCustomizer<T, R | undefined>): R | T;
|
|---|
| 40 | /**
|
|---|
| 41 | * Creates a shallow clone of a value.
|
|---|
| 42 | *
|
|---|
| 43 | * @template T - The type of the value to clone.
|
|---|
| 44 | * @param {T} value - The value to clone.
|
|---|
| 45 | * @returns {T} Returns the cloned value.
|
|---|
| 46 | *
|
|---|
| 47 | * @example
|
|---|
| 48 | * const obj = { a: 1, b: 2 };
|
|---|
| 49 | * const cloned = cloneWith(obj);
|
|---|
| 50 | * // => { a: 1, b: 2 }
|
|---|
| 51 | */
|
|---|
| 52 | declare function cloneWith<T>(value: T): T;
|
|---|
| 53 |
|
|---|
| 54 | export { cloneWith };
|
|---|