@aiszlab/relax 1.3.10 → 1.3.12

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 (162) hide show
  1. package/dist/dom/clipboard.d.ts +1 -0
  2. package/dist/dom/contains.cjs +22 -0
  3. package/dist/dom/index.cjs +9 -0
  4. package/dist/dom/index.mjs +2 -0
  5. package/dist/dom/scroll-to.cjs +74 -0
  6. package/dist/hooks/use-boolean.cjs +36 -0
  7. package/dist/hooks/use-click-away.cjs +29 -0
  8. package/dist/hooks/{use-click-away.js → use-click-away.mjs} +3 -3
  9. package/dist/hooks/use-controlled-state.cjs +39 -0
  10. package/dist/hooks/{use-controlled-state.js → use-controlled-state.mjs} +3 -3
  11. package/dist/hooks/use-counter.cjs +61 -0
  12. package/dist/hooks/{use-counter.js → use-counter.mjs} +2 -2
  13. package/dist/hooks/use-debounce-callback.cjs +83 -0
  14. package/dist/hooks/{use-debounce-callback.js → use-debounce-callback.mjs} +4 -4
  15. package/dist/hooks/use-default.cjs +16 -0
  16. package/dist/hooks/{use-default.js → use-default.mjs} +1 -1
  17. package/dist/hooks/use-device-pixel-ratio.cjs +22 -0
  18. package/dist/hooks/{use-device-pixel-ratio.js → use-device-pixel-ratio.mjs} +1 -1
  19. package/dist/hooks/use-event.cjs +16 -0
  20. package/dist/hooks/use-focus.cjs +33 -0
  21. package/dist/hooks/{use-focus.js → use-focus.mjs} +2 -2
  22. package/dist/hooks/use-force-update.cjs +23 -0
  23. package/dist/hooks/use-hover.cjs +27 -0
  24. package/dist/hooks/{use-hover.js → use-hover.mjs} +3 -3
  25. package/dist/hooks/use-identity.cjs +22 -0
  26. package/dist/hooks/use-image-loader.cjs +65 -0
  27. package/dist/hooks/use-infinite-scroll.cjs +64 -0
  28. package/dist/hooks/{use-infinite-scroll.js → use-infinite-scroll.mjs} +2 -2
  29. package/dist/hooks/use-is-mounted.cjs +35 -0
  30. package/dist/hooks/{use-is-mounted.js → use-is-mounted.mjs} +1 -1
  31. package/dist/hooks/use-local-storage-state.cjs +9 -0
  32. package/dist/hooks/{use-local-storage-state.js → use-local-storage-state.mjs} +1 -1
  33. package/dist/hooks/use-media-query.cjs +55 -0
  34. package/dist/hooks/{use-media-query.js → use-media-query.mjs} +3 -3
  35. package/dist/hooks/use-memorable.cjs +16 -0
  36. package/dist/hooks/use-memorable.mjs +14 -0
  37. package/dist/hooks/use-mount.cjs +18 -0
  38. package/dist/hooks/{use-mount.js → use-mount.mjs} +1 -1
  39. package/dist/hooks/use-mounted.cjs +18 -0
  40. package/dist/hooks/{use-mounted.js → use-mounted.mjs} +1 -1
  41. package/dist/hooks/use-mutate-observer.cjs +30 -0
  42. package/dist/hooks/{use-mutate-observer.js → use-mutate-observer.mjs} +3 -3
  43. package/dist/hooks/use-raf.cjs +28 -0
  44. package/dist/hooks/{use-raf.js → use-raf.mjs} +1 -1
  45. package/dist/hooks/use-reactive.cjs +32 -0
  46. package/dist/hooks/use-reactive.d.ts +4 -1
  47. package/dist/hooks/use-reactive.mjs +30 -0
  48. package/dist/hooks/use-refs.cjs +33 -0
  49. package/dist/hooks/{use-refs.js → use-refs.mjs} +1 -1
  50. package/dist/hooks/use-scroll-locker.cjs +99 -0
  51. package/dist/hooks/{use-scroll-locker.js → use-scroll-locker.mjs} +2 -2
  52. package/dist/hooks/use-scrollable.cjs +45 -0
  53. package/dist/hooks/{use-scrollable.js → use-scrollable.mjs} +1 -1
  54. package/dist/hooks/use-session-storage-state.cjs +9 -0
  55. package/dist/hooks/{use-session-storage-state.js → use-session-storage-state.mjs} +1 -1
  56. package/dist/hooks/use-storage-state.cjs +49 -0
  57. package/dist/hooks/{use-storage-state.js → use-storage-state.mjs} +1 -1
  58. package/dist/hooks/use-throttle-callback.cjs +85 -0
  59. package/dist/hooks/{use-throttle-callback.js → use-throttle-callback.mjs} +4 -4
  60. package/dist/hooks/use-timeout.cjs +70 -0
  61. package/dist/hooks/{use-timeout.js → use-timeout.mjs} +2 -2
  62. package/dist/hooks/use-timer.cjs +34 -0
  63. package/dist/hooks/{use-timer.js → use-timer.mjs} +1 -1
  64. package/dist/hooks/use-togglable.cjs +191 -0
  65. package/dist/hooks/{use-togglable.js → use-togglable.mjs} +2 -2
  66. package/dist/hooks/use-unmount.cjs +17 -0
  67. package/dist/hooks/use-update-effect.cjs +15 -0
  68. package/dist/hooks/{use-update-effect.js → use-update-effect.mjs} +2 -2
  69. package/dist/index.cjs +136 -0
  70. package/dist/index.d.ts +2 -1
  71. package/dist/index.mjs +65 -0
  72. package/dist/is/is-array.cjs +11 -0
  73. package/dist/is/is-dom-usable.cjs +12 -0
  74. package/dist/is/is-empty.cjs +27 -0
  75. package/dist/is/{is-empty.js → is-empty.mjs} +7 -7
  76. package/dist/is/is-function.cjs +11 -0
  77. package/dist/is/is-function.d.ts +2 -1
  78. package/dist/is/is-html-element.cjs +13 -0
  79. package/dist/is/is-html-input-element.cjs +13 -0
  80. package/dist/is/is-html-input-element.d.ts +1 -1
  81. package/dist/is/{is-html-input-element.js → is-html-input-element.mjs} +1 -1
  82. package/dist/is/is-mobile.cjs +15 -0
  83. package/dist/is/is-null.cjs +11 -0
  84. package/dist/is/is-number.cjs +7 -0
  85. package/dist/is/is-object.cjs +13 -0
  86. package/dist/is/is-object.d.ts +6 -0
  87. package/dist/is/is-object.mjs +11 -0
  88. package/dist/is/is-overflow.cjs +16 -0
  89. package/dist/is/is-primitive.cjs +11 -0
  90. package/dist/is/is-refable.cjs +36 -0
  91. package/dist/is/is-set.cjs +11 -0
  92. package/dist/is/is-string.cjs +7 -0
  93. package/dist/is/is-style-element.cjs +11 -0
  94. package/dist/is/is-thenable.cjs +11 -0
  95. package/dist/is/is-undefined.cjs +11 -0
  96. package/dist/is/is-void.cjs +14 -0
  97. package/dist/is/{is-void.js → is-void.mjs} +2 -2
  98. package/dist/utils/chain.cjs +17 -0
  99. package/dist/utils/clamp.cjs +15 -0
  100. package/dist/utils/clone.cjs +19 -0
  101. package/dist/utils/{clone.js → clone.mjs} +2 -2
  102. package/dist/utils/clsx.cjs +34 -0
  103. package/dist/utils/{clsx.js → clsx.mjs} +4 -4
  104. package/dist/utils/debounce.cjs +34 -0
  105. package/dist/utils/{debounce.js → debounce.mjs} +2 -2
  106. package/dist/utils/effect.cjs +18 -0
  107. package/dist/utils/{effect.js → effect.mjs} +1 -1
  108. package/dist/utils/exclude.cjs +20 -0
  109. package/dist/utils/range.cjs +18 -0
  110. package/dist/utils/replace.cjs +22 -0
  111. package/dist/utils/{replace.js → replace.mjs} +1 -1
  112. package/dist/utils/set-style.cjs +23 -0
  113. package/dist/utils/tagged-template-literals.cjs +34 -0
  114. package/dist/utils/throttle.cjs +34 -0
  115. package/dist/utils/{throttle.js → throttle.mjs} +2 -2
  116. package/dist/utils/to-array.cjs +27 -0
  117. package/dist/utils/{to-array.js → to-array.mjs} +1 -1
  118. package/dist/utils/to-form-data.cjs +29 -0
  119. package/dist/utils/{to-form-data.js → to-form-data.mjs} +1 -1
  120. package/dist/utils/to-function.cjs +15 -0
  121. package/dist/utils/{to-function.js → to-function.mjs} +1 -1
  122. package/dist/utils/toggle.cjs +32 -0
  123. package/dist/utils/{toggle.js → toggle.mjs} +1 -1
  124. package/dist/utils/unique.cjs +19 -0
  125. package/dist/utils/waitable.cjs +99 -0
  126. package/dist/utils/{waitable.js → waitable.mjs} +1 -1
  127. package/package.json +9 -4
  128. package/dist/dom/index.js +0 -2
  129. package/dist/hooks/use-memorable.js +0 -25
  130. package/dist/index.js +0 -64
  131. package/dist/is/is-complex.d.ts +0 -5
  132. package/dist/is/is-complex.js +0 -11
  133. /package/dist/dom/{contains.js → contains.mjs} +0 -0
  134. /package/dist/dom/{scroll-to.js → scroll-to.mjs} +0 -0
  135. /package/dist/hooks/{use-boolean.js → use-boolean.mjs} +0 -0
  136. /package/dist/hooks/{use-event.js → use-event.mjs} +0 -0
  137. /package/dist/hooks/{use-force-update.js → use-force-update.mjs} +0 -0
  138. /package/dist/hooks/{use-identity.js → use-identity.mjs} +0 -0
  139. /package/dist/hooks/{use-image-loader.js → use-image-loader.mjs} +0 -0
  140. /package/dist/hooks/{use-unmount.js → use-unmount.mjs} +0 -0
  141. /package/dist/is/{is-array.js → is-array.mjs} +0 -0
  142. /package/dist/is/{is-dom-usable.js → is-dom-usable.mjs} +0 -0
  143. /package/dist/is/{is-function.js → is-function.mjs} +0 -0
  144. /package/dist/is/{is-html-element.js → is-html-element.mjs} +0 -0
  145. /package/dist/is/{is-mobile.js → is-mobile.mjs} +0 -0
  146. /package/dist/is/{is-null.js → is-null.mjs} +0 -0
  147. /package/dist/is/{is-number.js → is-number.mjs} +0 -0
  148. /package/dist/is/{is-overflow.js → is-overflow.mjs} +0 -0
  149. /package/dist/is/{is-primitive.js → is-primitive.mjs} +0 -0
  150. /package/dist/is/{is-refable.js → is-refable.mjs} +0 -0
  151. /package/dist/is/{is-set.js → is-set.mjs} +0 -0
  152. /package/dist/is/{is-string.js → is-string.mjs} +0 -0
  153. /package/dist/is/{is-style-element.js → is-style-element.mjs} +0 -0
  154. /package/dist/is/{is-thenable.js → is-thenable.mjs} +0 -0
  155. /package/dist/is/{is-undefined.js → is-undefined.mjs} +0 -0
  156. /package/dist/utils/{chain.js → chain.mjs} +0 -0
  157. /package/dist/utils/{clamp.js → clamp.mjs} +0 -0
  158. /package/dist/utils/{exclude.js → exclude.mjs} +0 -0
  159. /package/dist/utils/{range.js → range.mjs} +0 -0
  160. /package/dist/utils/{set-style.js → set-style.mjs} +0 -0
  161. /package/dist/utils/{tagged-template-literals.js → tagged-template-literals.mjs} +0 -0
  162. /package/dist/utils/{unique.js → unique.mjs} +0 -0
@@ -1,5 +1,5 @@
1
- import { isArray } from '../is/is-array.js';
2
- import { isPrimitive } from '../is/is-primitive.js';
1
+ import { isArray } from '../is/is-array.mjs';
2
+ import { isPrimitive } from '../is/is-primitive.mjs';
3
3
 
4
4
  /**
5
5
  * @description
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var isArray = require('../is/is-array.cjs');
5
+ var isNumber = require('../is/is-number.cjs');
6
+ var isString = require('../is/is-string.cjs');
7
+ var isVoid = require('../is/is-void.cjs');
8
+
9
+ var _toClassNames = function toClassNames(value) {
10
+ if (isVoid.isVoid(value)) return [];
11
+ if (isString.isString(value) || isNumber.isNumber(value)) return [value.toString()];
12
+ if (isArray.isArray(value)) {
13
+ return value.reduce(function (classNames, item) {
14
+ return classNames.concat(_toClassNames(item));
15
+ }, []);
16
+ }
17
+ return Object.entries(value).reduce(function (classNames, _ref) {
18
+ var _ref2 = _slicedToArray(_ref, 2),
19
+ className = _ref2[0],
20
+ isValid = _ref2[1];
21
+ if (isValid) {
22
+ classNames.push(className);
23
+ }
24
+ return classNames;
25
+ }, []);
26
+ };
27
+ var clsx = function clsx() {
28
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29
+ args[_key] = arguments[_key];
30
+ }
31
+ return _toClassNames(args).join(" ");
32
+ };
33
+
34
+ exports.clsx = clsx;
@@ -1,8 +1,8 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import { isArray } from '../is/is-array.js';
3
- import { isNumber } from '../is/is-number.js';
4
- import { isString } from '../is/is-string.js';
5
- import { isVoid } from '../is/is-void.js';
2
+ import { isArray } from '../is/is-array.mjs';
3
+ import { isNumber } from '../is/is-number.mjs';
4
+ import { isString } from '../is/is-string.mjs';
5
+ import { isVoid } from '../is/is-void.mjs';
6
6
 
7
7
  var _toClassNames = function toClassNames(value) {
8
8
  if (isVoid(value)) return [];
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var rxjs = require('rxjs');
4
+ var isFunction = require('../is/is-function.cjs');
5
+ var waitable = require('./waitable.cjs');
6
+
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;
16
+ var waiter = new waitable.Waitable({
17
+ callback: callback,
18
+ pipe: pipe,
19
+ timer: rxjs.debounceTime(wait)
20
+ });
21
+ return {
22
+ next: function next() {
23
+ return waiter.next.apply(waiter, arguments);
24
+ },
25
+ flush: function flush() {
26
+ return waiter.flush();
27
+ },
28
+ abort: function abort() {
29
+ return waiter.abort();
30
+ }
31
+ };
32
+ };
33
+
34
+ exports.debounce = debounce;
@@ -1,6 +1,6 @@
1
1
  import { debounceTime } from 'rxjs';
2
- import { isFunction } from '../is/is-function.js';
3
- import { Waitable } from './waitable.js';
2
+ import { isFunction } from '../is/is-function.mjs';
3
+ import { Waitable } from './waitable.mjs';
4
4
 
5
5
  var debounce = function debounce(debouncer, wait) {
6
6
  var isCallable = isFunction(debouncer);
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var isThenable = require('../is/is-thenable.cjs');
4
+
5
+ /**
6
+ * @description
7
+ * call thenable effect
8
+ */
9
+ var effect = function effect(callable) {
10
+ var called = callable();
11
+ // if result is void
12
+ if (!called) return void 0;
13
+ // if result is promise like, return void
14
+ if (isThenable.isThenable(called)) return void 0;
15
+ return called;
16
+ };
17
+
18
+ exports.effect = effect;
@@ -1,4 +1,4 @@
1
- import { isThenable } from '../is/is-thenable.js';
1
+ import { isThenable } from '../is/is-thenable.mjs';
2
2
 
3
3
  /**
4
4
  * @description
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @description
5
+ * exclude any value from array
6
+ *
7
+ * for performance, avoid using `Array.includes`, replace with `Set`
8
+ *
9
+ * @example
10
+ * exclude([1, 2, 3, 4, 5], [2, 4]) // [1, 3, 5]
11
+ */
12
+ var exclude = function exclude(value, _excludeBy) {
13
+ var excludeBy = new Set(_excludeBy);
14
+ // @ts-ignore
15
+ return value.filter(function (item) {
16
+ return !excludeBy.has(item);
17
+ });
18
+ };
19
+
20
+ exports.exclude = exclude;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Returns an array of numbers, starting at `from` and ending at `to`.
5
+ * @param from number
6
+ * @param to number
7
+ * @returns number[]
8
+ */
9
+ var range = function range(from, to) {
10
+ var length = Math.max(to - from + 1, 0);
11
+ return Array.from({
12
+ length: length
13
+ }, function (_, index) {
14
+ return index + from;
15
+ });
16
+ };
17
+
18
+ exports.range = range;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
+ var isArray = require('../is/is-array.cjs');
5
+
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)));
16
+ }
17
+ var replaceValue = options.replaceValue,
18
+ searchValue = options.searchValue;
19
+ return value.replace(searchValue, replaceValue);
20
+ };
21
+
22
+ exports.replace = replace;
@@ -1,5 +1,5 @@
1
1
  import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
- import { isArray } from '../is/is-array.js';
2
+ import { isArray } from '../is/is-array.mjs';
3
3
 
4
4
  /**
5
5
  * @description
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+
5
+ /**
6
+ * @description
7
+ * set inline style util
8
+ */
9
+ var setStyle = function setStyle(target, styles) {
10
+ if (!styles) return {};
11
+ return Object.entries(styles).reduce(function (prev, _ref) {
12
+ var _ref2 = _slicedToArray(_ref, 2),
13
+ key = _ref2[0],
14
+ value = _ref2[1];
15
+ // @ts-ignore
16
+ prev[key] = target.style[key];
17
+ // @ts-ignore
18
+ target.style[key] = value;
19
+ return prev;
20
+ }, {});
21
+ };
22
+
23
+ exports.setStyle = setStyle;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var _construct = require('@babel/runtime/helpers/construct');
4
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
5
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
+
7
+ /**
8
+ * @description
9
+ * create tagged template literals
10
+ */
11
+ var taggedTemplateLiterals = function taggedTemplateLiterals(template, variables) {
12
+ if (!variables) return template;
13
+ var entries = Object.entries(variables);
14
+ if (entries.length === 0) return template;
15
+ var _entries$reduce = entries.reduce(function (prev, _ref) {
16
+ var _ref2 = _slicedToArray(_ref, 2),
17
+ key = _ref2[0],
18
+ value = _ref2[1];
19
+ prev[0].push(key);
20
+ prev[1].push(value !== null && value !== void 0 ? value : "");
21
+ return prev;
22
+ }, [[], []]),
23
+ _entries$reduce2 = _slicedToArray(_entries$reduce, 2),
24
+ keys = _entries$reduce2[0],
25
+ values = _entries$reduce2[1];
26
+ try {
27
+ var render = _construct(Function, _toConsumableArray(keys).concat(["return `".concat(template, "`")]));
28
+ return render.apply(void 0, _toConsumableArray(values));
29
+ } catch (error) {
30
+ return template;
31
+ }
32
+ };
33
+
34
+ exports.taggedTemplateLiterals = taggedTemplateLiterals;
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ var waitable = require('./waitable.cjs');
4
+ var isFunction = require('../is/is-function.cjs');
5
+ var rxjs = require('rxjs');
6
+
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;
16
+ var waiter = new waitable.Waitable({
17
+ callback: callback,
18
+ pipe: pipe,
19
+ timer: rxjs.throttleTime(wait)
20
+ });
21
+ return {
22
+ next: function next() {
23
+ return waiter.next.apply(waiter, arguments);
24
+ },
25
+ flush: function flush() {
26
+ return waiter.flush();
27
+ },
28
+ abort: function abort() {
29
+ return waiter.abort();
30
+ }
31
+ };
32
+ };
33
+
34
+ exports.throttle = throttle;
@@ -1,5 +1,5 @@
1
- import { Waitable } from './waitable.js';
2
- import { isFunction } from '../is/is-function.js';
1
+ import { Waitable } from './waitable.mjs';
2
+ import { isFunction } from '../is/is-function.mjs';
3
3
  import { throttleTime } from 'rxjs';
4
4
 
5
5
  var throttle = function throttle(throttler, wait) {
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var _typeof = require('@babel/runtime/helpers/typeof');
4
+ var isVoid = require('../is/is-void.cjs');
5
+
6
+ /**
7
+ * @description
8
+ * convert any type data to a array
9
+ */
10
+ var toArray = function toArray(value) {
11
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
12
+ separator = _ref.separator;
13
+ if (Array.isArray(value)) {
14
+ return value;
15
+ }
16
+ switch (_typeof(value)) {
17
+ case "string":
18
+ if (isVoid.isVoid(separator)) {
19
+ return [value];
20
+ }
21
+ return value.split(separator);
22
+ default:
23
+ return [value];
24
+ }
25
+ };
26
+
27
+ exports.toArray = toArray;
@@ -1,5 +1,5 @@
1
1
  import _typeof from '@babel/runtime/helpers/typeof';
2
- import { isVoid } from '../is/is-void.js';
2
+ import { isVoid } from '../is/is-void.mjs';
3
3
 
4
4
  /**
5
5
  * @description
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
+ var isArray = require('../is/is-array.cjs');
5
+
6
+ /**
7
+ * @description
8
+ * convert to formData
9
+ */
10
+ var toFormData = function toFormData(data) {
11
+ return Object.entries(data !== null && data !== void 0 ? data : {}).reduce(function (prev, _ref) {
12
+ var _ref2 = _slicedToArray(_ref, 2),
13
+ key = _ref2[0],
14
+ value = _ref2[1];
15
+ // support key-value array data
16
+ // if value is { list: [ 11, 22 ] }
17
+ // like prev.append('list[]', 11);
18
+ if (isArray.isArray(value)) {
19
+ value.forEach(function (item) {
20
+ prev.append("".concat(key, "[]"), item);
21
+ });
22
+ return prev;
23
+ }
24
+ prev.append(key, value);
25
+ return prev;
26
+ }, new FormData());
27
+ };
28
+
29
+ exports.toFormData = toFormData;
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
2
- import { isArray } from '../is/is-array.js';
2
+ import { isArray } from '../is/is-array.mjs';
3
3
 
4
4
  /**
5
5
  * @description
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var isFunction = require('../is/is-function.cjs');
4
+
5
+ var toFunction = function toFunction(value) {
6
+ var _isFunction = isFunction.isFunction(value);
7
+ if (_isFunction) {
8
+ return value;
9
+ }
10
+ return function () {
11
+ return value;
12
+ };
13
+ };
14
+
15
+ exports.toFunction = toFunction;
@@ -1,4 +1,4 @@
1
- import { isFunction } from '../is/is-function.js';
1
+ import { isFunction } from '../is/is-function.mjs';
2
2
 
3
3
  var toFunction = function toFunction(value) {
4
4
  var _isFunction = isFunction(value);
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var isSet = require('../is/is-set.cjs');
4
+
5
+ /**
6
+ * toggle api
7
+ * @description
8
+ * when list has current key, remove it, otherwise add it
9
+ *
10
+ * return a copy of list
11
+ */
12
+ var toggle = function toggle(value, key) {
13
+ if (isSet.isSet(value)) {
14
+ var _copied = new Set(value);
15
+ if (_copied.has(key)) {
16
+ _copied["delete"](key);
17
+ } else {
18
+ _copied.add(key);
19
+ }
20
+ return _copied;
21
+ }
22
+ var copied = Array.from(value);
23
+ var index = copied.indexOf(key);
24
+ if (index === -1) {
25
+ copied.push(key);
26
+ } else {
27
+ copied.splice(index, 1);
28
+ }
29
+ return copied;
30
+ };
31
+
32
+ exports.toggle = toggle;
@@ -1,4 +1,4 @@
1
- import { isSet } from '../is/is-set.js';
1
+ import { isSet } from '../is/is-set.mjs';
2
2
 
3
3
  /**
4
4
  * toggle api
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @description
5
+ * unique
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)));
16
+ };
17
+
18
+ exports.unique = unique;
19
+ exports.uniqueBy = uniqueBy;
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
+ var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
5
+ var _createClass = require('@babel/runtime/helpers/createClass');
6
+ var _classPrivateMethodInitSpec = require('@babel/runtime/helpers/classPrivateMethodInitSpec');
7
+ var _classPrivateFieldInitSpec = require('@babel/runtime/helpers/classPrivateFieldInitSpec');
8
+ var _classPrivateFieldGet = require('@babel/runtime/helpers/classPrivateFieldGet2');
9
+ var _assertClassBrand = require('@babel/runtime/helpers/assertClassBrand');
10
+ var _classPrivateFieldSet = require('@babel/runtime/helpers/classPrivateFieldSet2');
11
+ var rxjs = require('rxjs');
12
+ var isThenable = require('../is/is-thenable.cjs');
13
+
14
+ /**
15
+ * @description
16
+ * waitable instance
17
+ * for debounce...
18
+ */
19
+ var _cook$ = /*#__PURE__*/new WeakMap();
20
+ var _waiter$ = /*#__PURE__*/new WeakMap();
21
+ var _timer = /*#__PURE__*/new WeakMap();
22
+ var _pipe = /*#__PURE__*/new WeakMap();
23
+ var _callback = /*#__PURE__*/new WeakMap();
24
+ var _Waitable_brand = /*#__PURE__*/new WeakSet();
25
+ var Waitable = /*#__PURE__*/function () {
26
+ function Waitable(props) {
27
+ _classCallCheck(this, Waitable);
28
+ _classPrivateMethodInitSpec(this, _Waitable_brand);
29
+ _classPrivateFieldInitSpec(this, _cook$, void 0);
30
+ _classPrivateFieldInitSpec(this, _waiter$, void 0);
31
+ _classPrivateFieldInitSpec(this, _timer, void 0);
32
+ _classPrivateFieldInitSpec(this, _pipe, void 0);
33
+ _classPrivateFieldInitSpec(this, _callback, void 0);
34
+ _classPrivateFieldSet(_cook$, this, null);
35
+ _classPrivateFieldSet(_waiter$, this, null);
36
+ _classPrivateFieldSet(_pipe, this, props.pipe);
37
+ _classPrivateFieldSet(_timer, this, props.timer);
38
+ _classPrivateFieldSet(_callback, this, props.callback);
39
+ _assertClassBrand(_Waitable_brand, this, _use).call(this);
40
+ }
41
+ return _createClass(Waitable, [{
42
+ key: "flush",
43
+ value:
44
+ /**
45
+ * @description
46
+ * flush
47
+ * complete all handlers
48
+ * in relax, we will create a new observable for next debounce/throttle handler
49
+ * so it will make some async problems, pls attention
50
+ */
51
+ function flush() {
52
+ var _classPrivateFieldGet2;
53
+ (_classPrivateFieldGet2 = _classPrivateFieldGet(_waiter$, this)) === null || _classPrivateFieldGet2 === void 0 || _classPrivateFieldGet2.complete();
54
+ _assertClassBrand(_Waitable_brand, this, _use).call(this);
55
+ }
56
+ /**
57
+ * @description
58
+ * abort
59
+ * cancel all handlers
60
+ * in relax, we will create a new observable for next debounce/throttle handler
61
+ */
62
+ }, {
63
+ key: "abort",
64
+ value: function abort() {
65
+ var _classPrivateFieldGet3, _classPrivateFieldGet4;
66
+ (_classPrivateFieldGet3 = _classPrivateFieldGet(_cook$, this)) === null || _classPrivateFieldGet3 === void 0 || _classPrivateFieldGet3.unsubscribe();
67
+ (_classPrivateFieldGet4 = _classPrivateFieldGet(_waiter$, this)) === null || _classPrivateFieldGet4 === void 0 || _classPrivateFieldGet4.error();
68
+ _assertClassBrand(_Waitable_brand, this, _use).call(this);
69
+ }
70
+ /**
71
+ * @description
72
+ * trigger value
73
+ */
74
+ }, {
75
+ key: "next",
76
+ value: function next() {
77
+ var _classPrivateFieldGet5;
78
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
79
+ args[_key] = arguments[_key];
80
+ }
81
+ (_classPrivateFieldGet5 = _classPrivateFieldGet(_waiter$, this)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.next(args);
82
+ }
83
+ }]);
84
+ }();
85
+ function _use() {
86
+ var _this = this;
87
+ _classPrivateFieldSet(_cook$, this, new rxjs.Observable(function (subscriber) {
88
+ _classPrivateFieldSet(_waiter$, _this, subscriber);
89
+ }).pipe(_classPrivateFieldGet(_timer, this), rxjs.switchMap(function (args) {
90
+ var _classPrivateFieldGet6;
91
+ var piped = (_classPrivateFieldGet6 = _classPrivateFieldGet(_pipe, _this)).call.apply(_classPrivateFieldGet6, [_this].concat(_toConsumableArray(args)));
92
+ return isThenable.isThenable(piped) ? rxjs.from(piped) : rxjs.of(piped);
93
+ })).subscribe(function (args) {
94
+ var _classPrivateFieldGet7;
95
+ (_classPrivateFieldGet7 = _classPrivateFieldGet(_callback, _this)) === null || _classPrivateFieldGet7 === void 0 || _classPrivateFieldGet7.call.apply(_classPrivateFieldGet7, [_this].concat(_toConsumableArray(args)));
96
+ }));
97
+ }
98
+
99
+ exports.Waitable = Waitable;
@@ -7,7 +7,7 @@ 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
9
  import { Observable, switchMap, from, of } from 'rxjs';
10
- import { isThenable } from '../is/is-thenable.js';
10
+ import { isThenable } from '../is/is-thenable.mjs';
11
11
 
12
12
  /**
13
13
  * @description
package/package.json CHANGED
@@ -1,16 +1,21 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
4
4
  "description": "react utils collection",
5
- "type": "module",
6
5
  "exports": {
7
6
  ".": {
8
7
  "types": "./dist/index.d.ts",
9
- "default": "./dist/index.js"
8
+ "node": "./dist/index.cjs",
9
+ "require": "./dist/index.cjs",
10
+ "import": "./dist/index.mjs",
11
+ "default": "./dist/index.mjs"
10
12
  },
11
13
  "./dom": {
12
14
  "types": "./dist/dom/index.d.ts",
13
- "default": "./dist/dom/index.js"
15
+ "node": "./dist/dom/index.cjs",
16
+ "require": "./dist/dom/index.cjs",
17
+ "import": "./dist/dom/index.mjs",
18
+ "default": "./dist/dom/index.mjs"
14
19
  },
15
20
  "./types": "./dist/types/index.d.ts"
16
21
  },
package/dist/dom/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { scrollTo } from './scroll-to.js';
2
- export { contains } from './contains.js';
@@ -1,25 +0,0 @@
1
- import { useRef, useEffect } from 'react';
2
- import { useDefault } from './use-default.js';
3
-
4
- var useMemorable = function useMemorable(getter, condition, shouldUpdate) {
5
- var isMounted = useRef(false);
6
- var cacheRef = useRef({
7
- value: useDefault(getter),
8
- condition: condition
9
- });
10
- useEffect(function () {
11
- // value has got in the first render, skip this render time
12
- if (!isMounted.current) {
13
- isMounted.current = true;
14
- return;
15
- }
16
- if (!shouldUpdate(cacheRef.current.condition, condition)) return;
17
- cacheRef.current = {
18
- value: getter(),
19
- condition: condition
20
- };
21
- });
22
- return cacheRef.current.value;
23
- };
24
-
25
- export { useMemorable };