@aiszlab/relax 1.4.4 → 1.4.6

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 (65) hide show
  1. package/dist/hooks/use-debounce-callback.cjs +2 -17
  2. package/dist/hooks/use-debounce-callback.d.ts +4 -2
  3. package/dist/hooks/use-debounce-callback.mjs +2 -17
  4. package/dist/hooks/use-drag.d.ts +49 -0
  5. package/dist/hooks/use-event.cjs +0 -1
  6. package/dist/hooks/use-event.d.ts +2 -2
  7. package/dist/hooks/use-event.mjs +0 -1
  8. package/dist/hooks/use-infinite-scroll.cjs +40 -36
  9. package/dist/hooks/use-infinite-scroll.d.ts +3 -3
  10. package/dist/hooks/use-infinite-scroll.mjs +40 -36
  11. package/dist/hooks/use-is-mounted.d.ts +2 -2
  12. package/dist/hooks/use-media-query.cjs +9 -13
  13. package/dist/hooks/use-media-query.mjs +10 -14
  14. package/dist/hooks/use-raf.d.ts +2 -1
  15. package/dist/hooks/use-throttle-callback.cjs +2 -17
  16. package/dist/hooks/use-throttle-callback.d.ts +4 -2
  17. package/dist/hooks/use-throttle-callback.mjs +2 -17
  18. package/dist/hooks/use-timeout.d.ts +2 -1
  19. package/dist/hooks/use-update-state.d.ts +12 -0
  20. package/dist/is/is-html-element.cjs +0 -1
  21. package/dist/is/is-html-element.mjs +0 -1
  22. package/dist/is/is-mobile.cjs +2 -1
  23. package/dist/is/is-mobile.mjs +2 -1
  24. package/dist/is/is-overflow.cjs +0 -1
  25. package/dist/is/is-overflow.mjs +0 -1
  26. package/dist/types/any-function.d.ts +1 -0
  27. package/dist/types/first.d.ts +1 -1
  28. package/dist/types/index.d.ts +1 -0
  29. package/dist/types/last.d.ts +1 -1
  30. package/dist/types/partial-in.d.ts +5 -0
  31. package/dist/utils/clone.cjs +0 -1
  32. package/dist/utils/clone.mjs +0 -1
  33. package/dist/utils/debounce.cjs +0 -1
  34. package/dist/utils/debounce.d.ts +4 -4
  35. package/dist/utils/debounce.mjs +0 -1
  36. package/dist/utils/exclude.cjs +0 -1
  37. package/dist/utils/exclude.mjs +0 -1
  38. package/dist/utils/first.cjs +0 -1
  39. package/dist/utils/first.mjs +0 -1
  40. package/dist/utils/last.cjs +0 -1
  41. package/dist/utils/last.mjs +0 -1
  42. package/dist/utils/max.cjs +4 -10
  43. package/dist/utils/max.d.ts +3 -1
  44. package/dist/utils/max.mjs +4 -10
  45. package/dist/utils/merge.cjs +0 -2
  46. package/dist/utils/merge.mjs +0 -2
  47. package/dist/utils/min.cjs +6 -12
  48. package/dist/utils/min.d.ts +3 -1
  49. package/dist/utils/min.mjs +6 -12
  50. package/dist/utils/replace.cjs +16 -15
  51. package/dist/utils/replace.d.ts +14 -13
  52. package/dist/utils/replace.mjs +16 -15
  53. package/dist/utils/set-style.cjs +3 -5
  54. package/dist/utils/set-style.d.ts +1 -1
  55. package/dist/utils/set-style.mjs +3 -5
  56. package/dist/utils/throttle.cjs +0 -1
  57. package/dist/utils/throttle.d.ts +4 -4
  58. package/dist/utils/throttle.mjs +0 -1
  59. package/dist/utils/to-function.cjs +1 -2
  60. package/dist/utils/to-function.d.ts +4 -1
  61. package/dist/utils/to-function.mjs +1 -2
  62. package/dist/utils/waitable.cjs +7 -6
  63. package/dist/utils/waitable.d.ts +4 -4
  64. package/dist/utils/waitable.mjs +7 -6
  65. package/package.json +4 -4
@@ -8,7 +8,8 @@ var isMobile = function isMobile() {
8
8
  if (typeof navigator === "undefined" || typeof window === "undefined") {
9
9
  return false;
10
10
  }
11
- var agent = navigator.userAgent || navigator.vendor || window.opera;
11
+ var agent = navigator.userAgent || navigator.vendor;
12
+ if (!agent) return false;
12
13
  return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substring(0, 4));
13
14
  };
14
15
 
@@ -6,7 +6,8 @@ var isMobile = function isMobile() {
6
6
  if (typeof navigator === "undefined" || typeof window === "undefined") {
7
7
  return false;
8
8
  }
9
- var agent = navigator.userAgent || navigator.vendor || window.opera;
9
+ var agent = navigator.userAgent || navigator.vendor;
10
+ if (!agent) return false;
10
11
  return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substring(0, 4));
11
12
  };
12
13
 
@@ -9,7 +9,6 @@ function isOverflow() {
9
9
  if (element === document.body) {
10
10
  return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
11
11
  }
12
- // not body
13
12
  return element.scrollHeight > element.clientHeight;
14
13
  }
15
14
 
@@ -7,7 +7,6 @@ function isOverflow() {
7
7
  if (element === document.body) {
8
8
  return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
9
9
  }
10
- // not body
11
10
  return element.scrollHeight > element.clientHeight;
12
11
  }
13
12
 
@@ -0,0 +1 @@
1
+ export type AnyFunction = (...args: any) => any;
@@ -1 +1 @@
1
- export type First<T, R = undefined> = T extends string ? string : 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 : T extends Array<infer S> ? S | undefined : R;
@@ -8,3 +8,4 @@ export type { Last } from "./last";
8
8
  export type { State, StateGetter } from "./state";
9
9
  export type { Arrayable } from "./arrayable";
10
10
  export type { RequiredTo } from "./required-to";
11
+ export type { AnyFunction } from "./any-function";
@@ -1 +1 @@
1
- export type Last<T, R = undefined> = T extends [...Array<unknown>, infer D] ? D : R;
1
+ export type Last<T, R = undefined> = T extends [...Array<unknown>, infer D] ? D : T extends Array<infer S> ? S | undefined : R;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * partial some fields
4
+ */
5
+ export type PartialIn<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
@@ -35,7 +35,6 @@ var _clone = function clone(value) {
35
35
  return _clone(_value);
36
36
  });
37
37
  }
38
- // @ts-ignore
39
38
  return Object.entries(value).reduce(function (cloned, _ref3) {
40
39
  var _ref4 = _slicedToArray(_ref3, 2),
41
40
  _key = _ref4[0],
@@ -33,7 +33,6 @@ var _clone = function clone(value) {
33
33
  return _clone(_value);
34
34
  });
35
35
  }
36
- // @ts-ignore
37
36
  return Object.entries(value).reduce(function (cloned, _ref3) {
38
37
  var _ref4 = _slicedToArray(_ref3, 2),
39
38
  _key = _ref4[0],
@@ -7,7 +7,6 @@ var waitable = require('./waitable.cjs');
7
7
  var debounce = function debounce(debouncer, wait) {
8
8
  var _isFunction = isFunction.isFunction(debouncer);
9
9
  var callback = _isFunction ? debouncer : debouncer.callback;
10
- // @ts-ignore
11
10
  var waiter = new waitable.Waitable({
12
11
  callback: callback,
13
12
  pipe: _isFunction ? void 0 : debouncer.pipe,
@@ -1,5 +1,5 @@
1
- import { type Callable } from "../hooks/use-event";
2
- export interface Debounced<T extends Callable> {
1
+ import type { AnyFunction } from "@aiszlab/relax/types";
2
+ export interface Debounced<T extends AnyFunction> {
3
3
  /**
4
4
  * @description
5
5
  * value trigger
@@ -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 = unknown> = {
19
+ export type Debouncer<T extends AnyFunction, R> = {
20
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 = unknown>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
23
+ export declare const debounce: <T extends AnyFunction, R>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
@@ -5,7 +5,6 @@ import { Waitable } from './waitable.mjs';
5
5
  var debounce = function debounce(debouncer, wait) {
6
6
  var _isFunction = isFunction(debouncer);
7
7
  var callback = _isFunction ? debouncer : debouncer.callback;
8
- // @ts-ignore
9
8
  var waiter = new Waitable({
10
9
  callback: callback,
11
10
  pipe: _isFunction ? void 0 : debouncer.pipe,
@@ -11,7 +11,6 @@
11
11
  */
12
12
  var exclude = function exclude(value, _excludeBy) {
13
13
  var excludeBy = new Set(_excludeBy);
14
- // @ts-ignore
15
14
  return value.filter(function (item) {
16
15
  return !excludeBy.has(item);
17
16
  });
@@ -9,7 +9,6 @@
9
9
  */
10
10
  var exclude = function exclude(value, _excludeBy) {
11
11
  var excludeBy = new Set(_excludeBy);
12
- // @ts-ignore
13
12
  return value.filter(function (item) {
14
13
  return !excludeBy.has(item);
15
14
  });
@@ -7,7 +7,6 @@ var toArray = require('./to-array.cjs');
7
7
  * first element of array
8
8
  */
9
9
  var first = function first(value) {
10
- // @ts-ignore
11
10
  return toArray.toArray(value, {
12
11
  separator: ""
13
12
  }).at(0);
@@ -5,7 +5,6 @@ import { toArray } from './to-array.mjs';
5
5
  * first element of array
6
6
  */
7
7
  var first = function first(value) {
8
- // @ts-ignore
9
8
  return toArray(value, {
10
9
  separator: ""
11
10
  }).at(0);
@@ -7,7 +7,6 @@ var toArray = require('./to-array.cjs');
7
7
  * last element of array
8
8
  */
9
9
  var last = function last(value) {
10
- // @ts-ignore
11
10
  return toArray.toArray(value, {
12
11
  separator: ""
13
12
  }).at(-1);
@@ -5,7 +5,6 @@ import { toArray } from './to-array.mjs';
5
5
  * last element of array
6
6
  */
7
7
  var last = function last(value) {
8
- // @ts-ignore
9
8
  return toArray(value, {
10
9
  separator: ""
11
10
  }).at(-1);
@@ -2,16 +2,10 @@
2
2
 
3
3
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
4
 
5
- /**
6
- * @description
7
- * max
8
- */
9
- var max = function max() {
10
- for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
11
- args[_key2] = arguments[_key2];
5
+ function max(values, pipe) {
6
+ if (!pipe) {
7
+ return Math.max.apply(Math, _toConsumableArray(values));
12
8
  }
13
- var values = args[0],
14
- pipe = args[1];
15
9
  var _values = values.reduce(function (prev, _value) {
16
10
  var _key = pipe(_value);
17
11
  if (!prev.has(_key)) {
@@ -21,6 +15,6 @@ var max = function max() {
21
15
  }, new Map());
22
16
  var _max = Math.max.apply(Math, _toConsumableArray(_values.keys()));
23
17
  return _values.get(_max);
24
- };
18
+ }
25
19
 
26
20
  exports.max = max;
@@ -2,4 +2,6 @@
2
2
  * @description
3
3
  * max
4
4
  */
5
- export declare const max: <T>(values: T[], pipe: (value: T) => number) => T;
5
+ declare function max(values: number[]): number;
6
+ declare function max<T>(values: T[], pipe: (value: T) => number): T;
7
+ export { max };
@@ -1,15 +1,9 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
2
 
3
- /**
4
- * @description
5
- * max
6
- */
7
- var max = function max() {
8
- for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
9
- args[_key2] = arguments[_key2];
3
+ function max(values, pipe) {
4
+ if (!pipe) {
5
+ return Math.max.apply(Math, _toConsumableArray(values));
10
6
  }
11
- var values = args[0],
12
- pipe = args[1];
13
7
  var _values = values.reduce(function (prev, _value) {
14
8
  var _key = pipe(_value);
15
9
  if (!prev.has(_key)) {
@@ -19,6 +13,6 @@ var max = function max() {
19
13
  }, new Map());
20
14
  var _max = Math.max.apply(Math, _toConsumableArray(_values.keys()));
21
15
  return _values.get(_max);
22
- };
16
+ }
23
17
 
24
18
  export { max };
@@ -43,9 +43,7 @@ var merge = function merge() {
43
43
  for (var _len = arguments.length, values = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
44
44
  values[_key2] = arguments[_key2];
45
45
  }
46
- // @ts-ignore
47
46
  return unique.unique(values).reduce(function (_merged, _value) {
48
- // @ts-ignore
49
47
  return _merge2(_merged, _value !== null && _value !== void 0 ? _value : {});
50
48
  }, null);
51
49
  };
@@ -41,9 +41,7 @@ var merge = function merge() {
41
41
  for (var _len = arguments.length, values = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
42
42
  values[_key2] = arguments[_key2];
43
43
  }
44
- // @ts-ignore
45
44
  return unique(values).reduce(function (_merged, _value) {
46
- // @ts-ignore
47
45
  return _merge2(_merged, _value !== null && _value !== void 0 ? _value : {});
48
46
  }, null);
49
47
  };
@@ -2,16 +2,10 @@
2
2
 
3
3
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
4
 
5
- /**
6
- * @description
7
- * min
8
- */
9
- var min = function min() {
10
- for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
11
- args[_key2] = arguments[_key2];
5
+ function min(values, pipe) {
6
+ if (!pipe) {
7
+ return Math.min.apply(Math, _toConsumableArray(values));
12
8
  }
13
- var values = args[0],
14
- pipe = args[1];
15
9
  var _values = values.reduce(function (prev, _value) {
16
10
  var _key = pipe(_value);
17
11
  if (!prev.has(_key)) {
@@ -19,8 +13,8 @@ var min = function min() {
19
13
  }
20
14
  return prev;
21
15
  }, new Map());
22
- var _max = Math.min.apply(Math, _toConsumableArray(_values.keys()));
23
- return _values.get(_max);
24
- };
16
+ var _min = Math.min.apply(Math, _toConsumableArray(_values.keys()));
17
+ return _values.get(_min);
18
+ }
25
19
 
26
20
  exports.min = min;
@@ -2,4 +2,6 @@
2
2
  * @description
3
3
  * min
4
4
  */
5
- export declare const min: <T>(values: T[], pipe: (value: T) => number) => T;
5
+ declare function min(values: number[]): number;
6
+ declare function min<T>(values: T[], pipe: (value: T) => number): T;
7
+ export { min };
@@ -1,15 +1,9 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
2
 
3
- /**
4
- * @description
5
- * min
6
- */
7
- var min = function min() {
8
- for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
9
- args[_key2] = arguments[_key2];
3
+ function min(values, pipe) {
4
+ if (!pipe) {
5
+ return Math.min.apply(Math, _toConsumableArray(values));
10
6
  }
11
- var values = args[0],
12
- pipe = args[1];
13
7
  var _values = values.reduce(function (prev, _value) {
14
8
  var _key = pipe(_value);
15
9
  if (!prev.has(_key)) {
@@ -17,8 +11,8 @@ var min = function min() {
17
11
  }
18
12
  return prev;
19
13
  }, new Map());
20
- var _max = Math.min.apply(Math, _toConsumableArray(_values.keys()));
21
- return _values.get(_max);
22
- };
14
+ var _min = Math.min.apply(Math, _toConsumableArray(_values.keys()));
15
+ return _values.get(_min);
16
+ }
23
17
 
24
18
  export { min };
@@ -1,22 +1,23 @@
1
1
  'use strict';
2
2
 
3
3
  var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
- var isArray = require('../is/is-array.cjs');
4
+ var isString = require('../is/is-string.cjs');
5
+ var toArray = require('./to-array.cjs');
5
6
 
6
- /**
7
- * @description
8
- * comman replace
9
- * usable for `string`, `array`
10
- */
11
- var replace = function replace(value, options) {
12
- if (isArray.isArray(value)) {
13
- var index = options.index,
14
- _replaceValue = options.replaceValue;
15
- return [].concat(_toConsumableArray(value.slice(0, index)), [_replaceValue], _toConsumableArray(value.slice(index + 1)));
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];
16
10
  }
17
- var replaceValue = options.replaceValue,
18
- searchValue = options.searchValue;
19
- return value.replace(searchValue, replaceValue);
20
- };
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
+ }
21
22
 
22
23
  exports.replace = replace;
@@ -1,16 +1,17 @@
1
- type ReplaceArrayOptions<R> = {
2
- index: number;
3
- replaceValue: R;
4
- };
5
- type ReplaceStringOptions = {
6
- searchValue: string;
7
- replaceValue: string;
8
- };
9
- type ReplaceOptions<T> = T extends string ? ReplaceStringOptions : T extends Array<infer R> ? ReplaceArrayOptions<R> : never;
1
+ type StringReplacing = [searchValue: string, incoming: string];
2
+ type ArrayReplacing<T> = [incoming: Array<T> | T, start: number, end?: number];
10
3
  /**
11
4
  * @description
12
- * comman replace
13
- * usable for `string`, `array`
5
+ * string replace.
6
+ * it is an easy way to replace string.
7
+ * wrapper for `String.prototype.replace`.
14
8
  */
15
- export declare const replace: <T extends string | R[], R>(value: T, options: ReplaceOptions<T>) => T;
16
- export {};
9
+ declare function replace(value: string, ...args: StringReplacing): string;
10
+ /**
11
+ * @description
12
+ * replace array.
13
+ * `value`, `incoming` should be array.
14
+ * [start, end)
15
+ */
16
+ declare function replace<T>(value: Array<T>, ...args: ArrayReplacing<T>): Array<T>;
17
+ export { replace };
@@ -1,20 +1,21 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
- import { isArray } from '../is/is-array.mjs';
2
+ import { isString } from '../is/is-string.mjs';
3
+ import { toArray } from './to-array.mjs';
3
4
 
4
- /**
5
- * @description
6
- * comman replace
7
- * usable for `string`, `array`
8
- */
9
- var replace = function replace(value, options) {
10
- if (isArray(value)) {
11
- var index = options.index,
12
- _replaceValue = options.replaceValue;
13
- return [].concat(_toConsumableArray(value.slice(0, index)), [_replaceValue], _toConsumableArray(value.slice(index + 1)));
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];
14
8
  }
15
- var replaceValue = options.replaceValue,
16
- searchValue = options.searchValue;
17
- return value.replace(searchValue, replaceValue);
18
- };
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
+ }
19
20
 
20
21
  export { replace };
@@ -6,16 +6,14 @@ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
6
  * @description
7
7
  * set inline style util
8
8
  */
9
- var setStyle = function setStyle(target, styles) {
9
+ var setStyle = function setStyle(element, styles) {
10
10
  if (!styles) return {};
11
11
  return Object.entries(styles).reduce(function (prev, _ref) {
12
12
  var _ref2 = _slicedToArray(_ref, 2),
13
13
  key = _ref2[0],
14
14
  value = _ref2[1];
15
- // @ts-ignore
16
- prev[key] = target.style[key];
17
- // @ts-ignore
18
- target.style[key] = value;
15
+ prev[key] = element.style[key];
16
+ element.style[key] = value;
19
17
  return prev;
20
18
  }, {});
21
19
  };
@@ -3,4 +3,4 @@ import type { Voidable } from "@aiszlab/relax/types";
3
3
  * @description
4
4
  * set inline style util
5
5
  */
6
- export declare const setStyle: (target: HTMLElement, styles: Voidable<Partial<CSSStyleDeclaration>>) => Partial<CSSStyleDeclaration>;
6
+ export declare const setStyle: (element: HTMLElement, styles: Voidable<Partial<CSSStyleDeclaration>>) => Partial<CSSStyleDeclaration>;
@@ -4,16 +4,14 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
4
  * @description
5
5
  * set inline style util
6
6
  */
7
- var setStyle = function setStyle(target, styles) {
7
+ var setStyle = function setStyle(element, styles) {
8
8
  if (!styles) return {};
9
9
  return Object.entries(styles).reduce(function (prev, _ref) {
10
10
  var _ref2 = _slicedToArray(_ref, 2),
11
11
  key = _ref2[0],
12
12
  value = _ref2[1];
13
- // @ts-ignore
14
- prev[key] = target.style[key];
15
- // @ts-ignore
16
- target.style[key] = value;
13
+ prev[key] = element.style[key];
14
+ element.style[key] = value;
17
15
  return prev;
18
16
  }, {});
19
17
  };
@@ -7,7 +7,6 @@ var rxjs = require('rxjs');
7
7
  var throttle = function throttle(throttler, wait) {
8
8
  var _isFunction = isFunction.isFunction(throttler);
9
9
  var callback = _isFunction ? throttler : throttler.callback;
10
- // @ts-ignore
11
10
  var waiter = new waitable.Waitable({
12
11
  callback: callback,
13
12
  pipe: _isFunction ? void 0 : throttler.pipe,
@@ -1,5 +1,5 @@
1
1
  import type { Debounced, Debouncer } from "./debounce";
2
- import { type Callable } from "../hooks/use-event";
3
- export type Throttled<T extends Callable> = Debounced<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>;
2
+ import type { AnyFunction } from "@aiszlab/relax/types";
3
+ export type Throttled<T extends AnyFunction> = Debounced<T>;
4
+ export type Throttler<T extends AnyFunction, R = unknown> = Debouncer<T, R>;
5
+ export declare const throttle: <T extends AnyFunction, R = unknown>(throttler: Throttler<T, R> | T, wait: number) => Throttled<T>;
@@ -5,7 +5,6 @@ import { throttleTime } from 'rxjs';
5
5
  var throttle = function throttle(throttler, wait) {
6
6
  var _isFunction = isFunction(throttler);
7
7
  var callback = _isFunction ? throttler : throttler.callback;
8
- // @ts-ignore
9
8
  var waiter = new Waitable({
10
9
  callback: callback,
11
10
  pipe: _isFunction ? void 0 : throttler.pipe,
@@ -3,8 +3,7 @@
3
3
  var isFunction = require('../is/is-function.cjs');
4
4
 
5
5
  var toFunction = function toFunction(value) {
6
- var _isFunction = isFunction.isFunction(value);
7
- if (_isFunction) {
6
+ if (isFunction.isFunction(value)) {
8
7
  return value;
9
8
  }
10
9
  return function () {
@@ -1 +1,4 @@
1
- export declare const toFunction: <T extends Function>(value: unknown) => T;
1
+ import type { AnyFunction } from "../types";
2
+ type Functionable<T> = T extends AnyFunction ? T : T extends Function ? T : () => T;
3
+ export declare const toFunction: <T>(value: unknown) => Functionable<T>;
4
+ export {};
@@ -1,8 +1,7 @@
1
1
  import { isFunction } from '../is/is-function.mjs';
2
2
 
3
3
  var toFunction = function toFunction(value) {
4
- var _isFunction = isFunction(value);
5
- if (_isFunction) {
4
+ if (isFunction(value)) {
6
5
  return value;
7
6
  }
8
7
  return function () {
@@ -23,7 +23,10 @@ var _pipe = /*#__PURE__*/new WeakMap();
23
23
  var _callback = /*#__PURE__*/new WeakMap();
24
24
  var _Waitable_brand = /*#__PURE__*/new WeakSet();
25
25
  var Waitable = /*#__PURE__*/function () {
26
- function Waitable(props) {
26
+ function Waitable(_ref) {
27
+ var callback = _ref.callback,
28
+ pipe = _ref.pipe,
29
+ timer = _ref.timer;
27
30
  _classCallCheck(this, Waitable);
28
31
  _classPrivateMethodInitSpec(this, _Waitable_brand);
29
32
  _classPrivateFieldInitSpec(this, _cook$, void 0);
@@ -33,9 +36,9 @@ var Waitable = /*#__PURE__*/function () {
33
36
  _classPrivateFieldInitSpec(this, _callback, void 0);
34
37
  _classPrivateFieldSet(_cook$, this, null);
35
38
  _classPrivateFieldSet(_waiter$, this, null);
36
- _classPrivateFieldSet(_timer, this, props.timer);
37
- _classPrivateFieldSet(_pipe, this, props.pipe);
38
- _classPrivateFieldSet(_callback, this, props.callback);
39
+ _classPrivateFieldSet(_timer, this, timer);
40
+ _classPrivateFieldSet(_pipe, this, pipe);
41
+ _classPrivateFieldSet(_callback, this, callback);
39
42
  _assertClassBrand(_Waitable_brand, this, _use).call(this);
40
43
  }
41
44
  return _createClass(Waitable, [{
@@ -96,10 +99,8 @@ function _use() {
96
99
  })).subscribe(function (args) {
97
100
  if (!_classPrivateFieldGet(_pipe, _this)) {
98
101
  var _classPrivateFieldGet7;
99
- // @ts-ignore
100
102
  (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)).call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
101
103
  } else {
102
- // @ts-ignore
103
104
  _classPrivateFieldGet(_callback, _this).call(_this, args);
104
105
  }
105
106
  }));
@@ -1,15 +1,15 @@
1
1
  import { type MonoTypeOperatorFunction } from "rxjs";
2
- interface PropsWithoutPipe<T extends Array<unknown> = Array<unknown>> {
2
+ interface WaitingWithoutPipe<T extends Array<unknown> = Array<unknown>> {
3
3
  callback: (...args: T) => unknown;
4
4
  pipe: undefined;
5
5
  timer: MonoTypeOperatorFunction<T>;
6
6
  }
7
- interface PropsWithPipe<T extends Array<unknown> = Array<unknown>, R = unknown> {
7
+ interface WaitingWithPipe<T extends Array<unknown> = Array<unknown>, R = unknown> {
8
8
  callback: (value: R) => unknown;
9
9
  pipe: (...args: T) => R | Promise<R>;
10
10
  timer: MonoTypeOperatorFunction<T>;
11
11
  }
12
- type Props<T extends Array<unknown> = Array<unknown>, R = unknown> = PropsWithoutPipe<T> | PropsWithPipe<T, R>;
12
+ export type Waiting<T extends Array<unknown> = Array<unknown>, R = unknown> = WaitingWithoutPipe<T> | WaitingWithPipe<T, R>;
13
13
  /**
14
14
  * @description
15
15
  * waitable instance
@@ -17,7 +17,7 @@ type Props<T extends Array<unknown> = Array<unknown>, R = unknown> = PropsWithou
17
17
  */
18
18
  export declare class Waitable<T extends Array<unknown>, R = unknown> {
19
19
  #private;
20
- constructor(props: Props<T, R>);
20
+ constructor({ callback, pipe, timer }: Waiting<T, R>);
21
21
  /**
22
22
  * @description
23
23
  * flush