@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.
- package/dist/_virtual/_rollupPluginBabelHelpers.js +138 -0
- package/dist/dom/contains.d.ts +1 -0
- package/dist/dom/contains.js +20 -0
- package/dist/dom/index.d.ts +3 -0
- package/dist/dom/index.js +2 -0
- package/dist/dom/scroll-to.d.ts +19 -0
- package/dist/dom/scroll-to.js +69 -0
- package/dist/hooks/use-boolean.d.ts +19 -0
- package/dist/hooks/use-boolean.js +34 -0
- package/dist/hooks/use-controlled-state.d.ts +17 -0
- package/dist/hooks/use-controlled-state.js +40 -0
- package/dist/hooks/use-counter.d.ts +33 -0
- package/dist/hooks/use-counter.js +59 -0
- package/dist/hooks/use-debounce-callback.d.ts +18 -0
- package/dist/hooks/use-debounce-callback.js +81 -0
- package/dist/hooks/use-default.d.ts +8 -0
- package/dist/hooks/use-default.js +14 -0
- package/dist/hooks/use-device-pixel-ratio.d.ts +6 -0
- package/dist/hooks/use-device-pixel-ratio.js +20 -0
- package/dist/hooks/use-event.d.ts +2 -0
- package/dist/hooks/use-event.js +12 -0
- package/dist/hooks/use-focus.d.ts +15 -0
- package/dist/hooks/use-focus.js +31 -0
- package/dist/hooks/use-force-update.d.ts +7 -0
- package/dist/hooks/use-force-update.js +21 -0
- package/dist/hooks/use-hover.d.ts +8 -0
- package/dist/hooks/use-hover.js +25 -0
- package/dist/hooks/use-identity.d.ts +5 -0
- package/dist/hooks/use-identity.js +20 -0
- package/dist/hooks/use-image-loader.d.ts +12 -0
- package/dist/hooks/use-image-loader.js +54 -0
- package/dist/hooks/use-media-query.d.ts +7 -0
- package/dist/hooks/use-memorable.d.ts +1 -0
- package/dist/hooks/use-memorable.js +14 -0
- package/dist/hooks/use-mount.d.ts +8 -0
- package/dist/hooks/use-mount.js +16 -0
- package/dist/hooks/use-mounted.d.ts +8 -0
- package/dist/hooks/use-mounted.js +16 -0
- package/dist/hooks/use-mutate-observer.d.ts +1 -0
- package/dist/hooks/use-mutate-observer.js +28 -0
- package/dist/hooks/use-raf.d.ts +7 -0
- package/dist/hooks/use-raf.js +26 -0
- package/dist/hooks/use-reactive.d.ts +6 -0
- package/dist/hooks/use-refs.d.ts +5 -0
- package/dist/hooks/use-refs.js +31 -0
- package/dist/hooks/use-scroll-locker.d.ts +5 -0
- package/dist/hooks/use-scroll-locker.js +92 -0
- package/dist/hooks/use-scrollable.d.ts +17 -0
- package/dist/hooks/use-scrollable.js +43 -0
- package/dist/hooks/use-throttle-callback.d.ts +18 -0
- package/dist/hooks/use-throttle-callback.js +83 -0
- package/dist/hooks/use-timeout.d.ts +10 -0
- package/dist/hooks/use-timeout.js +68 -0
- package/dist/hooks/use-togglable.d.ts +48 -0
- package/dist/hooks/use-togglable.js +177 -0
- package/dist/hooks/use-update-effect.d.ts +3 -0
- package/dist/hooks/use-update-effect.js +19 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +52 -0
- package/dist/is/is-array.d.ts +5 -0
- package/dist/is/is-array.js +9 -0
- package/dist/is/is-complex.d.ts +5 -0
- package/dist/is/is-complex.js +11 -0
- package/dist/is/is-dom-usable.d.ts +5 -0
- package/dist/is/is-dom-usable.js +9 -0
- package/dist/is/is-empty.d.ts +7 -0
- package/dist/is/is-empty.js +25 -0
- package/dist/is/is-function.d.ts +5 -0
- package/dist/is/is-function.js +9 -0
- package/dist/is/is-map.d.ts +5 -0
- package/dist/is/is-mobile.d.ts +5 -0
- package/dist/is/is-mobile.js +13 -0
- package/dist/is/is-null.d.ts +5 -0
- package/dist/is/is-null.js +9 -0
- package/dist/is/is-overflow.d.ts +5 -0
- package/dist/is/is-overflow.js +14 -0
- package/dist/is/is-pointer-usable.d.ts +5 -0
- package/dist/is/is-primitive.d.ts +5 -0
- package/dist/is/is-primitive.js +9 -0
- package/dist/is/is-refable.d.ts +5 -0
- package/dist/is/is-refable.js +34 -0
- package/dist/is/is-set.d.ts +5 -0
- package/dist/is/is-set.js +9 -0
- package/dist/is/is-state-getter.d.ts +6 -0
- package/dist/is/is-state-getter.js +9 -0
- package/dist/is/is-style-element.d.ts +5 -0
- package/dist/is/is-style-element.js +9 -0
- package/dist/is/is-thenable.d.ts +5 -0
- package/dist/is/is-thenable.js +9 -0
- package/dist/is/is-undefined.d.ts +5 -0
- package/dist/is/is-undefined.js +9 -0
- package/dist/is/is-void.d.ts +5 -0
- package/dist/is/is-void.js +12 -0
- package/dist/types/first.d.ts +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/last.d.ts +1 -0
- package/dist/types/nullable.d.ts +5 -0
- package/dist/types/partialable.d.ts +5 -0
- package/dist/types/required-in.d.ts +5 -0
- package/dist/types/state.d.ts +10 -0
- package/dist/types/thenable-effect-callback.d.ts +6 -0
- package/dist/types/voidable.d.ts +7 -0
- package/dist/utils/chain.d.ts +2 -0
- package/dist/utils/chain.js +15 -0
- package/dist/utils/clamp.d.ts +9 -0
- package/dist/utils/clamp.js +13 -0
- package/dist/utils/clone.d.ts +6 -0
- package/dist/utils/clone.js +17 -0
- package/dist/utils/debounce.d.ts +23 -0
- package/dist/utils/debounce.js +32 -0
- package/dist/utils/effect.d.ts +7 -0
- package/dist/utils/effect.js +16 -0
- package/dist/utils/exclude.d.ts +10 -0
- package/dist/utils/exclude.js +18 -0
- package/dist/utils/range.d.ts +7 -0
- package/dist/utils/range.js +16 -0
- package/dist/utils/set-style.d.ts +6 -0
- package/dist/utils/set-style.js +21 -0
- package/dist/utils/throttle.d.ts +5 -0
- package/dist/utils/throttle.js +32 -0
- package/dist/utils/to-array.d.ts +18 -0
- package/dist/utils/to-array.js +25 -0
- package/dist/utils/to-form-data.d.ts +5 -0
- package/dist/utils/to-form-data.js +27 -0
- package/dist/utils/to-function.d.ts +1 -0
- package/dist/utils/to-function.js +13 -0
- package/dist/utils/toggle.d.ts +8 -0
- package/dist/utils/toggle.js +30 -0
- package/dist/utils/unique.d.ts +10 -0
- package/dist/utils/unique.js +16 -0
- package/dist/utils/waitable.d.ts +36 -0
- package/dist/utils/waitable.js +90 -0
- 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,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,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,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,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,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,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,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,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,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 };
|