@aiszlab/relax 1.2.57 → 1.2.58

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 (133) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.js +138 -0
  2. package/dist/dom/contains.d.ts +1 -0
  3. package/dist/dom/contains.js +20 -0
  4. package/dist/dom/index.d.ts +3 -0
  5. package/dist/dom/index.js +2 -0
  6. package/dist/dom/scroll-to.d.ts +19 -0
  7. package/dist/dom/scroll-to.js +69 -0
  8. package/dist/hooks/use-boolean.d.ts +19 -0
  9. package/dist/hooks/use-boolean.js +34 -0
  10. package/dist/hooks/use-controlled-state.d.ts +17 -0
  11. package/dist/hooks/use-controlled-state.js +40 -0
  12. package/dist/hooks/use-counter.d.ts +33 -0
  13. package/dist/hooks/use-counter.js +59 -0
  14. package/dist/hooks/use-debounce-callback.d.ts +18 -0
  15. package/dist/hooks/use-debounce-callback.js +81 -0
  16. package/dist/hooks/use-default.d.ts +8 -0
  17. package/dist/hooks/use-default.js +14 -0
  18. package/dist/hooks/use-device-pixel-ratio.d.ts +6 -0
  19. package/dist/hooks/use-device-pixel-ratio.js +20 -0
  20. package/dist/hooks/use-event.d.ts +2 -0
  21. package/dist/hooks/use-event.js +12 -0
  22. package/dist/hooks/use-focus.d.ts +15 -0
  23. package/dist/hooks/use-focus.js +31 -0
  24. package/dist/hooks/use-force-update.d.ts +7 -0
  25. package/dist/hooks/use-force-update.js +21 -0
  26. package/dist/hooks/use-hover.d.ts +8 -0
  27. package/dist/hooks/use-hover.js +25 -0
  28. package/dist/hooks/use-identity.d.ts +5 -0
  29. package/dist/hooks/use-identity.js +20 -0
  30. package/dist/hooks/use-image-loader.d.ts +12 -0
  31. package/dist/hooks/use-image-loader.js +54 -0
  32. package/dist/hooks/use-media-query.d.ts +7 -0
  33. package/dist/hooks/use-memorable.d.ts +1 -0
  34. package/dist/hooks/use-memorable.js +14 -0
  35. package/dist/hooks/use-mount.d.ts +8 -0
  36. package/dist/hooks/use-mount.js +16 -0
  37. package/dist/hooks/use-mounted.d.ts +8 -0
  38. package/dist/hooks/use-mounted.js +16 -0
  39. package/dist/hooks/use-mutate-observer.d.ts +1 -0
  40. package/dist/hooks/use-mutate-observer.js +28 -0
  41. package/dist/hooks/use-raf.d.ts +7 -0
  42. package/dist/hooks/use-raf.js +26 -0
  43. package/dist/hooks/use-reactive.d.ts +6 -0
  44. package/dist/hooks/use-refs.d.ts +5 -0
  45. package/dist/hooks/use-refs.js +31 -0
  46. package/dist/hooks/use-scroll-locker.d.ts +5 -0
  47. package/dist/hooks/use-scroll-locker.js +92 -0
  48. package/dist/hooks/use-scrollable.d.ts +17 -0
  49. package/dist/hooks/use-scrollable.js +43 -0
  50. package/dist/hooks/use-throttle-callback.d.ts +18 -0
  51. package/dist/hooks/use-throttle-callback.js +83 -0
  52. package/dist/hooks/use-timeout.d.ts +10 -0
  53. package/dist/hooks/use-timeout.js +68 -0
  54. package/dist/hooks/use-togglable.d.ts +48 -0
  55. package/dist/hooks/use-togglable.js +177 -0
  56. package/dist/hooks/use-update-effect.d.ts +3 -0
  57. package/dist/hooks/use-update-effect.js +19 -0
  58. package/dist/index.d.ts +64 -0
  59. package/dist/index.js +52 -0
  60. package/dist/is/is-array.d.ts +5 -0
  61. package/dist/is/is-array.js +9 -0
  62. package/dist/is/is-complex.d.ts +5 -0
  63. package/dist/is/is-complex.js +11 -0
  64. package/dist/is/is-dom-usable.d.ts +5 -0
  65. package/dist/is/is-dom-usable.js +9 -0
  66. package/dist/is/is-empty.d.ts +7 -0
  67. package/dist/is/is-empty.js +25 -0
  68. package/dist/is/is-function.d.ts +5 -0
  69. package/dist/is/is-function.js +9 -0
  70. package/dist/is/is-map.d.ts +5 -0
  71. package/dist/is/is-mobile.d.ts +5 -0
  72. package/dist/is/is-mobile.js +13 -0
  73. package/dist/is/is-null.d.ts +5 -0
  74. package/dist/is/is-null.js +9 -0
  75. package/dist/is/is-overflow.d.ts +5 -0
  76. package/dist/is/is-overflow.js +14 -0
  77. package/dist/is/is-pointer-usable.d.ts +5 -0
  78. package/dist/is/is-primitive.d.ts +5 -0
  79. package/dist/is/is-primitive.js +9 -0
  80. package/dist/is/is-refable.d.ts +5 -0
  81. package/dist/is/is-refable.js +34 -0
  82. package/dist/is/is-set.d.ts +5 -0
  83. package/dist/is/is-set.js +9 -0
  84. package/dist/is/is-state-getter.d.ts +6 -0
  85. package/dist/is/is-state-getter.js +9 -0
  86. package/dist/is/is-style-element.d.ts +5 -0
  87. package/dist/is/is-style-element.js +9 -0
  88. package/dist/is/is-thenable.d.ts +5 -0
  89. package/dist/is/is-thenable.js +9 -0
  90. package/dist/is/is-undefined.d.ts +5 -0
  91. package/dist/is/is-undefined.js +9 -0
  92. package/dist/is/is-void.d.ts +5 -0
  93. package/dist/is/is-void.js +12 -0
  94. package/dist/types/first.d.ts +1 -0
  95. package/dist/types/index.d.ts +8 -0
  96. package/dist/types/last.d.ts +1 -0
  97. package/dist/types/nullable.d.ts +5 -0
  98. package/dist/types/partialable.d.ts +5 -0
  99. package/dist/types/required-in.d.ts +5 -0
  100. package/dist/types/state.d.ts +10 -0
  101. package/dist/types/thenable-effect-callback.d.ts +6 -0
  102. package/dist/types/voidable.d.ts +7 -0
  103. package/dist/utils/chain.d.ts +2 -0
  104. package/dist/utils/chain.js +15 -0
  105. package/dist/utils/clamp.d.ts +9 -0
  106. package/dist/utils/clamp.js +13 -0
  107. package/dist/utils/clone.d.ts +6 -0
  108. package/dist/utils/clone.js +17 -0
  109. package/dist/utils/debounce.d.ts +23 -0
  110. package/dist/utils/debounce.js +32 -0
  111. package/dist/utils/effect.d.ts +7 -0
  112. package/dist/utils/effect.js +16 -0
  113. package/dist/utils/exclude.d.ts +10 -0
  114. package/dist/utils/exclude.js +18 -0
  115. package/dist/utils/range.d.ts +7 -0
  116. package/dist/utils/range.js +16 -0
  117. package/dist/utils/set-style.d.ts +6 -0
  118. package/dist/utils/set-style.js +21 -0
  119. package/dist/utils/throttle.d.ts +5 -0
  120. package/dist/utils/throttle.js +32 -0
  121. package/dist/utils/to-array.d.ts +18 -0
  122. package/dist/utils/to-array.js +25 -0
  123. package/dist/utils/to-form-data.d.ts +5 -0
  124. package/dist/utils/to-form-data.js +27 -0
  125. package/dist/utils/to-function.d.ts +1 -0
  126. package/dist/utils/to-function.js +13 -0
  127. package/dist/utils/toggle.d.ts +8 -0
  128. package/dist/utils/toggle.js +30 -0
  129. package/dist/utils/unique.d.ts +10 -0
  130. package/dist/utils/unique.js +16 -0
  131. package/dist/utils/waitable.d.ts +36 -0
  132. package/dist/utils/waitable.js +90 -0
  133. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ import { isValidElement } from 'react';
2
+ import { isFragment, isMemo } from 'react-is';
3
+
4
+ /**
5
+ * @description
6
+ */
7
+ var isRefable = function isRefable(node) {
8
+ if (!isValidElement(node)) {
9
+ return false;
10
+ }
11
+ if (isFragment(node)) {
12
+ return false;
13
+ }
14
+ return _RefableElement(node);
15
+ };
16
+ /**
17
+ * @description
18
+ * refable element
19
+ */
20
+ var _RefableElement = function _RefableElement(element) {
21
+ var _type$prototype, _element$prototype;
22
+ var type = isMemo(element) ? element.type.type : element.type;
23
+ // Function component node
24
+ if (typeof type === "function" && !((_type$prototype = type.prototype) !== null && _type$prototype !== void 0 && _type$prototype.render)) {
25
+ return false;
26
+ }
27
+ // Class component
28
+ if (typeof element === "function" && !((_element$prototype = element.prototype) !== null && _element$prototype !== void 0 && _element$prototype.render)) {
29
+ return false;
30
+ }
31
+ return true;
32
+ };
33
+
34
+ export { isRefable };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is set
4
+ */
5
+ export declare const isSet: (value: unknown) => value is Set<unknown>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is set
4
+ */
5
+ var isSet = function isSet(value) {
6
+ return value instanceof Set;
7
+ };
8
+
9
+ export { isSet };
@@ -0,0 +1,6 @@
1
+ import type { State, StateGetter } from "../types";
2
+ /**
3
+ * @description
4
+ * is state getter
5
+ */
6
+ export declare const isStateGetter: <T>(state: State<T>) => state is StateGetter<T>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is state getter
4
+ */
5
+ var isStateGetter = function isStateGetter(state) {
6
+ return typeof state === "function";
7
+ };
8
+
9
+ export { isStateGetter };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * style element
4
+ */
5
+ export declare const isStyleElement: (element: Element) => element is HTMLStyleElement;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * style element
4
+ */
5
+ var isStyleElement = function isStyleElement(element) {
6
+ return element.tagName === "STYLE";
7
+ };
8
+
9
+ export { isStyleElement };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is thenable
4
+ */
5
+ export declare const isThenable: <T>(value: T | PromiseLike<T>) => value is PromiseLike<T>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is thenable
4
+ */
5
+ var isThenable = function isThenable(value) {
6
+ return value instanceof Promise || !!(value !== null && value !== void 0 && value.then);
7
+ };
8
+
9
+ export { isThenable };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is undefined
4
+ */
5
+ export declare const isUndefined: (value: unknown) => value is undefined;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is undefined
4
+ */
5
+ var isUndefined = function isUndefined(value) {
6
+ return value === void 0;
7
+ };
8
+
9
+ export { isUndefined };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is null or undefined
4
+ */
5
+ export declare const isVoid: (value: unknown) => value is null | undefined;
@@ -0,0 +1,12 @@
1
+ import { isUndefined } from './is-undefined.js';
2
+ import { isNull } from './is-null.js';
3
+
4
+ /**
5
+ * @description
6
+ * is null or undefined
7
+ */
8
+ var isVoid = function isVoid(value) {
9
+ return isNull(value) || isUndefined(value);
10
+ };
11
+
12
+ export { isVoid };
@@ -0,0 +1 @@
1
+ export type First<T> = T extends [infer D, ...Array<unknown>] ? D : undefined;
@@ -0,0 +1,8 @@
1
+ export type { Nullable } from "./nullable";
2
+ export type { Partialable } from "./partialable";
3
+ export type { Voidable } from "./voidable";
4
+ export type { RequiredIn } from "./required-in";
5
+ export type { ThenableEffectCallback } from "./thenable-effect-callback";
6
+ export type { First } from "./first";
7
+ export type { Last } from "./last";
8
+ export type { State, StateGetter } from "./state";
@@ -0,0 +1 @@
1
+ export type Last<T> = T extends [...Array<unknown>, infer D] ? D : undefined;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * null able
4
+ */
5
+ export type Nullable<T> = T | null;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * partial able
4
+ */
5
+ export type Partialable<T> = T | undefined;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * require some fields
4
+ */
5
+ export type RequiredIn<T, K extends keyof T> = Required<Pick<T, K>> & Omit<T, K>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description
3
+ * in react, define some initial state always use a value getter
4
+ */
5
+ export type StateGetter<T> = () => T;
6
+ /**
7
+ * @description
8
+ * value or state setter
9
+ */
10
+ export type State<T> = T | StateGetter<T>;
@@ -0,0 +1,6 @@
1
+ import type { EffectCallback } from "react";
2
+ /**
3
+ * @description
4
+ * thenable effect callback
5
+ */
6
+ export type ThenableEffectCallback = () => ReturnType<EffectCallback> | PromiseLike<ReturnType<EffectCallback>>;
@@ -0,0 +1,7 @@
1
+ import type { Partialable } from "./partialable";
2
+ import type { Nullable } from "./nullable";
3
+ /**
4
+ * @description
5
+ * void able
6
+ */
7
+ export type Voidable<T> = Partialable<Nullable<T>>;
@@ -0,0 +1,2 @@
1
+ import type { Voidable } from "../types";
2
+ export declare const chain: <T extends Function>(...callbacks: Voidable<T>[]) => T;
@@ -0,0 +1,15 @@
1
+ var chain = function chain() {
2
+ for (var _len = arguments.length, callbacks = new Array(_len), _key = 0; _key < _len; _key++) {
3
+ callbacks[_key] = arguments[_key];
4
+ }
5
+ return function () {
6
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
7
+ args[_key2] = arguments[_key2];
8
+ }
9
+ callbacks.forEach(function (callback) {
10
+ callback === null || callback === void 0 || callback.apply(void 0, args);
11
+ });
12
+ };
13
+ };
14
+
15
+ export { chain };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * get mid value
4
+ * @param value number
5
+ * @param min number
6
+ * @param max number
7
+ * @returns number
8
+ */
9
+ export declare const clamp: (value: number, min: number, max: number) => number;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @description
3
+ * get mid value
4
+ * @param value number
5
+ * @param min number
6
+ * @param max number
7
+ * @returns number
8
+ */
9
+ var clamp = function clamp(value, min, max) {
10
+ return Math.min(Math.max(value, min), max);
11
+ };
12
+
13
+ export { clamp };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @description
3
+ * in develop, there are many cases to clone a string/number/object/array
4
+ * this util is planning to resolve it
5
+ */
6
+ export declare const clone: (value: unknown) => any;
@@ -0,0 +1,17 @@
1
+ import { isArray } from '../is/is-array.js';
2
+ import { isPrimitive } from '../is/is-primitive.js';
3
+
4
+ /**
5
+ * @description
6
+ * in develop, there are many cases to clone a string/number/object/array
7
+ * this util is planning to resolve it
8
+ */
9
+ var clone = function clone(value) {
10
+ 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);
15
+ };
16
+
17
+ export { clone };
@@ -0,0 +1,23 @@
1
+ import { type Callable } from "../hooks/use-event";
2
+ export interface Debounced<T extends Callable> {
3
+ /**
4
+ * @description
5
+ * value trigger
6
+ */
7
+ next: (...args: Parameters<T>) => void;
8
+ /**
9
+ * @description
10
+ * complete current debounce/throttle function
11
+ */
12
+ flush: () => void;
13
+ /**
14
+ * @description
15
+ * ignore any value after call cancel
16
+ */
17
+ abort: () => void;
18
+ }
19
+ export type Debouncer<T extends Callable, R extends Array<unknown> = Parameters<T>> = {
20
+ callback: (...args: R) => ReturnType<T>;
21
+ pipe: (...args: Parameters<T>) => R | Promise<R>;
22
+ };
23
+ export declare const debounce: <T extends Callable, R extends Array<unknown> = Parameters<T>>(debouncer: Debouncer<T, R> | T, wait: number) => Debounced<T>;
@@ -0,0 +1,32 @@
1
+ import { debounceTime } from 'rxjs';
2
+ import { isFunction } from '../is/is-function.js';
3
+ import { Waitable } from './waitable.js';
4
+
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;
14
+ var waiter = new Waitable({
15
+ callback: callback,
16
+ pipe: pipe,
17
+ timer: debounceTime(wait)
18
+ });
19
+ return {
20
+ next: function next() {
21
+ return waiter.next.apply(waiter, arguments);
22
+ },
23
+ flush: function flush() {
24
+ return waiter.flush();
25
+ },
26
+ abort: function abort() {
27
+ return waiter.abort();
28
+ }
29
+ };
30
+ };
31
+
32
+ export { debounce };
@@ -0,0 +1,7 @@
1
+ import type { EffectCallback } from "react";
2
+ import type { ThenableEffectCallback } from "../types";
3
+ /**
4
+ * @description
5
+ * call thenable effect
6
+ */
7
+ export declare const effect: (callable: ThenableEffectCallback) => ReturnType<EffectCallback>;
@@ -0,0 +1,16 @@
1
+ import { isThenable } from '../is/is-thenable.js';
2
+
3
+ /**
4
+ * @description
5
+ * call thenable effect
6
+ */
7
+ var effect = function effect(callable) {
8
+ var called = callable();
9
+ // if result is void
10
+ if (!called) return void 0;
11
+ // if result is promise like, return void
12
+ if (isThenable(called)) return void 0;
13
+ return called;
14
+ };
15
+
16
+ export { effect };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description
3
+ * exclude any value from array
4
+ *
5
+ * for performance, avoid using `Array.includes`, replace with `Set`
6
+ *
7
+ * @example
8
+ * exclude([1, 2, 3, 4, 5], [2, 4]) // [1, 3, 5]
9
+ */
10
+ export declare const exclude: <T, E = unknown>(value: Array<T>, _excludeBy: Array<E>) => Array<Exclude<T, E>>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description
3
+ * exclude any value from array
4
+ *
5
+ * for performance, avoid using `Array.includes`, replace with `Set`
6
+ *
7
+ * @example
8
+ * exclude([1, 2, 3, 4, 5], [2, 4]) // [1, 3, 5]
9
+ */
10
+ var exclude = function exclude(value, _excludeBy) {
11
+ var excludeBy = new Set(_excludeBy);
12
+ // @ts-ignore
13
+ return value.filter(function (item) {
14
+ return !excludeBy.has(item);
15
+ });
16
+ };
17
+
18
+ export { exclude };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns an array of numbers, starting at `from` and ending at `to`.
3
+ * @param from number
4
+ * @param to number
5
+ * @returns number[]
6
+ */
7
+ export declare const range: (from: number, to: number) => number[];
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns an array of numbers, starting at `from` and ending at `to`.
3
+ * @param from number
4
+ * @param to number
5
+ * @returns number[]
6
+ */
7
+ var range = function range(from, to) {
8
+ var length = Math.max(to - from + 1, 0);
9
+ return Array.from({
10
+ length: length
11
+ }, function (_, index) {
12
+ return index + from;
13
+ });
14
+ };
15
+
16
+ export { range };
@@ -0,0 +1,6 @@
1
+ import type { Voidable } from "../types";
2
+ /**
3
+ * @description
4
+ * set inline style util
5
+ */
6
+ export declare const setStyle: (target: HTMLElement, styles: Voidable<Partial<CSSStyleDeclaration>>) => Partial<CSSStyleDeclaration>;
@@ -0,0 +1,21 @@
1
+ import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+
3
+ /**
4
+ * @description
5
+ * set inline style util
6
+ */
7
+ var setStyle = function setStyle(target, styles) {
8
+ if (!styles) return {};
9
+ return Object.entries(styles).reduce(function (prev, _ref) {
10
+ var _ref2 = _slicedToArray(_ref, 2),
11
+ key = _ref2[0],
12
+ value = _ref2[1];
13
+ // @ts-ignore
14
+ prev[key] = target.style[key];
15
+ // @ts-ignore
16
+ target.style[key] = value;
17
+ return prev;
18
+ }, {});
19
+ };
20
+
21
+ export { setStyle };
@@ -0,0 +1,5 @@
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 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>;
@@ -0,0 +1,32 @@
1
+ import { Waitable } from './waitable.js';
2
+ import { isFunction } from '../is/is-function.js';
3
+ import { throttleTime } from 'rxjs';
4
+
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;
14
+ var waiter = new Waitable({
15
+ callback: callback,
16
+ pipe: pipe,
17
+ timer: throttleTime(wait)
18
+ });
19
+ return {
20
+ next: function next() {
21
+ return waiter.next.apply(waiter, arguments);
22
+ },
23
+ flush: function flush() {
24
+ return waiter.flush();
25
+ },
26
+ abort: function abort() {
27
+ return waiter.abort();
28
+ }
29
+ };
30
+ };
31
+
32
+ export { throttle };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @description
3
+ * options
4
+ */
5
+ type Options = {
6
+ /**
7
+ * @description
8
+ * separator
9
+ * only effect in `value is string`, value would be split by separator
10
+ */
11
+ separator?: string;
12
+ };
13
+ /**
14
+ * @description
15
+ * convert any type data to a array
16
+ */
17
+ export declare const toArray: <T extends unknown = unknown>(value: T | Array<T>, { separator }?: Options) => Array<T>;
18
+ export {};
@@ -0,0 +1,25 @@
1
+ import { typeof as _typeof } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { isVoid } from '../is/is-void.js';
3
+
4
+ /**
5
+ * @description
6
+ * convert any type data to a array
7
+ */
8
+ var toArray = function toArray(value) {
9
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
10
+ separator = _ref.separator;
11
+ if (Array.isArray(value)) {
12
+ return value;
13
+ }
14
+ switch (_typeof(value)) {
15
+ case "string":
16
+ if (isVoid(separator)) {
17
+ return [value];
18
+ }
19
+ return value.split(separator);
20
+ default:
21
+ return [value];
22
+ }
23
+ };
24
+
25
+ export { toArray };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * convert to formData
4
+ */
5
+ export declare const toFormData: (data: unknown) => FormData;
@@ -0,0 +1,27 @@
1
+ import { slicedToArray as _slicedToArray } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { isArray } from '../is/is-array.js';
3
+
4
+ /**
5
+ * @description
6
+ * convert to formData
7
+ */
8
+ var toFormData = function toFormData(data) {
9
+ return Object.entries(data !== null && data !== void 0 ? data : {}).reduce(function (prev, _ref) {
10
+ var _ref2 = _slicedToArray(_ref, 2),
11
+ key = _ref2[0],
12
+ value = _ref2[1];
13
+ // support key-value array data
14
+ // if value is { list: [ 11, 22 ] }
15
+ // like prev.append('list[]', 11);
16
+ if (isArray(value)) {
17
+ value.forEach(function (item) {
18
+ prev.append("".concat(key, "[]"), item);
19
+ });
20
+ return prev;
21
+ }
22
+ prev.append(key, value);
23
+ return prev;
24
+ }, new FormData());
25
+ };
26
+
27
+ export { toFormData };
@@ -0,0 +1 @@
1
+ export declare const toFunction: <T extends Function>(value: unknown) => T;
@@ -0,0 +1,13 @@
1
+ import { isFunction } from '../is/is-function.js';
2
+
3
+ var toFunction = function toFunction(value) {
4
+ var _isFunction = isFunction(value);
5
+ if (_isFunction) {
6
+ return value;
7
+ }
8
+ return function () {
9
+ return value;
10
+ };
11
+ };
12
+
13
+ export { toFunction };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * toggle api
3
+ * @description
4
+ * when list has current key, remove it, otherwise add it
5
+ *
6
+ * return a copy of list
7
+ */
8
+ export declare const toggle: <R, T extends Iterable<R>>(value: T, key: R) => T;
@@ -0,0 +1,30 @@
1
+ import { isSet } from '../is/is-set.js';
2
+
3
+ /**
4
+ * toggle api
5
+ * @description
6
+ * when list has current key, remove it, otherwise add it
7
+ *
8
+ * return a copy of list
9
+ */
10
+ var toggle = function toggle(value, key) {
11
+ if (isSet(value)) {
12
+ var _copied = new Set(value);
13
+ if (_copied.has(key)) {
14
+ _copied["delete"](key);
15
+ } else {
16
+ _copied.add(key);
17
+ }
18
+ return _copied;
19
+ }
20
+ var copied = Array.from(value);
21
+ var index = copied.indexOf(key);
22
+ if (index === -1) {
23
+ copied.push(key);
24
+ } else {
25
+ copied.splice(index, 1);
26
+ }
27
+ return copied;
28
+ };
29
+
30
+ export { toggle };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @description
3
+ * unique
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[];