@aiszlab/relax 2.0.3 → 2.0.4

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 (45) hide show
  1. package/dist/decimal/index.d.ts +4 -0
  2. package/dist/hooks/use-click-away.d.ts +2 -2
  3. package/dist/hooks/use-media-query.cjs +2 -2
  4. package/dist/hooks/use-media-query.mjs +2 -2
  5. package/dist/index.cjs +4 -2
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.mjs +2 -1
  8. package/dist/is/is-deep-key.d.ts +18 -0
  9. package/dist/is/is-key.d.ts +14 -0
  10. package/dist/is/is-object.cjs +26 -5
  11. package/dist/is/is-object.d.ts +22 -4
  12. package/dist/is/is-object.mjs +26 -5
  13. package/dist/is/is-symbol.d.ts +15 -0
  14. package/dist/types/first.d.ts +1 -1
  15. package/dist/types/get.d.ts +8 -0
  16. package/dist/types/last.d.ts +1 -1
  17. package/dist/utils/at.cjs +6 -6
  18. package/dist/utils/at.d.ts +2 -2
  19. package/dist/utils/at.mjs +6 -6
  20. package/dist/utils/first.cjs +7 -11
  21. package/dist/utils/first.d.ts +5 -2
  22. package/dist/utils/first.mjs +7 -11
  23. package/dist/utils/get.d.ts +244 -0
  24. package/dist/utils/is-index.d.ts +1 -0
  25. package/dist/utils/last.cjs +7 -11
  26. package/dist/utils/last.d.ts +5 -2
  27. package/dist/utils/last.mjs +7 -11
  28. package/dist/utils/merge.d.ts +1 -1
  29. package/dist/utils/replace/index.d.ts +3 -0
  30. package/dist/utils/replace/replace-at.cjs +12 -0
  31. package/dist/utils/replace/replace-at.d.ts +5 -0
  32. package/dist/utils/replace/replace-at.mjs +10 -0
  33. package/dist/utils/replace/replace.cjs +19 -0
  34. package/dist/utils/{replace.d.ts → replace/replace.d.ts} +2 -2
  35. package/dist/utils/replace/replace.mjs +17 -0
  36. package/dist/utils/set.d.ts +28 -0
  37. package/dist/utils/to-array.cjs +12 -11
  38. package/dist/utils/to-array.d.ts +2 -3
  39. package/dist/utils/to-array.mjs +12 -11
  40. package/dist/utils/to-key.d.ts +8 -0
  41. package/dist/utils/to-paths.d.ts +18 -0
  42. package/dist/utils/update.d.ts +11 -0
  43. package/package.json +17 -17
  44. package/dist/utils/replace.cjs +0 -23
  45. package/dist/utils/replace.mjs +0 -21
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @description divide
3
+ */
4
+ export declare function divide(a: number, b: number): number;
@@ -1,8 +1,8 @@
1
- import { type MutableRefObject } from "react";
1
+ import { type RefObject } from "react";
2
2
  import { type Containable } from "../dom";
3
3
  import type { Nullable, Arrayable } from "@aiszlab/relax/types";
4
4
  /**
5
5
  * @description
6
6
  * click away
7
7
  */
8
- export declare const useClickAway: (onClickAway: (event: MouseEvent) => void, target: Arrayable<MutableRefObject<Nullable<Containable>> | false>) => void;
8
+ export declare const useClickAway: (onClickAway: (event: MouseEvent) => void, target: Arrayable<RefObject<Nullable<Containable>> | false>) => void;
@@ -3,7 +3,7 @@
3
3
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
4
  var react = require('react');
5
5
  var toArray = require('../utils/to-array.cjs');
6
- var replace = require('../utils/replace.cjs');
6
+ var replaceAt = require('../utils/replace/replace-at.cjs');
7
7
 
8
8
  var useMediaQuery = function useMediaQuery(query) {
9
9
  var _query = react.useMemo(function () {
@@ -21,7 +21,7 @@ var useMediaQuery = function useMediaQuery(query) {
21
21
  setValue = _useState2[1];
22
22
  var onMediaQueryChange = react.useCallback(function (event, index) {
23
23
  setValue(function (prev) {
24
- return replace.replace(prev, event.matches, index);
24
+ return replaceAt.replaceAt(prev, index, event.matches);
25
25
  });
26
26
  }, []);
27
27
  react.useEffect(function () {
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
2
  import { useMemo, useState, useCallback, useEffect } from 'react';
3
3
  import { toArray } from '../utils/to-array.mjs';
4
- import { replace } from '../utils/replace.mjs';
4
+ import { replaceAt } from '../utils/replace/replace-at.mjs';
5
5
 
6
6
  var useMediaQuery = function useMediaQuery(query) {
7
7
  var _query = useMemo(function () {
@@ -19,7 +19,7 @@ var useMediaQuery = function useMediaQuery(query) {
19
19
  setValue = _useState2[1];
20
20
  var onMediaQueryChange = useCallback(function (event, index) {
21
21
  setValue(function (prev) {
22
- return replace(prev, event.matches, index);
22
+ return replaceAt(prev, index, event.matches);
23
23
  });
24
24
  }, []);
25
25
  useEffect(function () {
package/dist/index.cjs CHANGED
@@ -71,7 +71,6 @@ var throttle = require('./utils/throttle.cjs');
71
71
  var clone = require('./utils/clone.cjs');
72
72
  var toggle = require('./utils/toggle.cjs');
73
73
  var taggedTemplateLiterals = require('./utils/tagged-template-literals.cjs');
74
- var replace = require('./utils/replace.cjs');
75
74
  var first = require('./utils/first.cjs');
76
75
  var last = require('./utils/last.cjs');
77
76
  var merge = require('./utils/merge.cjs');
@@ -79,6 +78,8 @@ var max = require('./utils/max.cjs');
79
78
  var min = require('./utils/min.cjs');
80
79
  var load = require('./utils/load.cjs');
81
80
  var at = require('./utils/at.cjs');
81
+ var replace = require('./utils/replace/replace.cjs');
82
+ var replaceAt = require('./utils/replace/replace-at.cjs');
82
83
 
83
84
 
84
85
 
@@ -153,7 +154,6 @@ exports.throttle = throttle.throttle;
153
154
  exports.clone = clone.clone;
154
155
  exports.toggle = toggle.toggle;
155
156
  exports.taggedTemplateLiterals = taggedTemplateLiterals.taggedTemplateLiterals;
156
- exports.replace = replace.replace;
157
157
  exports.first = first.first;
158
158
  exports.last = last.last;
159
159
  exports.merge = merge.merge;
@@ -161,3 +161,5 @@ exports.max = max.max;
161
161
  exports.min = min.min;
162
162
  exports.load = load.load;
163
163
  exports.at = at.at;
164
+ exports.replace = replace.replace;
165
+ exports.replaceAt = replaceAt.replaceAt;
package/dist/index.d.ts CHANGED
@@ -81,7 +81,7 @@ export { throttle } from "./utils/throttle";
81
81
  export { clone } from "./utils/clone";
82
82
  export { toggle } from "./utils/toggle";
83
83
  export { taggedTemplateLiterals } from "./utils/tagged-template-literals";
84
- export { replace } from "./utils/replace";
84
+ export { replace, replaceAt } from "./utils/replace";
85
85
  export { first } from "./utils/first";
86
86
  export { last } from "./utils/last";
87
87
  export { merge } from "./utils/merge";
package/dist/index.mjs CHANGED
@@ -69,7 +69,6 @@ export { throttle } from './utils/throttle.mjs';
69
69
  export { clone } from './utils/clone.mjs';
70
70
  export { toggle } from './utils/toggle.mjs';
71
71
  export { taggedTemplateLiterals } from './utils/tagged-template-literals.mjs';
72
- export { replace } from './utils/replace.mjs';
73
72
  export { first } from './utils/first.mjs';
74
73
  export { last } from './utils/last.mjs';
75
74
  export { merge } from './utils/merge.mjs';
@@ -77,3 +76,5 @@ export { max } from './utils/max.mjs';
77
76
  export { min } from './utils/min.mjs';
78
77
  export { load } from './utils/load.mjs';
79
78
  export { at } from './utils/at.mjs';
79
+ export { replace } from './utils/replace/replace.mjs';
80
+ export { replaceAt } from './utils/replace/replace-at.mjs';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Checks if a given key is a deep key.
3
+ *
4
+ * A deep key is a string that contains a dot (.) or square brackets with a property accessor.
5
+ *
6
+ * @param {PropertyKey} key - The key to check.
7
+ * @returns {boolean} - Returns true if the key is a deep key, otherwise false.
8
+ *
9
+ * Examples:
10
+ *
11
+ * isDeepKey('a.b') // true
12
+ * isDeepKey('a[b]') // true
13
+ * isDeepKey('a') // false
14
+ * isDeepKey(123) // false
15
+ * isDeepKey('a.b.c') // true
16
+ * isDeepKey('a[b][c]') // true
17
+ */
18
+ export declare function isDeepKey(key: PropertyKey): boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Checks if `value` is a property name and not a property path. (It's ok that the `value` is not in the keys of the `object`)
3
+ * @param {unknown} value The value to check.
4
+ * @param {unknown} object The object to query.
5
+ * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
6
+ *
7
+ * @example
8
+ * isKey('a', { a: 1 });
9
+ * // => true
10
+ *
11
+ * isKey('a.b', { a: { b: 2 } });
12
+ * // => false
13
+ */
14
+ export declare function isKey(value?: unknown, object?: unknown): value is PropertyKey;
@@ -1,13 +1,34 @@
1
1
  'use strict';
2
2
 
3
3
  var _typeof = require('@babel/runtime/helpers/typeof');
4
+ var isFunction = require('./is-function.cjs');
5
+ var isNull = require('./is-null.cjs');
4
6
 
5
7
  /**
6
- * @description
7
- * is object
8
+ * Checks if the given value is an object. An object is a value that is
9
+ * not a primitive type (string, number, boolean, symbol, null, or undefined).
10
+ *
11
+ * This function tests whether the provided value is an object or not.
12
+ * It returns `true` if the value is an object, and `false` otherwise.
13
+ *
14
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
15
+ *
16
+ * @param {unknown} value - The value to check if it is an object.
17
+ * @returns {value is object} `true` if the value is an object, `false` otherwise.
18
+ *
19
+ * @example
20
+ * const value1 = {};
21
+ * const value2 = [1, 2, 3];
22
+ * const value3 = () => {};
23
+ * const value4 = null;
24
+ *
25
+ * console.log(isObject(value1)); // true
26
+ * console.log(isObject(value2)); // true
27
+ * console.log(isObject(value3)); // true
28
+ * console.log(isObject(value4)); // false
8
29
  */
9
- var isObject = function isObject(value) {
10
- return !!value && _typeof(value) === "object";
11
- };
30
+ function isObject(value) {
31
+ return !isNull.isNull(value) && (_typeof(value) === "object" || isFunction.isFunction(value));
32
+ }
12
33
 
13
34
  exports.isObject = isObject;
@@ -1,6 +1,24 @@
1
1
  /**
2
- * @description
3
- * is object
2
+ * Checks if the given value is an object. An object is a value that is
3
+ * not a primitive type (string, number, boolean, symbol, null, or undefined).
4
+ *
5
+ * This function tests whether the provided value is an object or not.
6
+ * It returns `true` if the value is an object, and `false` otherwise.
7
+ *
8
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
9
+ *
10
+ * @param {unknown} value - The value to check if it is an object.
11
+ * @returns {value is object} `true` if the value is an object, `false` otherwise.
12
+ *
13
+ * @example
14
+ * const value1 = {};
15
+ * const value2 = [1, 2, 3];
16
+ * const value3 = () => {};
17
+ * const value4 = null;
18
+ *
19
+ * console.log(isObject(value1)); // true
20
+ * console.log(isObject(value2)); // true
21
+ * console.log(isObject(value3)); // true
22
+ * console.log(isObject(value4)); // false
4
23
  */
5
- declare const isObject: (value: unknown) => value is Object;
6
- export { isObject };
24
+ export declare function isObject(value?: unknown): value is object;
@@ -1,11 +1,32 @@
1
1
  import _typeof from '@babel/runtime/helpers/typeof';
2
+ import { isFunction } from './is-function.mjs';
3
+ import { isNull } from './is-null.mjs';
2
4
 
3
5
  /**
4
- * @description
5
- * is object
6
+ * Checks if the given value is an object. An object is a value that is
7
+ * not a primitive type (string, number, boolean, symbol, null, or undefined).
8
+ *
9
+ * This function tests whether the provided value is an object or not.
10
+ * It returns `true` if the value is an object, and `false` otherwise.
11
+ *
12
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
13
+ *
14
+ * @param {unknown} value - The value to check if it is an object.
15
+ * @returns {value is object} `true` if the value is an object, `false` otherwise.
16
+ *
17
+ * @example
18
+ * const value1 = {};
19
+ * const value2 = [1, 2, 3];
20
+ * const value3 = () => {};
21
+ * const value4 = null;
22
+ *
23
+ * console.log(isObject(value1)); // true
24
+ * console.log(isObject(value2)); // true
25
+ * console.log(isObject(value3)); // true
26
+ * console.log(isObject(value4)); // false
6
27
  */
7
- var isObject = function isObject(value) {
8
- return !!value && _typeof(value) === "object";
9
- };
28
+ function isObject(value) {
29
+ return !isNull(value) && (_typeof(value) === "object" || isFunction(value));
30
+ }
10
31
 
11
32
  export { isObject };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Check whether a value is a symbol.
3
+ *
4
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
5
+ *
6
+ * @param {unknown} value The value to check.
7
+ * @returns {value is symbol} Returns `true` if `value` is a symbol, else `false`.
8
+ * @example
9
+ * isSymbol(Symbol.iterator);
10
+ * // => true
11
+ *
12
+ * isSymbol('abc');
13
+ * // => false
14
+ */
15
+ export declare function isSymbol(value?: unknown): value is symbol;
@@ -1 +1 @@
1
- export type First<T, R = undefined> = T extends string ? string : T extends [infer D, ...Array<unknown>] ? D : T extends Array<infer S> ? S | undefined : R;
1
+ export type First<T> = T extends null | undefined ? undefined : T extends string ? string : T extends [infer D, ...Array<any>] ? D : T extends Array<infer S> ? S | undefined : T;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * See the definition of `@types/lodash`.
3
+ */
4
+ type GetIndexedField<T, K> = K extends keyof T ? T[K] : K extends `${number}` ? "length" extends keyof T ? number extends T["length"] ? number extends keyof T ? T[number] : undefined : undefined : undefined : undefined;
5
+ type FieldWithPossiblyUndefined<T, Key> = Get<Exclude<T, undefined>, Key> | Extract<T, undefined>;
6
+ type IndexedFieldWithPossiblyUndefined<T, Key> = GetIndexedField<Exclude<T, undefined>, Key> | Extract<T, undefined>;
7
+ export type Get<T, P> = P extends `${infer Left}.${infer Right}` ? Left extends keyof Exclude<T, undefined> ? FieldWithPossiblyUndefined<Exclude<T, undefined>[Left], Right> | Extract<T, undefined> : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined<IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey> : undefined : IndexedFieldWithPossiblyUndefined<T, P>;
8
+ export {};
@@ -1 +1 @@
1
- export type Last<T, R = undefined> = T extends [...Array<unknown>, infer D] ? D : T extends Array<infer S> ? S | undefined : R;
1
+ export type Last<T> = T extends null | undefined ? undefined : T extends [...Array<unknown>, infer D] ? D : T extends Array<infer S> ? S | undefined : T;
package/dist/utils/at.cjs CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  var isString = require('../is/is-string.cjs');
4
4
 
5
- function at(value, pos) {
5
+ function at(value, index) {
6
6
  if (isString.isString(value)) {
7
- return value.at(pos);
7
+ return value.at(index);
8
8
  }
9
- // check can i use `at`
10
- if (!!Array.prototype.at) {
11
- return value.at(pos);
9
+ // @ts-expect-error Can i use `at`
10
+ if (Array.prototype.at) {
11
+ return value.at(index);
12
12
  }
13
- return value[pos];
13
+ return value[index];
14
14
  }
15
15
 
16
16
  exports.at = at;
@@ -2,6 +2,6 @@ import type { Partialable } from "../types";
2
2
  /**
3
3
  * @description for different browser or browser version, use good api to cover
4
4
  */
5
- declare function at(value: string, pos: number): string;
6
- declare function at<T>(value: Array<T>, pos: number): Partialable<T>;
5
+ declare function at(value: string, index: number): string;
6
+ declare function at<T>(value: Array<T>, index: number): Partialable<T>;
7
7
  export { at };
package/dist/utils/at.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  import { isString } from '../is/is-string.mjs';
2
2
 
3
- function at(value, pos) {
3
+ function at(value, index) {
4
4
  if (isString(value)) {
5
- return value.at(pos);
5
+ return value.at(index);
6
6
  }
7
- // check can i use `at`
8
- if (!!Array.prototype.at) {
9
- return value.at(pos);
7
+ // @ts-expect-error Can i use `at`
8
+ if (Array.prototype.at) {
9
+ return value.at(index);
10
10
  }
11
- return value[pos];
11
+ return value[index];
12
12
  }
13
13
 
14
14
  export { at };
@@ -1,18 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var toArray = require('./to-array.cjs');
4
3
  var at = require('./at.cjs');
5
- var isString = require('../is/is-string.cjs');
4
+ var isVoid = require('../is/is-void.cjs');
6
5
 
7
- /**
8
- * @description
9
- * first element of array
10
- */
11
- var first = function first(value) {
12
- if (isString.isString(value)) {
13
- return value.at(0);
6
+ function first(value) {
7
+ if (isVoid.isVoid(value)) {
8
+ return void 0;
14
9
  }
15
- return at.at(toArray.toArray(value), 0);
16
- };
10
+ // @ts-expect-error `at` support types
11
+ return at.at(value, 0);
12
+ }
17
13
 
18
14
  exports.first = first;
@@ -1,6 +1,9 @@
1
1
  import { type First } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
- * first element of array
4
+ * first element
5
5
  */
6
- export declare const first: <T = unknown>(value: T) => First<T, T>;
6
+ declare function first(value: undefined | null): undefined;
7
+ declare function first(value: string): string;
8
+ declare function first<T extends Array<unknown>>(value: T): First<T> | undefined;
9
+ export { first };
@@ -1,16 +1,12 @@
1
- import { toArray } from './to-array.mjs';
2
1
  import { at } from './at.mjs';
3
- import { isString } from '../is/is-string.mjs';
2
+ import { isVoid } from '../is/is-void.mjs';
4
3
 
5
- /**
6
- * @description
7
- * first element of array
8
- */
9
- var first = function first(value) {
10
- if (isString(value)) {
11
- return value.at(0);
4
+ function first(value) {
5
+ if (isVoid(value)) {
6
+ return void 0;
12
7
  }
13
- return at(toArray(value), 0);
14
- };
8
+ // @ts-expect-error `at` support types
9
+ return at(value, 0);
10
+ }
15
11
 
16
12
  export { first };
@@ -0,0 +1,244 @@
1
+ import type { Get } from "../types/get";
2
+ /**
3
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
4
+ *
5
+ * @template T - The type of the object.
6
+ * @template K - The type of the key in the object.
7
+ * @template D - The type of the default value.
8
+ *
9
+ * @param {T} object - The object to query.
10
+ * @param {K | [K]} path - The path of the property to get.
11
+ * @returns {T[K]} - Returns the resolved value.
12
+ */
13
+ export declare function get<T extends object, K extends keyof T>(object: T, path: K | readonly [K]): T[K];
14
+ /**
15
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
16
+ *
17
+ * @template T - The type of the object.
18
+ * @template K - The type of the key in the object.
19
+ *
20
+ * @param {T | null | undefined} object - The object to query.
21
+ * @param {K | [K]} path - The path of the property to get.
22
+ * @returns {T[K] | undefined} - Returns the resolved value.
23
+ */
24
+ export declare function get<T extends object, K extends keyof T>(object: T | null | undefined, path: K | readonly [K]): T[K] | undefined;
25
+ /**
26
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
27
+ *
28
+ * @template T - The type of the object.
29
+ * @template K - The type of the key in the object.
30
+ * @template D - The type of the default value.
31
+ *
32
+ * @param {T | null | undefined} object - The object to query.
33
+ * @param {K | [K]} path - The path of the property to get.
34
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
35
+ * @returns {Exclude<T[K], undefined> | D} - Returns the resolved value.
36
+ */
37
+ export declare function get<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | readonly [K], defaultValue: D): Exclude<T[K], undefined> | D;
38
+ /**
39
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
40
+ *
41
+ * @template T - The type of the object.
42
+ * @template K1 - The type of the first key in the object.
43
+ * @template K2 - The type of the second key in the object.
44
+ *
45
+ * @param {T} object - The object to query.
46
+ * @param {[K1, K2]} path - The path of the property to get.
47
+ * @returns {T[K1][K2]} - Returns the resolved value.
48
+ */
49
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: readonly [K1, K2]): T[K1][K2];
50
+ /**
51
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
52
+ *
53
+ * @template T - The type of the object.
54
+ * @template K1 - The type of the first key in the object.
55
+ * @template K2 - The type of the second key in the object.
56
+ *
57
+ * @param {T | null | undefined} object - The object to query.
58
+ * @param {[K1, K2]} path - The path of the property to get.
59
+ * @returns {T[K1][K2] | undefined} - Returns the resolved value.
60
+ */
61
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined;
62
+ /**
63
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
64
+ *
65
+ * @template T - The type of the object.
66
+ * @template K1 - The type of the first key in the object.
67
+ * @template K2 - The type of the second key in the object.
68
+ * @template D - The type of the default value.
69
+ *
70
+ * @param {T | null | undefined} object - The object to query.
71
+ * @param {[K1, K2]} path - The path of the property to get.
72
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
73
+ * @returns {Exclude<T[K1][K2], undefined> | D} - Returns the resolved value.
74
+ */
75
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: readonly [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
76
+ /**
77
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
78
+ *
79
+ * @template T - The type of the object.
80
+ * @template K1 - The type of the first key in the object.
81
+ * @template K2 - The type of the second key in the object.
82
+ * @template K3 - The type of the third key in the object.
83
+ *
84
+ * @param {T} object - The object to query.
85
+ * @param {[K1, K2, K3]} path - The path of the property to get.
86
+ * @returns {T[K1][K2][K3]} - Returns the resolved value.
87
+ */
88
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3];
89
+ /**
90
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
91
+ *
92
+ * @template T - The type of the object.
93
+ * @template K1 - The type of the first key in the object.
94
+ * @template K2 - The type of the second key in the object.
95
+ * @template K3 - The type of the third key in the object.
96
+ *
97
+ * @param {T | null | undefined} object - The object to query.
98
+ * @param {[K1, K2, K3]} path - The path of the property to get.
99
+ * @returns {T[K1][K2][K3] | undefined} - Returns the resolved value.
100
+ */
101
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: readonly [K1, K2, K3]): T[K1][K2][K3] | undefined;
102
+ /**
103
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
104
+ *
105
+ * @template T - The type of the object.
106
+ * @template K1 - The type of the first key in the object.
107
+ * @template K2 - The type of the second key in the object.
108
+ * @template K3 - The type of the third key in the object.
109
+ * @template D - The type of the default value.
110
+ *
111
+ * @param {T | null | undefined} object - The object to query.
112
+ * @param {[K1, K2, K3]} path - The path of the property to get.
113
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
114
+ * @returns {Exclude<T[K1][K2][K3], undefined> | D} - Returns the resolved value.
115
+ */
116
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: readonly [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
117
+ /**
118
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
119
+ *
120
+ * @template T - The type of the object.
121
+ * @template K1 - The type of the first key in the object.
122
+ * @template K2 - The type of the second key in the object.
123
+ * @template K3 - The type of the third key in the object.
124
+ * @template K4 - The type of the fourth key in the object.
125
+ *
126
+ * @param {T} object - The object to query.
127
+ * @param {[K1, K2, K3, K4]} path - The path of the property to get.
128
+ * @returns {T[K1][K2][K3][K4]} - Returns the resolved value.
129
+ */
130
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4];
131
+ /**
132
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
133
+ *
134
+ * @template T - The type of the object.
135
+ * @template K1 - The type of the first key in the object.
136
+ * @template K2 - The type of the second key in the object.
137
+ * @template K3 - The type of the third key in the object.
138
+ * @template K4 - The type of the fourth key in the object.
139
+ *
140
+ * @param {T | null | undefined} object - The object to query.
141
+ * @param {[K1, K2, K3, K4]} path - The path of the property to get.
142
+ * @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value.
143
+ */
144
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
145
+ /**
146
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
147
+ *
148
+ * @template T - The type of the object.
149
+ * @template K1 - The type of the first key in the object.
150
+ * @template K2 - The type of the second key in the object.
151
+ * @template K3 - The type of the third key in the object.
152
+ * @template K4 - The type of the fourth key in the object.
153
+ * @template D - The type of the default value.
154
+ *
155
+ * @param {T | null | undefined} object - The object to query.
156
+ * @param {[K1, K2, K3, K4]} path - The path of the property to get.
157
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
158
+ * @returns {Exclude<T[K1][K2][K3][K4], undefined> | D} - Returns the resolved value.
159
+ */
160
+ export declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: readonly [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
161
+ /**
162
+ * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
163
+ *
164
+ * @template T - The type of the value.
165
+ *
166
+ * @param {Record<number, T>} object - The object to query.
167
+ * @param {number} path - The path of the property to get.
168
+ * @returns {T} - Returns the resolved value.
169
+ */
170
+ export declare function get<T>(object: Record<number, T>, path: number): T;
171
+ /**
172
+ * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
173
+ *
174
+ * @template T - The type of the value.
175
+ *
176
+ * @param {Record<number, T> | null | undefined} object - The object to query.
177
+ * @param {number} path - The path of the property to get.
178
+ * @returns {T | undefined} - Returns the resolved value.
179
+ */
180
+ export declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
181
+ /**
182
+ * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
183
+ *
184
+ * @template T - The type of the value.
185
+ * @template D - The type of the default value.
186
+ *
187
+ * @param {Record<number, T> | null | undefined} object - The object to query.
188
+ * @param {number} path - The path of the property to get.
189
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
190
+ * @returns {T | D} - Returns the resolved value.
191
+ */
192
+ export declare function get<T, D>(object: Record<number, T> | null | undefined, path: number, defaultValue: D): T | D;
193
+ /**
194
+ * Retrieves the value at a given path from a null or undefined object, returning the default value.
195
+ *
196
+ * @template D - The type of the default value.
197
+ *
198
+ * @param {null | undefined} object - The object to query.
199
+ * @param {PropertyKey} path - The path of the property to get.
200
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
201
+ * @returns {D} - Returns the default value.
202
+ */
203
+ export declare function get<D>(object: null | undefined, path: PropertyKey, defaultValue: D): D;
204
+ /**
205
+ * Retrieves the value at a given path from a null or undefined object, returning undefined.
206
+ *
207
+ * @param {null | undefined} object - The object to query.
208
+ * @param {PropertyKey} path - The path of the property to get.
209
+ * @returns {undefined} - Returns undefined.
210
+ */
211
+ export declare function get(object: null | undefined, path: PropertyKey): undefined;
212
+ /**
213
+ * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.
214
+ *
215
+ * @template T - The type of the object.
216
+ * @template P - The type of the path.
217
+ *
218
+ * @param {T} data - The object to query.
219
+ * @param {P} path - The path of the property to get.
220
+ * @returns {string extends P ? any : Get<T, P>} - Returns the resolved value.
221
+ */
222
+ export declare function get<T, P extends string>(data: T, path: P): string extends P ? any : Get<T, P>;
223
+ /**
224
+ * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.
225
+ *
226
+ * @template T - The type of the object.
227
+ * @template P - The type of the path.
228
+ * @template D - The type of the default value.
229
+ *
230
+ * @param {T} data - The object to query.
231
+ * @param {P} path - The path of the property to get.
232
+ * @param {D} defaultValue - The value returned if the resolved value is undefined.
233
+ * @returns {Exclude<Get<T, P>, null | undefined> | D} - Returns the resolved value.
234
+ */
235
+ export declare function get<T, P extends string, D = Get<T, P>>(data: T, path: P, defaultValue: D): Exclude<Get<T, P>, null | undefined> | D;
236
+ /**
237
+ * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
238
+ *
239
+ * @param {unknown} object - The object to query.
240
+ * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get.
241
+ * @param {unknown} [defaultValue] - The value returned if the resolved value is undefined.
242
+ * @returns {any} - Returns the resolved value.
243
+ */
244
+ export declare function get(object: unknown, path: PropertyKey | readonly PropertyKey[], defaultValue?: unknown): any;
@@ -0,0 +1 @@
1
+ export declare function isIndex(value: PropertyKey, length?: number): boolean;
@@ -1,18 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var toArray = require('./to-array.cjs');
4
- var isString = require('../is/is-string.cjs');
5
3
  var at = require('./at.cjs');
4
+ var isVoid = require('../is/is-void.cjs');
6
5
 
7
- /**
8
- * @description
9
- * last element of array
10
- */
11
- var last = function last(value) {
12
- if (isString.isString(value)) {
13
- return value.at(-1);
6
+ function last(value) {
7
+ if (isVoid.isVoid(value)) {
8
+ return void 0;
14
9
  }
15
- return at.at(toArray.toArray(value), -1);
16
- };
10
+ // @ts-expect-error `at` support types
11
+ return at.at(value, -1);
12
+ }
17
13
 
18
14
  exports.last = last;
@@ -1,6 +1,9 @@
1
1
  import { type Last } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
- * last element of array
4
+ * last element
5
5
  */
6
- export declare const last: <T = unknown>(value: T) => Last<T, T>;
6
+ declare function last(value: undefined | null): undefined;
7
+ declare function last(value: string): string;
8
+ declare function last<T extends Array<unknown>>(value: T): Last<T> | undefined;
9
+ export { last };
@@ -1,16 +1,12 @@
1
- import { toArray } from './to-array.mjs';
2
- import { isString } from '../is/is-string.mjs';
3
1
  import { at } from './at.mjs';
2
+ import { isVoid } from '../is/is-void.mjs';
4
3
 
5
- /**
6
- * @description
7
- * last element of array
8
- */
9
- var last = function last(value) {
10
- if (isString(value)) {
11
- return value.at(-1);
4
+ function last(value) {
5
+ if (isVoid(value)) {
6
+ return void 0;
12
7
  }
13
- return at(toArray(value), -1);
14
- };
8
+ // @ts-expect-error `at` support types
9
+ return at(value, -1);
10
+ }
15
11
 
16
12
  export { last };
@@ -3,5 +3,5 @@
3
3
  * deep merge api
4
4
  * use unique values to avoid duplicate
5
5
  */
6
- declare const merge: <T>(values_0: T, ...values: unknown[]) => T;
6
+ declare const merge: <T>(...values: [T, ...unknown[]]) => T;
7
7
  export { merge };
@@ -0,0 +1,3 @@
1
+ import { replace } from "./replace";
2
+ import { replaceAt } from "./replace-at";
3
+ export { replace, replaceAt };
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * replace at
5
+ */
6
+ function replaceAt(value, index, replaceValue) {
7
+ var _newValue = Array.from(value);
8
+ _newValue[index] = replaceValue;
9
+ return _newValue;
10
+ }
11
+
12
+ exports.replaceAt = replaceAt;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * replace at
3
+ */
4
+ declare function replaceAt<T>(value: Array<T>, index: number, replaceValue: T): T[];
5
+ export { replaceAt };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * replace at
3
+ */
4
+ function replaceAt(value, index, replaceValue) {
5
+ var _newValue = Array.from(value);
6
+ _newValue[index] = replaceValue;
7
+ return _newValue;
8
+ }
9
+
10
+ export { replaceAt };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var isString = require('../../is/is-string.cjs');
4
+
5
+ function replace(value) {
6
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
7
+ args[_key - 1] = arguments[_key];
8
+ }
9
+ if (isString.isString(value)) {
10
+ return value.replace.apply(value, args);
11
+ }
12
+ var searchValue = args[0],
13
+ incoming = args[1];
14
+ return value.map(function (_v) {
15
+ return _v === searchValue ? incoming : _v;
16
+ });
17
+ }
18
+
19
+ exports.replace = replace;
@@ -1,5 +1,5 @@
1
- type StringReplacing = [searchValue: string, incoming: string];
2
- type ArrayReplacing<T> = [incoming: Array<T> | T, start: number, end?: number];
1
+ type StringReplacing = [searchValue: string, replaceValue: string];
2
+ type ArrayReplacing<T> = [searchValue: T, replaceValue: T];
3
3
  /**
4
4
  * @description
5
5
  * string replace.
@@ -0,0 +1,17 @@
1
+ import { isString } from '../../is/is-string.mjs';
2
+
3
+ function replace(value) {
4
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
5
+ args[_key - 1] = arguments[_key];
6
+ }
7
+ if (isString(value)) {
8
+ return value.replace.apply(value, args);
9
+ }
10
+ var searchValue = args[0],
11
+ incoming = args[1];
12
+ return value.map(function (_v) {
13
+ return _v === searchValue ? incoming : _v;
14
+ });
15
+ }
16
+
17
+ export { replace };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {T} obj - The object to modify.
6
+ * @param {PropertyKey | PropertyKey[]} path - The path of the property to set.
7
+ * @param {unknown} value - The value to set.
8
+ * @returns {T} - The modified object.
9
+ *
10
+ * @example
11
+ * // Set a value in a nested object
12
+ * const obj = { a: { b: { c: 3 } } };
13
+ * set(obj, 'a.b.c', 4);
14
+ * console.log(obj.a.b.c); // 4
15
+ *
16
+ * @example
17
+ * // Set a value in an array
18
+ * const arr = [1, 2, 3];
19
+ * set(arr, 1, 4);
20
+ * console.log(arr[1]); // 4
21
+ *
22
+ * @example
23
+ * // Create non-existent path and set value
24
+ * const obj = {};
25
+ * set(obj, 'a.b.c', 4);
26
+ * console.log(obj); // { a: { b: { c: 4 } } }
27
+ */
28
+ export declare function set<T extends object>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
@@ -1,18 +1,19 @@
1
1
  'use strict';
2
2
 
3
- var isString = require('../is/is-string.cjs');
4
- var isUndefined = require('../is/is-undefined.cjs');
3
+ var isArray = require('../is/is-array.cjs');
4
+ var isVoid = require('../is/is-void.cjs');
5
5
 
6
- function toArray(value, splitter) {
7
- // string branch
8
- if (isString.isString(value)) {
9
- if (isUndefined.isUndefined(splitter)) {
10
- return [value];
11
- }
12
- return value.split(splitter);
6
+ /**
7
+ * @description
8
+ * convert any type data to a array
9
+ */
10
+ function toArray(value) {
11
+ // in `void` case, just return empty array
12
+ if (isVoid.isVoid(value)) {
13
+ return [];
13
14
  }
14
- // array branch
15
- if (Array.isArray(value)) {
15
+ // already is `Array`
16
+ if (isArray.isArray(value)) {
16
17
  return value;
17
18
  }
18
19
  return [value];
@@ -1,8 +1,7 @@
1
- type Splitter = string | RegExp;
1
+ type ToArrayReturn<T> = T extends null ? unknown[] : T extends undefined ? unknown : T extends Array<infer E> ? E[] : T[];
2
2
  /**
3
3
  * @description
4
4
  * convert any type data to a array
5
5
  */
6
- declare function toArray(value: string, splitter?: Splitter): string[];
7
- declare function toArray<T = unknown>(value: T): T extends Array<unknown> ? T : T[];
6
+ declare function toArray<T extends unknown = unknown>(value: T): ToArrayReturn<T>;
8
7
  export { toArray };
@@ -1,16 +1,17 @@
1
- import { isString } from '../is/is-string.mjs';
2
- import { isUndefined } from '../is/is-undefined.mjs';
1
+ import { isArray } from '../is/is-array.mjs';
2
+ import { isVoid } from '../is/is-void.mjs';
3
3
 
4
- function toArray(value, splitter) {
5
- // string branch
6
- if (isString(value)) {
7
- if (isUndefined(splitter)) {
8
- return [value];
9
- }
10
- return value.split(splitter);
4
+ /**
5
+ * @description
6
+ * convert any type data to a array
7
+ */
8
+ function toArray(value) {
9
+ // in `void` case, just return empty array
10
+ if (isVoid(value)) {
11
+ return [];
11
12
  }
12
- // array branch
13
- if (Array.isArray(value)) {
13
+ // already is `Array`
14
+ if (isArray(value)) {
14
15
  return value;
15
16
  }
16
17
  return [value];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Converts `value` to a string key if it's not a string or symbol.
3
+ *
4
+ * @private
5
+ * @param {unknown} value The value to inspect.
6
+ * @returns {string|symbol} Returns the key.
7
+ */
8
+ export declare function toKey(value: unknown): string | symbol;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts a deep key string into an array of path segments.
3
+ *
4
+ * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
5
+ *
6
+ * @param {string} deepKey - The deep key string to convert.
7
+ * @returns {string[]} An array of strings, each representing a segment of the path.
8
+ *
9
+ * Examples:
10
+ *
11
+ * toPath('a.b.c') // Returns ['a', 'b', 'c']
12
+ * toPath('a[b][c]') // Returns ['a', 'b', 'c']
13
+ * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
14
+ * toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
15
+ * toPath('') // Returns []
16
+ * toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
17
+ */
18
+ export declare function toPaths(deepKey: string): string[];
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Updates the value at the specified path of the given object using an updater function.
3
+ * If any part of the path does not exist, it will be created.
4
+ *
5
+ * @template T - The type of the object.
6
+ * @param {T} target - The object to modify.
7
+ * @param {PropertyKey | PropertyKey[]} path - The path of the property to update.
8
+ * @param {(value: unknown) => unknown} updater - The function to produce the updated value.
9
+ * @returns {T} - The modified object.
10
+ */
11
+ export declare function update<T extends object | null | undefined>(target: T, path: PropertyKey | readonly PropertyKey[], updater: (value: unknown) => unknown): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "react utils collection",
5
5
  "exports": {
6
6
  ".": {
@@ -20,35 +20,35 @@
20
20
  "./types": "./dist/types/index.d.ts"
21
21
  },
22
22
  "dependencies": {
23
- "@babel/runtime": "^7.26.9",
24
- "react-is": "^19.0.0",
25
- "rxjs": "^7.8.1"
23
+ "@babel/runtime": "^7.27.0",
24
+ "react-is": "^19.1.0",
25
+ "rxjs": "^7.8.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@babel/core": "^7.26.9",
29
- "@babel/plugin-transform-runtime": "^7.26.9",
28
+ "@babel/core": "^7.26.10",
29
+ "@babel/plugin-transform-runtime": "^7.26.10",
30
30
  "@babel/preset-env": "^7.26.9",
31
31
  "@babel/preset-react": "^7.26.3",
32
- "@babel/preset-typescript": "^7.26.0",
32
+ "@babel/preset-typescript": "^7.27.0",
33
33
  "@jest/globals": "^29.7.0",
34
34
  "@rollup/plugin-babel": "^6.0.4",
35
- "@rollup/plugin-node-resolve": "^16.0.0",
35
+ "@rollup/plugin-node-resolve": "^16.0.1",
36
36
  "@rollup/plugin-typescript": "^12.1.2",
37
- "@testing-library/react": "^16.2.0",
37
+ "@testing-library/react": "^16.3.0",
38
38
  "@types/babel__core": "^7.20.5",
39
- "@types/react": "^19.0.10",
40
- "@types/react-dom": "^19.0.4",
39
+ "@types/react": "^19.1.2",
40
+ "@types/react-dom": "^19.1.2",
41
41
  "@types/react-is": "^19.0.0",
42
42
  "jest": "^29.7.0",
43
43
  "jest-environment-jsdom": "^29.7.0",
44
- "react": "^19.0.0",
45
- "react-dom": "^19.0.0",
46
- "rollup": "^4.34.8",
47
- "typescript": "5.7.3"
44
+ "react": "^19.1.0",
45
+ "react-dom": "^19.1.0",
46
+ "rollup": "^4.40.0",
47
+ "typescript": "5.8.3"
48
48
  },
49
49
  "peerDependencies": {
50
- "react": "18",
51
- "react-dom": "18"
50
+ "react": ">=18",
51
+ "react-dom": ">=18"
52
52
  },
53
53
  "files": [
54
54
  "dist/"
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
- var isString = require('../is/is-string.cjs');
5
- var toArray = require('./to-array.cjs');
6
-
7
- function replace(value) {
8
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
9
- args[_key - 1] = arguments[_key];
10
- }
11
- if (isString.isString(value)) {
12
- return value.replace.apply(value, args);
13
- }
14
- var incoming = args[0],
15
- start = args[1],
16
- end = args[2];
17
- var _incomings = toArray.toArray(incoming);
18
- var leading = value.slice(0, start);
19
- var trailing = value.slice(end !== null && end !== void 0 ? end : start + _incomings.length);
20
- return [].concat(_toConsumableArray(leading), _toConsumableArray(_incomings), _toConsumableArray(trailing));
21
- }
22
-
23
- exports.replace = replace;
@@ -1,21 +0,0 @@
1
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
- import { isString } from '../is/is-string.mjs';
3
- import { toArray } from './to-array.mjs';
4
-
5
- function replace(value) {
6
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
7
- args[_key - 1] = arguments[_key];
8
- }
9
- if (isString(value)) {
10
- return value.replace.apply(value, args);
11
- }
12
- var incoming = args[0],
13
- start = args[1],
14
- end = args[2];
15
- var _incomings = toArray(incoming);
16
- var leading = value.slice(0, start);
17
- var trailing = value.slice(end !== null && end !== void 0 ? end : start + _incomings.length);
18
- return [].concat(_toConsumableArray(leading), _toConsumableArray(_incomings), _toConsumableArray(trailing));
19
- }
20
-
21
- export { replace };