@aiszlab/relax 1.3.15 → 1.3.17

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 (54) hide show
  1. package/dist/dom/contains.cjs +4 -3
  2. package/dist/dom/contains.d.ts +1 -1
  3. package/dist/dom/contains.mjs +4 -3
  4. package/dist/hooks/use-click-away.d.ts +1 -1
  5. package/dist/hooks/use-refs.cjs +2 -2
  6. package/dist/hooks/use-refs.d.ts +2 -2
  7. package/dist/hooks/use-refs.mjs +2 -2
  8. package/dist/hooks/use-scrollable.d.ts +1 -1
  9. package/dist/index.cjs +4 -1
  10. package/dist/index.d.ts +3 -1
  11. package/dist/index.mjs +3 -1
  12. package/dist/is/is-empty.cjs +1 -1
  13. package/dist/is/is-empty.mjs +1 -1
  14. package/dist/is/is-primitive.cjs +2 -1
  15. package/dist/is/is-primitive.d.ts +4 -2
  16. package/dist/is/is-primitive.mjs +2 -1
  17. package/dist/path/index.cjs +7 -0
  18. package/dist/path/index.d.ts +1 -0
  19. package/dist/path/index.mjs +1 -0
  20. package/dist/path/leaf.cjs +18 -0
  21. package/dist/path/leaf.d.ts +5 -0
  22. package/dist/path/leaf.mjs +16 -0
  23. package/dist/react/mount-ref.cjs +5 -5
  24. package/dist/react/mount-ref.d.ts +1 -1
  25. package/dist/react/mount-ref.mjs +5 -5
  26. package/dist/types/first.d.ts +1 -1
  27. package/dist/utils/clone.cjs +33 -6
  28. package/dist/utils/clone.d.ts +1 -1
  29. package/dist/utils/clone.mjs +33 -6
  30. package/dist/utils/debounce.cjs +4 -9
  31. package/dist/utils/debounce.d.ts +3 -3
  32. package/dist/utils/debounce.mjs +4 -9
  33. package/dist/utils/first.cjs +4 -1
  34. package/dist/utils/first.d.ts +1 -1
  35. package/dist/utils/first.mjs +4 -1
  36. package/dist/utils/last.cjs +4 -1
  37. package/dist/utils/last.d.ts +1 -1
  38. package/dist/utils/last.mjs +4 -1
  39. package/dist/utils/merge.cjs +53 -0
  40. package/dist/utils/merge.d.ts +7 -0
  41. package/dist/utils/merge.mjs +51 -0
  42. package/dist/utils/throttle.cjs +4 -9
  43. package/dist/utils/throttle.d.ts +2 -2
  44. package/dist/utils/throttle.mjs +4 -9
  45. package/dist/utils/unique-by.cjs +22 -0
  46. package/dist/utils/unique-by.d.ts +5 -0
  47. package/dist/utils/unique-by.mjs +20 -0
  48. package/dist/utils/unique.cjs +7 -10
  49. package/dist/utils/unique.d.ts +1 -6
  50. package/dist/utils/unique.mjs +8 -10
  51. package/dist/utils/waitable.cjs +12 -3
  52. package/dist/utils/waitable.d.ts +11 -5
  53. package/dist/utils/waitable.mjs +13 -4
  54. package/package.json +10 -1
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var contains = function contains(root, node) {
3
+ var contains = function contains(root) {
4
+ var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
4
5
  if (!root) {
5
6
  return false;
6
7
  }
7
8
  // Use native if support
8
- if (root.contains) {
9
- return root.contains(node !== null && node !== void 0 ? node : null);
9
+ if (!!root.contains) {
10
+ return root.contains(node);
10
11
  }
11
12
  // `document.contains` not support with IE11
12
13
  var _node = node;
@@ -13,4 +13,4 @@ export type Containable = {
13
13
  */
14
14
  contains?: (node: Nullable<Node>) => boolean;
15
15
  };
16
- export declare const contains: (root: Voidable<Containable>, node: Voidable<Node>) => boolean;
16
+ export declare const contains: (root: Voidable<Containable>, node?: Voidable<Node>) => boolean;
@@ -1,10 +1,11 @@
1
- var contains = function contains(root, node) {
1
+ var contains = function contains(root) {
2
+ var node = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
2
3
  if (!root) {
3
4
  return false;
4
5
  }
5
6
  // Use native if support
6
- if (root.contains) {
7
- return root.contains(node !== null && node !== void 0 ? node : null);
7
+ if (!!root.contains) {
8
+ return root.contains(node);
8
9
  }
9
10
  // `document.contains` not support with IE11
10
11
  var _node = node;
@@ -1,5 +1,5 @@
1
1
  import { type MutableRefObject } from "react";
2
- import { type Containable } from "@aiszlab/relax/dom";
2
+ import { type Containable } from "../dom";
3
3
  import type { Nullable, Arrayable } from "@aiszlab/relax/types";
4
4
  /**
5
5
  * @description
@@ -7,10 +7,10 @@ var useRefs = function useRefs() {
7
7
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
8
8
  refs[_key] = arguments[_key];
9
9
  }
10
- return useEvent.useEvent(function (_reference) {
10
+ return useEvent.useEvent(function (reference) {
11
11
  refs.forEach(function (ref) {
12
12
  if (!ref) return;
13
- mountRef.mountRef(ref, _reference);
13
+ mountRef.mountRef(ref, reference);
14
14
  });
15
15
  });
16
16
  };
@@ -1,3 +1,3 @@
1
1
  import type { Nullable, Voidable } from "@aiszlab/relax/types";
2
- import { type Refable } from "@aiszlab/relax/react";
3
- export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (_reference: T) => void;
2
+ import { type Refable } from "../react/mount-ref";
3
+ export declare const useRefs: <T>(...refs: Voidable<Refable<Nullable<T>>>[]) => (reference: T) => void;
@@ -5,10 +5,10 @@ var useRefs = function useRefs() {
5
5
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
6
6
  refs[_key] = arguments[_key];
7
7
  }
8
- return useEvent(function (_reference) {
8
+ return useEvent(function (reference) {
9
9
  refs.forEach(function (ref) {
10
10
  if (!ref) return;
11
- mountRef(ref, _reference);
11
+ mountRef(ref, reference);
12
12
  });
13
13
  });
14
14
  };
@@ -1,5 +1,5 @@
1
1
  import { type Key } from "react";
2
- import { type Orientation } from "@aiszlab/relax/dom";
2
+ import { type Orientation } from "../dom";
3
3
  interface UseScrollableProps {
4
4
  orientation?: Orientation;
5
5
  }
package/dist/index.cjs CHANGED
@@ -50,6 +50,7 @@ var isHtmlInputElement = require('./is/is-html-input-element.cjs');
50
50
  var isObject = require('./is/is-object.cjs');
51
51
  var effect = require('./utils/effect.cjs');
52
52
  var unique = require('./utils/unique.cjs');
53
+ var uniqueBy = require('./utils/unique-by.cjs');
53
54
  var range = require('./utils/range.cjs');
54
55
  var clamp = require('./utils/clamp.cjs');
55
56
  var chain = require('./utils/chain.cjs');
@@ -67,6 +68,7 @@ var replace = require('./utils/replace.cjs');
67
68
  var clsx = require('./utils/clsx.cjs');
68
69
  var first = require('./utils/first.cjs');
69
70
  var last = require('./utils/last.cjs');
71
+ var merge = require('./utils/merge.cjs');
70
72
 
71
73
 
72
74
 
@@ -120,7 +122,7 @@ exports.isHTMLInputElement = isHtmlInputElement.isHTMLInputElement;
120
122
  exports.isObject = isObject.isObject;
121
123
  exports.effect = effect.effect;
122
124
  exports.unique = unique.unique;
123
- exports.uniqueBy = unique.uniqueBy;
125
+ exports.uniqueBy = uniqueBy.uniqueBy;
124
126
  exports.range = range.range;
125
127
  exports.clamp = clamp.clamp;
126
128
  exports.chain = chain.chain;
@@ -138,3 +140,4 @@ exports.replace = replace.replace;
138
140
  exports.clsx = clsx.clsx;
139
141
  exports.first = first.first;
140
142
  exports.last = last.last;
143
+ exports.merge = merge.merge;
package/dist/index.d.ts CHANGED
@@ -59,7 +59,8 @@ export { isObject } from "./is/is-object";
59
59
  * utils
60
60
  */
61
61
  export { effect } from "./utils/effect";
62
- export { unique, uniqueBy } from "./utils/unique";
62
+ export { unique } from "./utils/unique";
63
+ export { uniqueBy } from "./utils/unique-by";
63
64
  export { range } from "./utils/range";
64
65
  export { clamp } from "./utils/clamp";
65
66
  export { chain } from "./utils/chain";
@@ -77,3 +78,4 @@ export { replace } from "./utils/replace";
77
78
  export { clsx } from "./utils/clsx";
78
79
  export { first } from "./utils/first";
79
80
  export { last } from "./utils/last";
81
+ export { merge } from "./utils/merge";
package/dist/index.mjs CHANGED
@@ -47,7 +47,8 @@ export { isHTMLElement } from './is/is-html-element.mjs';
47
47
  export { isHTMLInputElement } from './is/is-html-input-element.mjs';
48
48
  export { isObject } from './is/is-object.mjs';
49
49
  export { effect } from './utils/effect.mjs';
50
- export { unique, uniqueBy } from './utils/unique.mjs';
50
+ export { unique } from './utils/unique.mjs';
51
+ export { uniqueBy } from './utils/unique-by.mjs';
51
52
  export { range } from './utils/range.mjs';
52
53
  export { clamp } from './utils/clamp.mjs';
53
54
  export { chain } from './utils/chain.mjs';
@@ -65,3 +66,4 @@ export { replace } from './utils/replace.mjs';
65
66
  export { clsx } from './utils/clsx.mjs';
66
67
  export { first } from './utils/first.mjs';
67
68
  export { last } from './utils/last.mjs';
69
+ export { merge } from './utils/merge.mjs';
@@ -21,7 +21,7 @@ var isEmpty = function isEmpty(value) {
21
21
  if (isObject.isObject(value)) {
22
22
  return Object.keys(value).length === 0;
23
23
  }
24
- return !!value;
24
+ return !value;
25
25
  };
26
26
 
27
27
  exports.isEmpty = isEmpty;
@@ -19,7 +19,7 @@ var isEmpty = function isEmpty(value) {
19
19
  if (isObject(value)) {
20
20
  return Object.keys(value).length === 0;
21
21
  }
22
- return !!value;
22
+ return !value;
23
23
  };
24
24
 
25
25
  export { isEmpty };
@@ -2,7 +2,8 @@
2
2
 
3
3
  /**
4
4
  * @description
5
- * string/number/... is primitive type
5
+ * primitive type
6
+ * string | number | symbol | boolean | null | undefined
6
7
  */
7
8
  var isPrimitive = function isPrimitive(value) {
8
9
  return value !== Object(value);
@@ -1,5 +1,7 @@
1
+ export type Primitive = string | number | symbol | boolean | null | undefined;
1
2
  /**
2
3
  * @description
3
- * string/number/... is primitive type
4
+ * primitive type
5
+ * string | number | symbol | boolean | null | undefined
4
6
  */
5
- export declare const isPrimitive: (value: unknown) => boolean;
7
+ export declare const isPrimitive: <T extends Primitive>(value: unknown) => value is T;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @description
3
- * string/number/... is primitive type
3
+ * primitive type
4
+ * string | number | symbol | boolean | null | undefined
4
5
  */
5
6
  var isPrimitive = function isPrimitive(value) {
6
7
  return value !== Object(value);
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var leaf = require('./leaf.cjs');
4
+
5
+
6
+
7
+ exports.leaf = leaf.leaf;
@@ -0,0 +1 @@
1
+ export { leaf } from "./leaf";
@@ -0,0 +1 @@
1
+ export { leaf } from './leaf.mjs';
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @description
5
+ * leaf
6
+ */
7
+ var leaf = function leaf(path) {
8
+ var start = 0;
9
+ for (var index = path.length - 1; index >= 0; index--) {
10
+ if (path.charCodeAt(index) === 47) {
11
+ start = index + 1;
12
+ break;
13
+ }
14
+ }
15
+ return path.slice(start);
16
+ };
17
+
18
+ exports.leaf = leaf;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * leaf
4
+ */
5
+ export declare const leaf: (path: string) => string;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description
3
+ * leaf
4
+ */
5
+ var leaf = function leaf(path) {
6
+ var start = 0;
7
+ for (var index = path.length - 1; index >= 0; index--) {
8
+ if (path.charCodeAt(index) === 47) {
9
+ start = index + 1;
10
+ break;
11
+ }
12
+ }
13
+ return path.slice(start);
14
+ };
15
+
16
+ export { leaf };
@@ -2,18 +2,18 @@
2
2
 
3
3
  var isFunction = require('../is/is-function.cjs');
4
4
 
5
- var mountRef = function mountRef(ref, trigger) {
6
- if (isFunction.isFunction(ref)) {
7
- ref(trigger);
5
+ var mountRef = function mountRef(refable, reference) {
6
+ if (isFunction.isFunction(refable)) {
7
+ refable(reference);
8
8
  return;
9
9
  }
10
10
  // in deprecated react, class component can use string ref
11
11
  // but there are many problems, in relax, we just make it not work
12
12
  // issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
13
- if (typeof ref === "string") {
13
+ if (typeof refable === "string") {
14
14
  return;
15
15
  }
16
- ref.current = trigger;
16
+ refable.current = reference;
17
17
  };
18
18
 
19
19
  exports.mountRef = mountRef;
@@ -1,3 +1,3 @@
1
1
  import type { MutableRefObject, RefCallback } from "react";
2
2
  export type Refable<T> = RefCallback<T> | MutableRefObject<T> | string;
3
- export declare const mountRef: <T>(ref: Refable<T>, trigger: T) => void;
3
+ export declare const mountRef: <T>(refable: Refable<T>, reference: T) => void;
@@ -1,17 +1,17 @@
1
1
  import { isFunction } from '../is/is-function.mjs';
2
2
 
3
- var mountRef = function mountRef(ref, trigger) {
4
- if (isFunction(ref)) {
5
- ref(trigger);
3
+ var mountRef = function mountRef(refable, reference) {
4
+ if (isFunction(refable)) {
5
+ refable(reference);
6
6
  return;
7
7
  }
8
8
  // in deprecated react, class component can use string ref
9
9
  // but there are many problems, in relax, we just make it not work
10
10
  // issue for react: https://github.com/facebook/react/pull/8333#issuecomment-271648615
11
- if (typeof ref === "string") {
11
+ if (typeof refable === "string") {
12
12
  return;
13
13
  }
14
- ref.current = trigger;
14
+ refable.current = reference;
15
15
  };
16
16
 
17
17
  export { mountRef };
@@ -1 +1 @@
1
- export type First<T, R = undefined> = T extends [infer D, ...Array<unknown>] ? D : R;
1
+ export type First<T, R = undefined> = T extends string ? string : T extends [infer D, ...Array<unknown>] ? D : R;
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
3
4
  var isArray = require('../is/is-array.cjs');
4
5
  var isPrimitive = require('../is/is-primitive.cjs');
5
6
 
@@ -8,12 +9,38 @@ var isPrimitive = require('../is/is-primitive.cjs');
8
9
  * in develop, there are many cases to clone a string/number/object/array
9
10
  * this util is planning to resolve it
10
11
  */
11
- var clone = function clone(value) {
12
+ var _clone = function clone(value) {
12
13
  if (isPrimitive.isPrimitive(value)) return value;
13
- if (value instanceof Map) return new Map(value);
14
- if (value instanceof Set) return new Set(value);
15
- if (isArray.isArray(value)) return Array.from(value);
16
- return Object(value);
14
+ if (value instanceof Map) {
15
+ // @ts-ignore
16
+ return new Map(Array.from(value.entries()).map(function (_ref) {
17
+ var _ref2 = _slicedToArray(_ref, 2),
18
+ _key = _ref2[0],
19
+ _value = _ref2[1];
20
+ return [_key, _clone(_value)];
21
+ }));
22
+ }
23
+ if (value instanceof Set) {
24
+ // @ts-ignore
25
+ return new Set(Array.from(value.values()).map(function (_value) {
26
+ return _clone(_value);
27
+ }));
28
+ }
29
+ if (isArray.isArray(value)) {
30
+ // @ts-ignore
31
+ return value.map(function (_value) {
32
+ return _clone(_value);
33
+ });
34
+ }
35
+ // @ts-ignore
36
+ return Object.entries(value).reduce(function (cloned, _ref3) {
37
+ var _ref4 = _slicedToArray(_ref3, 2),
38
+ _key = _ref4[0],
39
+ _value = _ref4[1];
40
+ // @ts-ignore
41
+ cloned[_key] = _clone(_value);
42
+ return cloned;
43
+ }, {});
17
44
  };
18
45
 
19
- exports.clone = clone;
46
+ exports.clone = _clone;
@@ -3,4 +3,4 @@
3
3
  * in develop, there are many cases to clone a string/number/object/array
4
4
  * this util is planning to resolve it
5
5
  */
6
- export declare const clone: (value: unknown) => any;
6
+ export declare const clone: <T>(value: T) => T;
@@ -1,3 +1,4 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
1
2
  import { isArray } from '../is/is-array.mjs';
2
3
  import { isPrimitive } from '../is/is-primitive.mjs';
3
4
 
@@ -6,12 +7,38 @@ import { isPrimitive } from '../is/is-primitive.mjs';
6
7
  * in develop, there are many cases to clone a string/number/object/array
7
8
  * this util is planning to resolve it
8
9
  */
9
- var clone = function clone(value) {
10
+ var _clone = function clone(value) {
10
11
  if (isPrimitive(value)) return value;
11
- if (value instanceof Map) return new Map(value);
12
- if (value instanceof Set) return new Set(value);
13
- if (isArray(value)) return Array.from(value);
14
- return Object(value);
12
+ if (value instanceof Map) {
13
+ // @ts-ignore
14
+ return new Map(Array.from(value.entries()).map(function (_ref) {
15
+ var _ref2 = _slicedToArray(_ref, 2),
16
+ _key = _ref2[0],
17
+ _value = _ref2[1];
18
+ return [_key, _clone(_value)];
19
+ }));
20
+ }
21
+ if (value instanceof Set) {
22
+ // @ts-ignore
23
+ return new Set(Array.from(value.values()).map(function (_value) {
24
+ return _clone(_value);
25
+ }));
26
+ }
27
+ if (isArray(value)) {
28
+ // @ts-ignore
29
+ return value.map(function (_value) {
30
+ return _clone(_value);
31
+ });
32
+ }
33
+ // @ts-ignore
34
+ return Object.entries(value).reduce(function (cloned, _ref3) {
35
+ var _ref4 = _slicedToArray(_ref3, 2),
36
+ _key = _ref4[0],
37
+ _value = _ref4[1];
38
+ // @ts-ignore
39
+ cloned[_key] = _clone(_value);
40
+ return cloned;
41
+ }, {});
15
42
  };
16
43
 
17
- export { clone };
44
+ export { _clone as clone };
@@ -5,17 +5,12 @@ var isFunction = require('../is/is-function.cjs');
5
5
  var waitable = require('./waitable.cjs');
6
6
 
7
7
  var debounce = function debounce(debouncer, wait) {
8
- var isCallable = isFunction.isFunction(debouncer);
9
- var callback = isCallable ? debouncer : debouncer.callback;
10
- var pipe = isCallable ? function () {
11
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
- args[_key] = arguments[_key];
13
- }
14
- return args;
15
- } : debouncer.pipe;
8
+ var _isFunction = isFunction.isFunction(debouncer);
9
+ var callback = _isFunction ? debouncer : debouncer.callback;
10
+ // @ts-ignore
16
11
  var waiter = new waitable.Waitable({
17
12
  callback: callback,
18
- pipe: pipe,
13
+ pipe: _isFunction ? void 0 : debouncer.pipe,
19
14
  timer: rxjs.debounceTime(wait)
20
15
  });
21
16
  return {
@@ -16,8 +16,8 @@ export interface Debounced<T extends Callable> {
16
16
  */
17
17
  abort: () => void;
18
18
  }
19
- export type Debouncer<T extends Callable, R extends Array<unknown> = Parameters<T>> = {
20
- callback: (...args: R) => ReturnType<T>;
19
+ export type Debouncer<T extends Callable, R = unknown> = {
20
+ callback: (args: R) => ReturnType<T>;
21
21
  pipe: (...args: Parameters<T>) => R | Promise<R>;
22
22
  };
23
- export declare const debounce: <T extends Callable, R extends Array<unknown> = Parameters<T>>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
23
+ export declare const debounce: <T extends Callable, R = unknown>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
@@ -3,17 +3,12 @@ import { isFunction } from '../is/is-function.mjs';
3
3
  import { Waitable } from './waitable.mjs';
4
4
 
5
5
  var debounce = function debounce(debouncer, wait) {
6
- var isCallable = isFunction(debouncer);
7
- var callback = isCallable ? debouncer : debouncer.callback;
8
- var pipe = isCallable ? function () {
9
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
- args[_key] = arguments[_key];
11
- }
12
- return args;
13
- } : debouncer.pipe;
6
+ var _isFunction = isFunction(debouncer);
7
+ var callback = _isFunction ? debouncer : debouncer.callback;
8
+ // @ts-ignore
14
9
  var waiter = new Waitable({
15
10
  callback: callback,
16
- pipe: pipe,
11
+ pipe: _isFunction ? void 0 : debouncer.pipe,
17
12
  timer: debounceTime(wait)
18
13
  });
19
14
  return {
@@ -7,7 +7,10 @@ var toArray = require('./to-array.cjs');
7
7
  * first element of array
8
8
  */
9
9
  var first = function first(value) {
10
- return toArray.toArray(value).at(0);
10
+ // @ts-ignore
11
+ return toArray.toArray(value, {
12
+ separator: ""
13
+ }).at(0);
11
14
  };
12
15
 
13
16
  exports.first = first;
@@ -1,4 +1,4 @@
1
- import { type First } from "../types";
1
+ import { type First } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
4
  * first element of array
@@ -5,7 +5,10 @@ import { toArray } from './to-array.mjs';
5
5
  * first element of array
6
6
  */
7
7
  var first = function first(value) {
8
- return toArray(value).at(0);
8
+ // @ts-ignore
9
+ return toArray(value, {
10
+ separator: ""
11
+ }).at(0);
9
12
  };
10
13
 
11
14
  export { first };
@@ -7,7 +7,10 @@ var toArray = require('./to-array.cjs');
7
7
  * last element of array
8
8
  */
9
9
  var last = function last(value) {
10
- return toArray.toArray(value).at(-1);
10
+ // @ts-ignore
11
+ return toArray.toArray(value, {
12
+ separator: ""
13
+ }).at(-1);
11
14
  };
12
15
 
13
16
  exports.last = last;
@@ -1,4 +1,4 @@
1
- import { type Last } from "../types";
1
+ import { type Last } from "@aiszlab/relax/types";
2
2
  /**
3
3
  * @description
4
4
  * last element of array
@@ -5,7 +5,10 @@ import { toArray } from './to-array.mjs';
5
5
  * last element of array
6
6
  */
7
7
  var last = function last(value) {
8
- return toArray(value).at(-1);
8
+ // @ts-ignore
9
+ return toArray(value, {
10
+ separator: ""
11
+ }).at(-1);
9
12
  };
10
13
 
11
14
  export { last };
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
+ var isArray = require('../is/is-array.cjs');
5
+ var isFunction = require('../is/is-function.cjs');
6
+ var isPrimitive = require('../is/is-primitive.cjs');
7
+ var clone = require('./clone.cjs');
8
+ var unique = require('./unique.cjs');
9
+
10
+ var _merge2 = function _merge(previous, next) {
11
+ if (isPrimitive.isPrimitive(previous) || isPrimitive.isPrimitive(next) || isFunction.isFunction(previous) || isFunction.isFunction(next) || previous === next) {
12
+ return clone.clone(next);
13
+ }
14
+ var _previous = new Map(Object.entries(previous));
15
+ var _next = new Map(Object.entries(next));
16
+ var _uniqueKeys = unique.unique(_previous.keys(), _next.keys());
17
+ var merged = _uniqueKeys.reduce(function (_merged, _key) {
18
+ var _previousValue = _previous.get(_key);
19
+ var _nextValue = _next.get(_key);
20
+ if (!_next.has(_key)) {
21
+ _merged[_key] = clone.clone(_previousValue);
22
+ return _merged;
23
+ }
24
+ // deep merge child value
25
+ _merged[_key] = _merge2(_previousValue, _nextValue);
26
+ return _merged;
27
+ }, {});
28
+ // convert value type same as previous
29
+ // if `previous` is object, use merged object directly
30
+ if (!isArray.isArray(previous)) return merged;
31
+ // else `previous` is array, check next value type
32
+ // but length will be merged when next value is array
33
+ return Array.from(_objectSpread(_objectSpread({}, merged), {}, {
34
+ length: isArray.isArray(next) ? Object.keys(merged).length : previous.length
35
+ }));
36
+ };
37
+ /**
38
+ * @description
39
+ * deep merge api
40
+ * use unique values to avoid duplicate
41
+ */
42
+ var merge = function merge() {
43
+ for (var _len = arguments.length, values = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
44
+ values[_key2] = arguments[_key2];
45
+ }
46
+ // @ts-ignore
47
+ return unique.unique(values).reduce(function (_merged, _value) {
48
+ // @ts-ignore
49
+ return _merge2(_merged, _value !== null && _value !== void 0 ? _value : {});
50
+ }, null);
51
+ };
52
+
53
+ exports.merge = merge;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @description
3
+ * deep merge api
4
+ * use unique values to avoid duplicate
5
+ */
6
+ declare const merge: <T>(values_0: T, ...values: unknown[]) => T;
7
+ export { merge };
@@ -0,0 +1,51 @@
1
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
+ import { isArray } from '../is/is-array.mjs';
3
+ import { isFunction } from '../is/is-function.mjs';
4
+ import { isPrimitive } from '../is/is-primitive.mjs';
5
+ import { clone as _clone } from './clone.mjs';
6
+ import { unique } from './unique.mjs';
7
+
8
+ var _merge2 = function _merge(previous, next) {
9
+ if (isPrimitive(previous) || isPrimitive(next) || isFunction(previous) || isFunction(next) || previous === next) {
10
+ return _clone(next);
11
+ }
12
+ var _previous = new Map(Object.entries(previous));
13
+ var _next = new Map(Object.entries(next));
14
+ var _uniqueKeys = unique(_previous.keys(), _next.keys());
15
+ var merged = _uniqueKeys.reduce(function (_merged, _key) {
16
+ var _previousValue = _previous.get(_key);
17
+ var _nextValue = _next.get(_key);
18
+ if (!_next.has(_key)) {
19
+ _merged[_key] = _clone(_previousValue);
20
+ return _merged;
21
+ }
22
+ // deep merge child value
23
+ _merged[_key] = _merge2(_previousValue, _nextValue);
24
+ return _merged;
25
+ }, {});
26
+ // convert value type same as previous
27
+ // if `previous` is object, use merged object directly
28
+ if (!isArray(previous)) return merged;
29
+ // else `previous` is array, check next value type
30
+ // but length will be merged when next value is array
31
+ return Array.from(_objectSpread(_objectSpread({}, merged), {}, {
32
+ length: isArray(next) ? Object.keys(merged).length : previous.length
33
+ }));
34
+ };
35
+ /**
36
+ * @description
37
+ * deep merge api
38
+ * use unique values to avoid duplicate
39
+ */
40
+ var merge = function merge() {
41
+ for (var _len = arguments.length, values = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
42
+ values[_key2] = arguments[_key2];
43
+ }
44
+ // @ts-ignore
45
+ return unique(values).reduce(function (_merged, _value) {
46
+ // @ts-ignore
47
+ return _merge2(_merged, _value !== null && _value !== void 0 ? _value : {});
48
+ }, null);
49
+ };
50
+
51
+ export { merge };
@@ -5,17 +5,12 @@ var isFunction = require('../is/is-function.cjs');
5
5
  var rxjs = require('rxjs');
6
6
 
7
7
  var throttle = function throttle(throttler, wait) {
8
- var isCallable = isFunction.isFunction(throttler);
9
- var callback = isCallable ? throttler : throttler.callback;
10
- var pipe = isCallable ? function () {
11
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
- args[_key] = arguments[_key];
13
- }
14
- return args;
15
- } : throttler.pipe;
8
+ var _isFunction = isFunction.isFunction(throttler);
9
+ var callback = _isFunction ? throttler : throttler.callback;
10
+ // @ts-ignore
16
11
  var waiter = new waitable.Waitable({
17
12
  callback: callback,
18
- pipe: pipe,
13
+ pipe: _isFunction ? void 0 : throttler.pipe,
19
14
  timer: rxjs.throttleTime(wait)
20
15
  });
21
16
  return {
@@ -1,5 +1,5 @@
1
1
  import type { Debounced, Debouncer } from "./debounce";
2
2
  import { type Callable } from "../hooks/use-event";
3
3
  export type Throttled<T extends Callable> = Debounced<T>;
4
- export type Throttler<T extends Callable, R extends Array<unknown> = Parameters<T>> = Debouncer<T, R>;
5
- export declare const throttle: <T extends Callable, R extends Array<unknown> = Parameters<T>>(throttler: Throttler<T, R> | T, wait: number) => Throttled<T>;
4
+ export type Throttler<T extends Callable, R = unknown> = Debouncer<T, R>;
5
+ export declare const throttle: <T extends Callable, R = unknown>(throttler: Throttler<T, R> | T, wait: number) => Throttled<T>;
@@ -3,17 +3,12 @@ import { isFunction } from '../is/is-function.mjs';
3
3
  import { throttleTime } from 'rxjs';
4
4
 
5
5
  var throttle = function throttle(throttler, wait) {
6
- var isCallable = isFunction(throttler);
7
- var callback = isCallable ? throttler : throttler.callback;
8
- var pipe = isCallable ? function () {
9
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
10
- args[_key] = arguments[_key];
11
- }
12
- return args;
13
- } : throttler.pipe;
6
+ var _isFunction = isFunction(throttler);
7
+ var callback = _isFunction ? throttler : throttler.callback;
8
+ // @ts-ignore
14
9
  var waiter = new Waitable({
15
10
  callback: callback,
16
- pipe: pipe,
11
+ pipe: _isFunction ? void 0 : throttler.pipe,
17
12
  timer: throttleTime(wait)
18
13
  });
19
14
  return {
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var unique = require('./unique.cjs');
4
+
5
+ /**
6
+ * @description
7
+ * unique by
8
+ */
9
+ var uniqueBy = function uniqueBy(value, pipe) {
10
+ if (!pipe) {
11
+ return unique.unique(value);
12
+ }
13
+ return Array.from(Array.from(value).reduce(function (prev, _value) {
14
+ var _key = pipe(_value);
15
+ if (!prev.has(_key)) {
16
+ prev.set(pipe(_value), _value);
17
+ }
18
+ return prev;
19
+ }, new Map()).values());
20
+ };
21
+
22
+ exports.uniqueBy = uniqueBy;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * unique by
4
+ */
5
+ export declare const uniqueBy: <T, P>(value: Iterable<T>, pipe?: (item: T) => P) => any[];
@@ -0,0 +1,20 @@
1
+ import { unique } from './unique.mjs';
2
+
3
+ /**
4
+ * @description
5
+ * unique by
6
+ */
7
+ var uniqueBy = function uniqueBy(value, pipe) {
8
+ if (!pipe) {
9
+ return unique(value);
10
+ }
11
+ return Array.from(Array.from(value).reduce(function (prev, _value) {
12
+ var _key = pipe(_value);
13
+ if (!prev.has(_key)) {
14
+ prev.set(pipe(_value), _value);
15
+ }
16
+ return prev;
17
+ }, new Map()).values());
18
+ };
19
+
20
+ export { uniqueBy };
@@ -4,16 +4,13 @@
4
4
  * @description
5
5
  * unique
6
6
  */
7
- var unique = function unique(value) {
8
- return Array.from(new Set(value));
9
- };
10
- /**
11
- * @description
12
- * unique by
13
- */
14
- var uniqueBy = function uniqueBy(value, callback) {
15
- return Array.from(new Set(Array.from(value).map(callback)));
7
+ var unique = function unique() {
8
+ for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ values[_key] = arguments[_key];
10
+ }
11
+ return Array.from(values.reduce(function (unionize, _value) {
12
+ return unionize.union(new Set(_value));
13
+ }, new Set()));
16
14
  };
17
15
 
18
16
  exports.unique = unique;
19
- exports.uniqueBy = uniqueBy;
@@ -2,9 +2,4 @@
2
2
  * @description
3
3
  * unique
4
4
  */
5
- export declare const unique: <T = unknown>(value: Iterable<T>) => T[];
6
- /**
7
- * @description
8
- * unique by
9
- */
10
- export declare const uniqueBy: <T, P>(value: Iterable<T>, callback: (item: T) => P) => P[];
5
+ export declare const unique: <T = unknown>(...values: Array<Iterable<T>>) => T[];
@@ -2,15 +2,13 @@
2
2
  * @description
3
3
  * unique
4
4
  */
5
- var unique = function unique(value) {
6
- return Array.from(new Set(value));
7
- };
8
- /**
9
- * @description
10
- * unique by
11
- */
12
- var uniqueBy = function uniqueBy(value, callback) {
13
- return Array.from(new Set(Array.from(value).map(callback)));
5
+ var unique = function unique() {
6
+ for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
7
+ values[_key] = arguments[_key];
8
+ }
9
+ return Array.from(values.reduce(function (unionize, _value) {
10
+ return unionize.union(new Set(_value));
11
+ }, new Set()));
14
12
  };
15
13
 
16
- export { unique, uniqueBy };
14
+ export { unique };
@@ -33,8 +33,8 @@ var Waitable = /*#__PURE__*/function () {
33
33
  _classPrivateFieldInitSpec(this, _callback, void 0);
34
34
  _classPrivateFieldSet(_cook$, this, null);
35
35
  _classPrivateFieldSet(_waiter$, this, null);
36
- _classPrivateFieldSet(_pipe, this, props.pipe);
37
36
  _classPrivateFieldSet(_timer, this, props.timer);
37
+ _classPrivateFieldSet(_pipe, this, props.pipe);
38
38
  _classPrivateFieldSet(_callback, this, props.callback);
39
39
  _assertClassBrand(_Waitable_brand, this, _use).call(this);
40
40
  }
@@ -88,11 +88,20 @@ function _use() {
88
88
  _classPrivateFieldSet(_waiter$, _this, subscriber);
89
89
  }).pipe(_classPrivateFieldGet(_timer, this), rxjs.switchMap(function (args) {
90
90
  var _classPrivateFieldGet6;
91
+ if (!_classPrivateFieldGet(_pipe, _this)) {
92
+ return rxjs.of(args);
93
+ }
91
94
  var piped = (_classPrivateFieldGet6 = _classPrivateFieldGet(_pipe, _this)).call.apply(_classPrivateFieldGet6, [_this].concat(_toConsumableArray(args)));
92
95
  return isThenable.isThenable(piped) ? rxjs.from(piped) : rxjs.of(piped);
93
96
  })).subscribe(function (args) {
94
- var _classPrivateFieldGet7;
95
- (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
97
+ if (!_classPrivateFieldGet(_pipe, _this)) {
98
+ var _classPrivateFieldGet7;
99
+ // @ts-ignore
100
+ (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)).call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
101
+ } else {
102
+ // @ts-ignore
103
+ _classPrivateFieldGet(_callback, _this).call(_this, args);
104
+ }
96
105
  }));
97
106
  }
98
107
 
@@ -1,15 +1,21 @@
1
1
  import { type MonoTypeOperatorFunction } from "rxjs";
2
- interface Props<T extends Array<unknown> = Array<unknown>, R extends Array<unknown> = T> {
2
+ interface PropsWithoutPipe<T extends Array<unknown> = Array<unknown>> {
3
3
  callback: (...args: T) => unknown;
4
- pipe: (...args: R) => T | Promise<T>;
5
- timer: MonoTypeOperatorFunction<R>;
4
+ pipe: undefined;
5
+ timer: MonoTypeOperatorFunction<T>;
6
6
  }
7
+ interface PropsWithPipe<T extends Array<unknown> = Array<unknown>, R = unknown> {
8
+ callback: (value: R) => unknown;
9
+ pipe: (...args: T) => R | Promise<R>;
10
+ timer: MonoTypeOperatorFunction<T>;
11
+ }
12
+ type Props<T extends Array<unknown> = Array<unknown>, R = unknown> = PropsWithoutPipe<T> | PropsWithPipe<T, R>;
7
13
  /**
8
14
  * @description
9
15
  * waitable instance
10
16
  * for debounce...
11
17
  */
12
- export declare class Waitable<T extends Array<unknown>, R extends Array<unknown> = T> {
18
+ export declare class Waitable<T extends Array<unknown>, R = unknown> {
13
19
  #private;
14
20
  constructor(props: Props<T, R>);
15
21
  /**
@@ -31,6 +37,6 @@ export declare class Waitable<T extends Array<unknown>, R extends Array<unknown>
31
37
  * @description
32
38
  * trigger value
33
39
  */
34
- next(...args: R): void;
40
+ next(...args: T): void;
35
41
  }
36
42
  export {};
@@ -6,7 +6,7 @@ import _classPrivateFieldInitSpec from '@babel/runtime/helpers/classPrivateField
6
6
  import _classPrivateFieldGet from '@babel/runtime/helpers/classPrivateFieldGet2';
7
7
  import _assertClassBrand from '@babel/runtime/helpers/assertClassBrand';
8
8
  import _classPrivateFieldSet from '@babel/runtime/helpers/classPrivateFieldSet2';
9
- import { Observable, switchMap, from, of } from 'rxjs';
9
+ import { Observable, switchMap, of, from } from 'rxjs';
10
10
  import { isThenable } from '../is/is-thenable.mjs';
11
11
 
12
12
  /**
@@ -31,8 +31,8 @@ var Waitable = /*#__PURE__*/function () {
31
31
  _classPrivateFieldInitSpec(this, _callback, void 0);
32
32
  _classPrivateFieldSet(_cook$, this, null);
33
33
  _classPrivateFieldSet(_waiter$, this, null);
34
- _classPrivateFieldSet(_pipe, this, props.pipe);
35
34
  _classPrivateFieldSet(_timer, this, props.timer);
35
+ _classPrivateFieldSet(_pipe, this, props.pipe);
36
36
  _classPrivateFieldSet(_callback, this, props.callback);
37
37
  _assertClassBrand(_Waitable_brand, this, _use).call(this);
38
38
  }
@@ -86,11 +86,20 @@ function _use() {
86
86
  _classPrivateFieldSet(_waiter$, _this, subscriber);
87
87
  }).pipe(_classPrivateFieldGet(_timer, this), switchMap(function (args) {
88
88
  var _classPrivateFieldGet6;
89
+ if (!_classPrivateFieldGet(_pipe, _this)) {
90
+ return of(args);
91
+ }
89
92
  var piped = (_classPrivateFieldGet6 = _classPrivateFieldGet(_pipe, _this)).call.apply(_classPrivateFieldGet6, [_this].concat(_toConsumableArray(args)));
90
93
  return isThenable(piped) ? from(piped) : of(piped);
91
94
  })).subscribe(function (args) {
92
- var _classPrivateFieldGet7;
93
- (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
95
+ if (!_classPrivateFieldGet(_pipe, _this)) {
96
+ var _classPrivateFieldGet7;
97
+ // @ts-ignore
98
+ (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)).call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
99
+ } else {
100
+ // @ts-ignore
101
+ _classPrivateFieldGet(_callback, _this).call(_this, args);
102
+ }
94
103
  }));
95
104
  }
96
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.3.15",
3
+ "version": "1.3.17",
4
4
  "description": "react utils collection",
5
5
  "exports": {
6
6
  ".": {
@@ -24,6 +24,13 @@
24
24
  "import": "./dist/react/index.mjs",
25
25
  "default": "./dist/react/index.mjs"
26
26
  },
27
+ "./path": {
28
+ "types": "./dist/path/index.d.ts",
29
+ "node": "./dist/path/index.cjs",
30
+ "require": "./dist/path/index.cjs",
31
+ "import": "./dist/path/index.mjs",
32
+ "default": "./dist/path/index.mjs"
33
+ },
27
34
  "./types": "./dist/types/index.d.ts"
28
35
  },
29
36
  "scripts": {
@@ -32,6 +39,7 @@
32
39
  "clean:build": "rm -rf dist",
33
40
  "prepublishOnly": "npm run clean:build && npm run build",
34
41
  "test": "jest",
42
+ "test:coverage": "jest --coverage",
35
43
  "publish:npm": "npm publish"
36
44
  },
37
45
  "dependencies": {
@@ -50,6 +58,7 @@
50
58
  "@rollup/plugin-node-resolve": "^15.2.3",
51
59
  "@rollup/plugin-typescript": "^11.1.6",
52
60
  "@testing-library/react": "^16.0.1",
61
+ "@types/babel__core": "^7.20.5",
53
62
  "@types/react": "^18.3.6",
54
63
  "@types/react-dom": "^18.3.0",
55
64
  "@types/react-is": "^18.3.0",