@superutils/core 1.0.3 → 1.0.5
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/index.d.ts +74 -35
- package/dist/index.js +63 -46
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ type Curry<TData, TParams extends unknown[]> = <TArgs extends unknown[]>(...args
|
|
|
27
27
|
/**
|
|
28
28
|
* Deferred function config
|
|
29
29
|
*/
|
|
30
|
-
interface
|
|
30
|
+
interface DeferredOptions<ThisArg = unknown> {
|
|
31
31
|
leading?: boolean | 'global';
|
|
32
32
|
onError?: (err: unknown) => ValueOrPromise<unknown>;
|
|
33
33
|
thisArg?: ThisArg;
|
|
@@ -283,7 +283,7 @@ type CurriedArgs<TArgs extends unknown[], TArgsIsFinite extends boolean, TFunc e
|
|
|
283
283
|
*
|
|
284
284
|
*/
|
|
285
285
|
declare const deferred: {
|
|
286
|
-
<TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?:
|
|
286
|
+
<TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?: DeferredOptions<ThisArg>): (...args: TArgs) => void;
|
|
287
287
|
defaults: {
|
|
288
288
|
/**
|
|
289
289
|
* Set the default value of argument `leading` for the `deferred` function.
|
|
@@ -400,7 +400,7 @@ declare const isArrLike: (x: any) => x is typeof x extends (infer Value)[] ? Val
|
|
|
400
400
|
* Check if value is convertible to an array by using `Array.from(x)` even if it comes from a different realm
|
|
401
401
|
* (eg: iframe, iframes, worker contexts, node vm contexts, browser extensions).
|
|
402
402
|
*
|
|
403
|
-
* Caution: much slower than {@link isArrLike
|
|
403
|
+
* Caution: much slower than {@link isArrLike} due to use of `Object.prototype.toString.call()`
|
|
404
404
|
*/
|
|
405
405
|
declare const isArrLikeSafe: <T = unknown, MapKey = unknown>(x: unknown) => x is Set<T> | Map<MapKey, T> | T[];
|
|
406
406
|
/** Check if all values in the array are unique */
|
|
@@ -644,7 +644,7 @@ declare const is: {
|
|
|
644
644
|
declare function noop(): void;
|
|
645
645
|
declare function noopAsync(): Promise<void>;
|
|
646
646
|
|
|
647
|
-
type
|
|
647
|
+
type ThrottleOptions<ThisArg = unknown> = {
|
|
648
648
|
onError?: (err: unknown) => ValueOrPromise<unknown>;
|
|
649
649
|
thisArg?: ThisArg;
|
|
650
650
|
trailing?: boolean;
|
|
@@ -662,7 +662,7 @@ type ThrottleConfig<ThisArg = unknown> = {
|
|
|
662
662
|
* @param config.trailing (optional) whether to enable trailing edge execution. Default: `true`
|
|
663
663
|
*/
|
|
664
664
|
declare const throttled: {
|
|
665
|
-
<TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?:
|
|
665
|
+
<TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?: ThrottleOptions<ThisArg>): (...args: TArgs) => void;
|
|
666
666
|
/**
|
|
667
667
|
* Set the default values
|
|
668
668
|
* This change is applicable application-wide and only applies to any new invocation of `throttle()`.
|
|
@@ -712,25 +712,34 @@ declare const objClean: <T extends Record<PropertyKey, unknown>, Key extends key
|
|
|
712
712
|
* Deep-copy an object to another object
|
|
713
713
|
*
|
|
714
714
|
* @param input input object
|
|
715
|
+
* @param _output (optional) output object
|
|
715
716
|
* @param ignoreKeys (optional) input peroperties to be ignored. Prevents output's property to be overriden.
|
|
716
717
|
*
|
|
717
718
|
* For child object properties use "." (dot) separated path.
|
|
718
719
|
*
|
|
719
720
|
* Eg: `"child.grandchild1"` where input is `{ child: { grandchild1: 1, grandchild2: 2 }}`
|
|
720
721
|
*
|
|
721
|
-
* @param
|
|
722
|
-
*
|
|
722
|
+
* @param override (optional) whether to allow override output properties.
|
|
723
|
+
* This will only be used if `output` object is provided and has own property.
|
|
723
724
|
* Accepted values:
|
|
724
|
-
* `true`: input property will override output property
|
|
725
|
-
* `false`: no overriding if output contains the property. Even if the property value is `undefined`.
|
|
726
|
-
* `"empty"`: only allow overriding output property if it's value is empty by using {@link isEmpty}.
|
|
725
|
+
* - `true`: input property will override output property
|
|
726
|
+
* - `false`: no overriding if output contains the property. Even if the property value is `undefined`.
|
|
727
|
+
* - `"empty"`: only allow overriding output property if it's value is empty by using {@link isEmpty}.
|
|
728
|
+
* - `function`: decide whether to override on a per property basis.
|
|
729
|
+
*
|
|
730
|
+
* Function Arguments:
|
|
731
|
+
* 1. key: current property name/key
|
|
732
|
+
* 2. outputValue: `output` property value
|
|
733
|
+
* 3. inputValue: `input` property value
|
|
727
734
|
*
|
|
728
735
|
* Default: `false`
|
|
729
736
|
*
|
|
737
|
+
* @param reverse (optional) whether to reverse sort object properties. Default: `false`
|
|
738
|
+
*
|
|
730
739
|
*
|
|
731
740
|
* @returns copied and/or merged object
|
|
732
741
|
*/
|
|
733
|
-
declare const objCopy: <Key extends
|
|
742
|
+
declare const objCopy: <Key extends PropertyKey, InValue, OutValue, IgnoredKey extends Key | string>(input: Record<Key, InValue>, output?: Record<PropertyKey, OutValue>, ignoreKeys?: IgnoredKey[] | Set<IgnoredKey>, override?: boolean | "empty" | ((key: Key, outputValue: OutValue, inputValue: InValue) => boolean), recursive?: boolean) => Record<PropertyKey, unknown>;
|
|
734
743
|
|
|
735
744
|
/**
|
|
736
745
|
* Creates an object from an array of keys and a corresponding array of values.
|
|
@@ -760,6 +769,15 @@ declare const objCopy: <Key extends string | symbol, T extends Record<Key, unkno
|
|
|
760
769
|
*/
|
|
761
770
|
declare const objCreate: <V, K extends PropertyKey, RV, RK extends PropertyKey, Result extends Record<K | RK, V | RV>>(keys?: K[], values?: V[], result?: Result) => Result;
|
|
762
771
|
|
|
772
|
+
/**
|
|
773
|
+
* Checks if all the supplied keys exist in an object
|
|
774
|
+
*
|
|
775
|
+
* @param input
|
|
776
|
+
* @param keys
|
|
777
|
+
* @param equireValue (optional) whether each property should have some value.
|
|
778
|
+
*/
|
|
779
|
+
declare function objHasKeys(input?: object | unknown[], keys?: PropertyKey[], requireValue?: boolean): boolean;
|
|
780
|
+
|
|
763
781
|
/**
|
|
764
782
|
* Get object property names/keys
|
|
765
783
|
*
|
|
@@ -837,10 +855,11 @@ declare const objWithoutKeys: (input: unknown, keys: string[], output?: Record<P
|
|
|
837
855
|
declare const arrReadOnly: <T>(arr: T[], config?: Omit<ReadOnlyConfig<T[]>, "revoke">) => T[];
|
|
838
856
|
|
|
839
857
|
/**
|
|
858
|
+
* @ignore exclude from documentation
|
|
840
859
|
* Helper class for creating read-only arrays.
|
|
841
860
|
*
|
|
842
861
|
* Caution: This class can by itself only make the array partially read-only.
|
|
843
|
-
* Use {@link arrReadOnly
|
|
862
|
+
* Use {@link arrReadOnly} instead.
|
|
844
863
|
*/
|
|
845
864
|
declare class ReadOnlyArrayHelper<T> extends Array<T> {
|
|
846
865
|
readonly config: Omit<ReadOnlyConfig<T[]>, 'revoke'>;
|
|
@@ -852,16 +871,6 @@ declare class ReadOnlyArrayHelper<T> extends Array<T> {
|
|
|
852
871
|
shift: () => T;
|
|
853
872
|
splice: (..._ignoredArgs: unknown[]) => never[];
|
|
854
873
|
unshift: (..._ignoredArgs: T[]) => number;
|
|
855
|
-
reduce: {
|
|
856
|
-
(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
|
|
857
|
-
(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
|
|
858
|
-
<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
|
|
859
|
-
};
|
|
860
|
-
reduceRight: {
|
|
861
|
-
(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T): T;
|
|
862
|
-
(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;
|
|
863
|
-
<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
|
|
864
|
-
};
|
|
865
874
|
}
|
|
866
875
|
|
|
867
876
|
/**
|
|
@@ -905,9 +914,9 @@ declare const arrReverse: <T = unknown>(arr: T[], reverse?: boolean, newArray?:
|
|
|
905
914
|
* const map = arrToMap(arr, (item: Item) => item.key, 1) // Map<number, Item>
|
|
906
915
|
* ```
|
|
907
916
|
*/
|
|
917
|
+
declare function arrToMap<T extends unknown[], FlatDepth extends number = 0, MapItem = FlatArray<T, FlatDepth>, KeyProp extends keyof MapItem = keyof MapItem>(arr: T, key: KeyProp, flatDepth?: FlatDepth): Map<MapItem[KeyProp], MapItem>;
|
|
908
918
|
declare function arrToMap<T extends unknown[], FlatDepth extends number = 0>(arr: T, flatDepth?: FlatDepth): Map<number, FlatArray<T, FlatDepth>>;
|
|
909
919
|
declare function arrToMap<T extends unknown[], FlatDepth extends number = 0, MapItem = FlatArray<T, FlatDepth>, MapKey = unknown>(arr: T, key: (item: MapItem, index: number, flatArr: MapItem[]) => MapKey, flatDepth?: FlatDepth): Map<MapKey, MapItem>;
|
|
910
|
-
declare function arrToMap<T extends unknown[], FlatDepth extends number = 0, MapItem = FlatArray<T, FlatDepth>, KeyProp extends keyof MapItem = keyof MapItem>(arr: T, key: KeyProp, flatDepth?: FlatDepth): Map<MapItem[KeyProp], MapItem>;
|
|
911
920
|
|
|
912
921
|
/**
|
|
913
922
|
* @function arrUnique
|
|
@@ -987,6 +996,12 @@ type SearchOptions<K, V, AsMap extends boolean = false> = {
|
|
|
987
996
|
*
|
|
988
997
|
* @param data
|
|
989
998
|
* @param predicate callback function to filter values
|
|
999
|
+
* Parameters:
|
|
1000
|
+
* 1. `item`: current item
|
|
1001
|
+
* 2. `key`: index/key
|
|
1002
|
+
* 3. `data`: value provided in the first argument (`data`)
|
|
1003
|
+
* @param limit (optional) limit number of results
|
|
1004
|
+
* @param arArray
|
|
990
1005
|
*
|
|
991
1006
|
* @returns new Map with filtered items
|
|
992
1007
|
*
|
|
@@ -1007,7 +1022,7 @@ type SearchOptions<K, V, AsMap extends boolean = false> = {
|
|
|
1007
1022
|
* // }
|
|
1008
1023
|
* ```
|
|
1009
1024
|
*/
|
|
1010
|
-
declare const filter: <K, V, AsArray extends boolean = false, Result = AsArray extends true ? V[] : Map<K, V>>(data: IterableList<K, V>, predicate: (
|
|
1025
|
+
declare const filter: <K, V, AsArray extends boolean = false, Result = AsArray extends true ? V[] : Map<K, V>>(data: IterableList<K, V>, predicate: (item: V, key: K, data: IterableList<K, V>) => boolean, limit?: number, asArray?: AsArray, result?: Map<K, V>) => Result;
|
|
1011
1026
|
|
|
1012
1027
|
/**
|
|
1013
1028
|
* Finds a first item matching criteria in an {@link IterableList}.
|
|
@@ -1119,16 +1134,16 @@ declare const search: {
|
|
|
1119
1134
|
<K, V, AsMap extends boolean = true, Result = AsMap extends true ? Map<K, V> : V[]>(data: IterableList<K, V>, options: SearchOptions<K, V, AsMap>): Result;
|
|
1120
1135
|
defaultOptions: Pick<Required<SearchOptions<unknown, unknown, true>>, "matchAll" | "limit" | "asMap" | "ignoreCase" | "matchExact">;
|
|
1121
1136
|
};
|
|
1122
|
-
/** Utility for use with {@link search
|
|
1137
|
+
/** Utility for use with {@link search} function */
|
|
1123
1138
|
declare function matchItemOrProp<K, V>(// extends Record<string, unknown>
|
|
1124
1139
|
{ query, ignoreCase, matchExact, transform, }: Pick<SearchOptions<K, V, boolean>, 'transform' | 'query' | 'ignoreCase' | 'matchExact'>, item: V, propertyName?: string): boolean;
|
|
1125
1140
|
|
|
1126
|
-
type
|
|
1141
|
+
type SliceMapTransform<Data, Value, Key> = (item: Value, key: Key, data: Data) => Value;
|
|
1127
1142
|
type SliceMapOptions<Data, Value, Key, AsMap extends boolean = false> = {
|
|
1128
1143
|
/** Whether to return the result as a Map (preserving original keys) or an Array */
|
|
1129
1144
|
asMap?: AsMap;
|
|
1130
|
-
/**
|
|
1131
|
-
transform?:
|
|
1145
|
+
/** Callback to transform each item from the selected range */
|
|
1146
|
+
transform?: SliceMapTransform<Data, Value, Key>;
|
|
1132
1147
|
/** End index (exclusive). Default: `undefined` (end of the list) */
|
|
1133
1148
|
end?: number;
|
|
1134
1149
|
/** Whether to exclude item if value is `undefined | null` */
|
|
@@ -1140,9 +1155,14 @@ type SliceMapOptions<Data, Value, Key, AsMap extends boolean = false> = {
|
|
|
1140
1155
|
* Slice an iterable list and map the values into an Array/Map
|
|
1141
1156
|
*
|
|
1142
1157
|
* @param data Array, Map, Set...
|
|
1143
|
-
* @param
|
|
1144
|
-
*
|
|
1145
|
-
*
|
|
1158
|
+
* @param options One of the following is required to create a new list:
|
|
1159
|
+
* 1. A callback function {@link SliceMapTransform} to transform all items.
|
|
1160
|
+
* 2. Advanced options {@link SliceMapOptions}.
|
|
1161
|
+
* @param options.asMap (optional) whether return a Map or Array.
|
|
1162
|
+
* @param options.end (optional) End index (exclusive). Default: `undefined` (end of the list)
|
|
1163
|
+
* @param options.ignoreEmpty (optional) Whether to exclude item if value is `undefined | null`
|
|
1164
|
+
* @param options.start (optional) Default: `0`
|
|
1165
|
+
* @param options.transform (optional)
|
|
1146
1166
|
*
|
|
1147
1167
|
* If callback throws error or returnes `undefined`, the item will be ignored.
|
|
1148
1168
|
*
|
|
@@ -1153,7 +1173,7 @@ type SliceMapOptions<Data, Value, Key, AsMap extends boolean = false> = {
|
|
|
1153
1173
|
*
|
|
1154
1174
|
* @returns Array/Map
|
|
1155
1175
|
*/
|
|
1156
|
-
declare const sliceMap: <Data extends IterableList, Key = Data extends IterableList<infer Key_1, unknown> ? Key_1 : never, Value = Data extends IterableList<unknown, infer Value_1> ? Value_1 : never, AsMap extends boolean = false
|
|
1176
|
+
declare const sliceMap: <Data extends IterableList, Key = Data extends IterableList<infer Key_1, unknown> ? Key_1 : never, Value = Data extends IterableList<unknown, infer Value_1> ? Value_1 : never, AsMap extends boolean = false, Result = AsMap extends false ? Value[] : Map<Key, Value>>(data: Data, options?: SliceMapOptions<Data, Value, Key, AsMap> | SliceMapTransform<Data, Value, Key>) => Result;
|
|
1157
1177
|
|
|
1158
1178
|
type EntryComparator<K, V> = (a: [K, V], b: [K, V]) => number;
|
|
1159
1179
|
type ArrayComparator<V> = (a: V, b: V) => number;
|
|
@@ -1267,6 +1287,13 @@ declare const mapJoin: <K, V>(...inputs: (Map<K, V> | [K, V][])[]) => Map<K, V>;
|
|
|
1267
1287
|
*/
|
|
1268
1288
|
declare const randomInt: (min?: number, max?: number) => number;
|
|
1269
1289
|
|
|
1290
|
+
/** Describes a number type with negative values only */
|
|
1291
|
+
type NegativeNumber<N extends number = number> = `${N}` extends `-${string}` ? N : never;
|
|
1292
|
+
/** Describes a number type with positive values excluding `0` */
|
|
1293
|
+
type PositiveNumber<N extends number = number> = `${N}` extends `-${string}` | '0' ? never : N;
|
|
1294
|
+
/** Describes a number type with positive values and `0` */
|
|
1295
|
+
type PositiveNumberWithZero<N extends number = number> = `${N}` extends `-${string}` ? never : N;
|
|
1296
|
+
|
|
1270
1297
|
/**
|
|
1271
1298
|
* Clears clutter from strings
|
|
1272
1299
|
*
|
|
@@ -1282,12 +1309,14 @@ declare const randomInt: (min?: number, max?: number) => number;
|
|
|
1282
1309
|
declare const clearClutter: (text: string, lineSeparator?: string) => string;
|
|
1283
1310
|
|
|
1284
1311
|
/**
|
|
1285
|
-
*
|
|
1312
|
+
* Copies text to browser clipboard.
|
|
1286
1313
|
*
|
|
1287
1314
|
* CAUTION:
|
|
1288
1315
|
* Based on browser security policy it may be required to invoke `copyToClipboard` from an user-generated event handler.
|
|
1289
1316
|
*
|
|
1290
|
-
*
|
|
1317
|
+
* Invoking from non-browser environment will already resolve with `0`.
|
|
1318
|
+
*
|
|
1319
|
+
* This function first attempts to use the modern, asynchronous Clipboard API (`navigator.clipboard.writeText`).
|
|
1291
1320
|
* If that fails or is unavailable, it falls back to the legacy `document.execCommand('copy')` method.
|
|
1292
1321
|
*
|
|
1293
1322
|
*
|
|
@@ -1317,4 +1346,14 @@ declare const EMAIL_REGEX: RegExp;
|
|
|
1317
1346
|
declare const HEX_REGEX: RegExp;
|
|
1318
1347
|
declare const HASH_REGEX: RegExp;
|
|
1319
1348
|
|
|
1320
|
-
|
|
1349
|
+
/**
|
|
1350
|
+
* Convert comma separated strings to array
|
|
1351
|
+
*
|
|
1352
|
+
* @param value value to convert
|
|
1353
|
+
* @param seperator (optional) only used when value is a string. Default: `","`
|
|
1354
|
+
*
|
|
1355
|
+
* @returns Array
|
|
1356
|
+
*/
|
|
1357
|
+
declare const strToArr: (value: unknown, seperator?: string) => string[];
|
|
1358
|
+
|
|
1359
|
+
export { type ArrayComparator, type AsyncFn, type CreateTuple, type CurriedArgs, type Curry, type DeferredOptions, type DropFirst, type DropFirstN, type DropLast, EMAIL_REGEX, type EntryComparator, type FindOptions, HASH_REGEX, HEX_REGEX, type IfPromiseAddValue, type IsFiniteTuple, type IsOptional, type IterableList, type KeepFirst, type KeepFirstN, type KeepOptionals, type KeepRequired, type MakeOptional, type MinLength, type NegativeNumber, type OptionalIf, type PositiveNumber, type PositiveNumberWithZero, type ReadOnlyAllowAddFn, ReadOnlyArrayHelper, type ReadOnlyConfig, type SearchOptions, type Slice, type SliceMapOptions, type SliceMapTransform, type SortOptions, type ThrottleOptions, type TimeoutId, type TupleMaxLength, type TupleWithAlt, type ValueOrFunc, type ValueOrPromise, arrReadOnly, arrReverse, arrToMap, arrUnique, asAny, clearClutter, copyToClipboard, curry, debounce, deferred, fallbackIfFails, filter, find, forceCast, getEntries, getKeys, getSize, getUrlParam, getValues, is, isArr, isArr2D, isArrLike, isArrLikeSafe, isArrObj, isArrUnique, isAsyncFn, isBool, isDate, isDateValid, isDefined, isEmpty, isEmptySafe, isEnvBrowser, isEnvNode, isEnvTouchable, isError, isFn, isInteger, isMap, isMapObj, isNumber, isObj, isPositiveInteger, isPositiveNumber, isPromise, isRegExp, isSet, isStr, isSymbol, isUint8Arr, isUrl, isUrlValid, mapJoin, matchItemOrProp, noop, noopAsync, objClean, objCopy, objCreate, objHasKeys, objKeys, objReadOnly, objSetProp, objSetPropUndefined, objSort, objWithoutKeys, randomInt, reverse, search, sliceMap, sort, strToArr, throttled, toDatetimeLocal };
|
package/dist/index.js
CHANGED
|
@@ -102,17 +102,14 @@ var isEmptySafe = (x, numberableOnly = false) => {
|
|
|
102
102
|
var isEmpty_default = isEmpty;
|
|
103
103
|
|
|
104
104
|
// src/is/isEnv.ts
|
|
105
|
-
var isEnvBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
105
|
+
var isEnvBrowser = () => typeof window !== "undefined" && typeof (window == null ? void 0 : window.document) !== "undefined";
|
|
106
106
|
var isEnvNode = () => {
|
|
107
107
|
var _a;
|
|
108
108
|
return typeof process !== "undefined" && ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) != null;
|
|
109
109
|
};
|
|
110
110
|
var isEnvTouchable = () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} catch (_) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
111
|
+
var _a, _b;
|
|
112
|
+
return typeof window !== "undefined" && "ontouchstart" in ((_b = (_a = window == null ? void 0 : window.document) == null ? void 0 : _a.documentElement) != null ? _b : {});
|
|
116
113
|
};
|
|
117
114
|
|
|
118
115
|
// src/noop.ts
|
|
@@ -201,14 +198,13 @@ var fallbackIfFails = (target, args, fallbackValue) => {
|
|
|
201
198
|
try {
|
|
202
199
|
result = !isFn(target) ? target : target(...isFn(args) ? args() : args);
|
|
203
200
|
if (!isPromise(result)) return result;
|
|
204
|
-
|
|
201
|
+
return result.catch((err) => getAltValCb(err, fallbackValue));
|
|
205
202
|
} catch (error) {
|
|
206
|
-
|
|
203
|
+
return getAltValCb(error, fallbackValue);
|
|
207
204
|
}
|
|
208
|
-
return result;
|
|
209
205
|
};
|
|
210
206
|
var fallbackIfFails_default = fallbackIfFails;
|
|
211
|
-
var getAltValCb = (fallbackValue) =>
|
|
207
|
+
var getAltValCb = (error, fallbackValue) => isFn(fallbackValue) ? fallbackValue(error) : fallbackValue;
|
|
212
208
|
|
|
213
209
|
// src/deferred.ts
|
|
214
210
|
var deferred = (callback, delay = 50, config = {}) => {
|
|
@@ -299,7 +295,7 @@ var objClean = (obj, keys, ignoreIfNotExist = true) => {
|
|
|
299
295
|
const result = {};
|
|
300
296
|
if (!isObj(obj) || !isArr(keys)) return result;
|
|
301
297
|
const uniqKeys = arrUnique(
|
|
302
|
-
keys.map((x) =>
|
|
298
|
+
keys.map((x) => String(x).split(".")[0])
|
|
303
299
|
).sort();
|
|
304
300
|
for (const key of uniqKeys) {
|
|
305
301
|
if (ignoreIfNotExist && !obj.hasOwnProperty(key)) continue;
|
|
@@ -339,8 +335,8 @@ var objKeys_default = objKeys;
|
|
|
339
335
|
// src/obj/objCopy.ts
|
|
340
336
|
var clone = (value, fallback = "null") => JSON.parse(fallbackIfFails_default(JSON.stringify, [value], fallback));
|
|
341
337
|
var objCopy = (input, output, ignoreKeys, override = false, recursive = true) => {
|
|
342
|
-
|
|
343
|
-
if (!isObj(input)) return
|
|
338
|
+
const _output = isObj(output) ? output : {};
|
|
339
|
+
if (!isObj(input)) return _output;
|
|
344
340
|
const _ignoreKeys = new Set(ignoreKeys != null ? ignoreKeys : []);
|
|
345
341
|
const inKeys = objKeys_default(input, true, true).filter(
|
|
346
342
|
(x) => !_ignoreKeys.has(x)
|
|
@@ -348,14 +344,14 @@ var objCopy = (input, output, ignoreKeys, override = false, recursive = true) =>
|
|
|
348
344
|
for (const _key of inKeys) {
|
|
349
345
|
const key = _key;
|
|
350
346
|
const value = input[key];
|
|
351
|
-
const skip =
|
|
347
|
+
const skip = _output.hasOwnProperty(key) && (override === "empty" ? !isEmpty(_output[key]) : isFn(override) ? !override(key, _output[key], value) : true);
|
|
352
348
|
if (skip) continue;
|
|
353
349
|
const isPrimitive = [void 0, null, Infinity, NaN].includes(asAny(value)) || !isObj(value, false);
|
|
354
350
|
if (isPrimitive) {
|
|
355
|
-
|
|
351
|
+
_output[key] = value;
|
|
356
352
|
continue;
|
|
357
353
|
}
|
|
358
|
-
|
|
354
|
+
_output[key] = (() => {
|
|
359
355
|
switch (Object.getPrototypeOf(value)) {
|
|
360
356
|
case Array.prototype:
|
|
361
357
|
return clone(value, "[]");
|
|
@@ -385,19 +381,19 @@ var objCopy = (input, output, ignoreKeys, override = false, recursive = true) =>
|
|
|
385
381
|
}
|
|
386
382
|
if (isSymbol(key) || !recursive) return clone(value);
|
|
387
383
|
const ignoreChildKeys = [..._ignoreKeys].map(
|
|
388
|
-
(x) =>
|
|
384
|
+
(x) => String(x).startsWith(String(key).concat(".")) && String(x).split(String(key).concat("."))[1]
|
|
389
385
|
).filter(Boolean);
|
|
390
386
|
if (!ignoreChildKeys.length) return clone(value);
|
|
391
387
|
return objCopy(
|
|
392
388
|
value,
|
|
393
|
-
|
|
389
|
+
_output[key],
|
|
394
390
|
ignoreChildKeys,
|
|
395
391
|
override,
|
|
396
392
|
recursive
|
|
397
393
|
);
|
|
398
394
|
})();
|
|
399
395
|
}
|
|
400
|
-
return
|
|
396
|
+
return _output;
|
|
401
397
|
};
|
|
402
398
|
|
|
403
399
|
// src/obj/objCreate.ts
|
|
@@ -410,6 +406,16 @@ var objCreate = (keys = [], values = [], result) => {
|
|
|
410
406
|
return result;
|
|
411
407
|
};
|
|
412
408
|
|
|
409
|
+
// src/obj/objHasKeys.ts
|
|
410
|
+
function objHasKeys(input = {}, keys = [], requireValue = false) {
|
|
411
|
+
if (!isObj(input) || !isArr(keys)) return false;
|
|
412
|
+
for (const key of keys) {
|
|
413
|
+
if (!input.hasOwnProperty(key)) return false;
|
|
414
|
+
if (requireValue && isEmpty(input[key])) return false;
|
|
415
|
+
}
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
|
|
413
419
|
// src/obj/objReadOnly.ts
|
|
414
420
|
var objReadOnly = (obj, config) => {
|
|
415
421
|
if (!isObj(obj, false)) obj = {};
|
|
@@ -502,10 +508,10 @@ var ReadOnlyArrayHelper = class extends Array {
|
|
|
502
508
|
this.shift = () => this.ignoreOrThrow(this[0]);
|
|
503
509
|
this.splice = (..._ignoredArgs) => this.ignoreOrThrow([]);
|
|
504
510
|
this.unshift = (..._ignoredArgs) => this.ignoreOrThrow(this.length);
|
|
505
|
-
// fromAsync = super.fromAsync
|
|
506
|
-
this.reduce = super.reduce;
|
|
507
|
-
this.reduceRight = super.reduceRight;
|
|
508
511
|
}
|
|
512
|
+
// fromAsync = super.fromAsync
|
|
513
|
+
// reduce = super.reduce
|
|
514
|
+
// reduceRight = super.reduceRight
|
|
509
515
|
};
|
|
510
516
|
|
|
511
517
|
// src/arr/arrReverse.ts
|
|
@@ -533,9 +539,10 @@ function arrToMap(arr, key, flatDepth = 0) {
|
|
|
533
539
|
var arrUnique = (arr, flatDepth = 0) => !isArr(arr) ? [] : Array.from(new Set(arr.flat(flatDepth)));
|
|
534
540
|
|
|
535
541
|
// src/iterable/filter.ts
|
|
536
|
-
var filter = (data, predicate, limit
|
|
542
|
+
var filter = (data, predicate, limit, asArray, result) => {
|
|
537
543
|
var _a;
|
|
538
544
|
if (!isMap(result)) result = /* @__PURE__ */ new Map();
|
|
545
|
+
if (!isPositiveInteger(limit)) limit = Infinity;
|
|
539
546
|
for (const [key, item] of ((_a = data == null ? void 0 : data.entries) == null ? void 0 : _a.call(data)) || []) {
|
|
540
547
|
if (result.size >= limit) break;
|
|
541
548
|
fallbackIfFails_default(predicate != null ? predicate : item, [item, key, data], false) && result.set(key, item);
|
|
@@ -612,20 +619,19 @@ function matchItemOrProp({
|
|
|
612
619
|
matchExact,
|
|
613
620
|
transform
|
|
614
621
|
}, item, propertyName) {
|
|
615
|
-
var _a, _b;
|
|
616
622
|
const fuzzy = isStr(query) || isRegExp(query) || propertyName === void 0;
|
|
617
623
|
const keyword = fuzzy ? query : query[propertyName];
|
|
618
624
|
const propVal = fuzzy || !isObj(item) ? item : item[propertyName];
|
|
619
625
|
let value = fallbackIfFails_default(
|
|
620
626
|
() => {
|
|
621
|
-
var
|
|
627
|
+
var _a;
|
|
622
628
|
return isFn(transform) ? transform(
|
|
623
629
|
item,
|
|
624
630
|
fuzzy ? void 0 : propVal,
|
|
625
631
|
propertyName
|
|
626
632
|
) : isObj(propVal, false) ? JSON.stringify(
|
|
627
633
|
isArrLike(propVal) ? [...propVal.values()] : Object.values(propVal)
|
|
628
|
-
) : (
|
|
634
|
+
) : (_a = propVal == null ? void 0 : propVal.toString) == null ? void 0 : _a.call(propVal);
|
|
629
635
|
},
|
|
630
636
|
[],
|
|
631
637
|
""
|
|
@@ -634,7 +640,7 @@ function matchItemOrProp({
|
|
|
634
640
|
if (isRegExp(keyword)) return keyword.test(`${value}`);
|
|
635
641
|
if (ignoreCase && !matchExact) value = value.toLowerCase();
|
|
636
642
|
if (value === keyword) return true;
|
|
637
|
-
return !matchExact && `${value}`.includes((
|
|
643
|
+
return !matchExact && `${value}`.includes(String(keyword));
|
|
638
644
|
}
|
|
639
645
|
var search_default = search;
|
|
640
646
|
|
|
@@ -670,9 +676,13 @@ var reverse = (data, reverse2 = true, newInstance = false) => {
|
|
|
670
676
|
if (!dataType) return [];
|
|
671
677
|
const arr = dataType === 1 ? !newInstance ? data : [...data] : dataType === 2 ? [...data.entries()] : [...data.values()];
|
|
672
678
|
if (reverse2) arr.reverse();
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
679
|
+
switch (dataType) {
|
|
680
|
+
case 1:
|
|
681
|
+
return arr;
|
|
682
|
+
case 2:
|
|
683
|
+
case 3:
|
|
684
|
+
if (newInstance || !("clear" in data && isFn(data.clear)))
|
|
685
|
+
return dataType === 2 ? new Map(arr) : new Set(arr);
|
|
676
686
|
}
|
|
677
687
|
(_a = data == null ? void 0 : data.clear) == null ? void 0 : _a.call(data);
|
|
678
688
|
for (const item of arr)
|
|
@@ -783,22 +793,24 @@ var copyToClipboard = (str) => fallbackIfFails(
|
|
|
783
793
|
() => navigator.clipboard.writeText(str).then(() => 1),
|
|
784
794
|
[],
|
|
785
795
|
// If clipboard API is not available or fails, use the fallback method
|
|
786
|
-
() =>
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
796
|
+
() => Promise.resolve(copyLegacy(str) ? 2 : 0)
|
|
797
|
+
);
|
|
798
|
+
var copyLegacy = (str) => fallbackIfFails(
|
|
799
|
+
() => {
|
|
800
|
+
const el = document.createElement("textarea");
|
|
801
|
+
el.value = str;
|
|
802
|
+
el.setAttribute("readonly", "");
|
|
803
|
+
el.style.position = "absolute";
|
|
804
|
+
el.style.left = "-9999px";
|
|
805
|
+
document.body.appendChild(el);
|
|
806
|
+
el.select();
|
|
807
|
+
const success = document.execCommand("copy");
|
|
808
|
+
document.body.removeChild(el);
|
|
809
|
+
return success;
|
|
810
|
+
},
|
|
811
|
+
[],
|
|
812
|
+
false
|
|
813
|
+
// On error, return false
|
|
802
814
|
);
|
|
803
815
|
|
|
804
816
|
// src/str/getUrlParam.ts
|
|
@@ -850,6 +862,9 @@ var EMAIL_REGEX = new RegExp(
|
|
|
850
862
|
);
|
|
851
863
|
var HEX_REGEX = /^0x[0-9a-f]+$/i;
|
|
852
864
|
var HASH_REGEX = /^0x[0-9a-f]{64}$/i;
|
|
865
|
+
|
|
866
|
+
// src/str/strToArr.ts
|
|
867
|
+
var strToArr = (value, seperator = ",") => typeof value === "string" && value.split(seperator).filter(Boolean) || [];
|
|
853
868
|
export {
|
|
854
869
|
EMAIL_REGEX,
|
|
855
870
|
HASH_REGEX,
|
|
@@ -915,6 +930,7 @@ export {
|
|
|
915
930
|
objClean,
|
|
916
931
|
objCopy,
|
|
917
932
|
objCreate,
|
|
933
|
+
objHasKeys,
|
|
918
934
|
objKeys,
|
|
919
935
|
objReadOnly,
|
|
920
936
|
objSetProp,
|
|
@@ -926,6 +942,7 @@ export {
|
|
|
926
942
|
search,
|
|
927
943
|
sliceMap,
|
|
928
944
|
sort,
|
|
945
|
+
strToArr,
|
|
929
946
|
throttled,
|
|
930
947
|
toDatetimeLocal
|
|
931
948
|
};
|
package/package.json
CHANGED
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
"_watch": "tsc -p tsconfig.json --watch",
|
|
37
37
|
"build": "tsup src/index.ts --format esm --dts --clean --config ../../tsup.config.js",
|
|
38
38
|
"dev": "npm run build -- --watch",
|
|
39
|
-
"
|
|
39
|
+
"start": "npm run build -- --watch",
|
|
40
|
+
"test": "cd ../../ && npm run test core"
|
|
40
41
|
},
|
|
41
42
|
"sideEffects": false,
|
|
42
43
|
"type": "module",
|
|
43
44
|
"types": "dist/index.d.ts",
|
|
44
|
-
"version": "1.0.
|
|
45
|
+
"version": "1.0.5"
|
|
45
46
|
}
|