@superutils/core 1.0.4 → 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 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 DeferredConfig<ThisArg = unknown> {
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?: DeferredConfig<ThisArg>): (...args: TArgs) => void;
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()} due to use of `Object.prototype.toString.call()`
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 ThrottleConfig<ThisArg = unknown> = {
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?: ThrottleConfig<ThisArg>): (...args: TArgs) => void;
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 output (optional) output object
722
- * @param override (optional) whether to allow override output (if provided) properties.
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 string | symbol, T extends Record<Key, unknown>, IgnoredKey extends Key | string>(input: T, output?: Record<PropertyKey, unknown>, ignoreKeys?: IgnoredKey[] | Set<IgnoredKey>, override?: boolean | "empty", recursive?: boolean) => Record<PropertyKey, unknown>;
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()} instead.
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: (value: V, key: K, data: IterableList<K, V>) => boolean, limit?: number, asArray?: AsArray, result?: Map<K, V>) => Result;
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()} function */
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 SliceMapCallback<Data, Value, Key> = (item: Value, key: Key, data: Data) => Value;
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
- /** callback to transform each item */
1131
- transform?: SliceMapCallback<Data, Value, Key>;
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 start Default: `0`
1144
- * @param end (optional) last index - exclusive. Default: index of the last item
1145
- * @param callback to be executed on each item within the set range.
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>(data: Data, options?: SliceMapOptions<Data, Value, Key, AsMap> | SliceMapCallback<Data, Value, Key>) => AsMap extends false ? Value[] : Map<Key, Value>;
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
  *
@@ -1319,4 +1346,14 @@ declare const EMAIL_REGEX: RegExp;
1319
1346
  declare const HEX_REGEX: RegExp;
1320
1347
  declare const HASH_REGEX: RegExp;
1321
1348
 
1322
- export { type ArrayComparator, type AsyncFn, type CreateTuple, type CurriedArgs, type Curry, type DeferredConfig, 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 OptionalIf, type ReadOnlyAllowAddFn, ReadOnlyArrayHelper, type ReadOnlyConfig, type SearchOptions, type Slice, type SliceMapCallback, type SliceMapOptions, type SortOptions, type ThrottleConfig, 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, objKeys, objReadOnly, objSetProp, objSetPropUndefined, objSort, objWithoutKeys, randomInt, reverse, search, sliceMap, sort, throttled, toDatetimeLocal };
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
@@ -195,15 +195,12 @@ var is = {
195
195
  // src/fallbackIfFails.ts
196
196
  var fallbackIfFails = (target, args, fallbackValue) => {
197
197
  let result;
198
- let asPromise = false;
199
198
  try {
200
199
  result = !isFn(target) ? target : target(...isFn(args) ? args() : args);
201
200
  if (!isPromise(result)) return result;
202
- asPromise = true;
203
201
  return result.catch((err) => getAltValCb(err, fallbackValue));
204
202
  } catch (error) {
205
- result = getAltValCb(error, fallbackValue);
206
- return asPromise && !isPromise(result) ? Promise.resolve(result) : result;
203
+ return getAltValCb(error, fallbackValue);
207
204
  }
208
205
  };
209
206
  var fallbackIfFails_default = fallbackIfFails;
@@ -298,7 +295,7 @@ var objClean = (obj, keys, ignoreIfNotExist = true) => {
298
295
  const result = {};
299
296
  if (!isObj(obj) || !isArr(keys)) return result;
300
297
  const uniqKeys = arrUnique(
301
- keys.map((x) => isStr(x) ? `${x}`.split(".")[0] : x)
298
+ keys.map((x) => String(x).split(".")[0])
302
299
  ).sort();
303
300
  for (const key of uniqKeys) {
304
301
  if (ignoreIfNotExist && !obj.hasOwnProperty(key)) continue;
@@ -338,8 +335,8 @@ var objKeys_default = objKeys;
338
335
  // src/obj/objCopy.ts
339
336
  var clone = (value, fallback = "null") => JSON.parse(fallbackIfFails_default(JSON.stringify, [value], fallback));
340
337
  var objCopy = (input, output, ignoreKeys, override = false, recursive = true) => {
341
- if (!isObj(output)) output = {};
342
- if (!isObj(input)) return output;
338
+ const _output = isObj(output) ? output : {};
339
+ if (!isObj(input)) return _output;
343
340
  const _ignoreKeys = new Set(ignoreKeys != null ? ignoreKeys : []);
344
341
  const inKeys = objKeys_default(input, true, true).filter(
345
342
  (x) => !_ignoreKeys.has(x)
@@ -347,14 +344,14 @@ var objCopy = (input, output, ignoreKeys, override = false, recursive = true) =>
347
344
  for (const _key of inKeys) {
348
345
  const key = _key;
349
346
  const value = input[key];
350
- const skip = output.hasOwnProperty(key) && (!override || override === "empty" && !isEmpty(output[key]));
347
+ const skip = _output.hasOwnProperty(key) && (override === "empty" ? !isEmpty(_output[key]) : isFn(override) ? !override(key, _output[key], value) : true);
351
348
  if (skip) continue;
352
349
  const isPrimitive = [void 0, null, Infinity, NaN].includes(asAny(value)) || !isObj(value, false);
353
350
  if (isPrimitive) {
354
- output[key] = value;
351
+ _output[key] = value;
355
352
  continue;
356
353
  }
357
- output[key] = (() => {
354
+ _output[key] = (() => {
358
355
  switch (Object.getPrototypeOf(value)) {
359
356
  case Array.prototype:
360
357
  return clone(value, "[]");
@@ -384,19 +381,19 @@ var objCopy = (input, output, ignoreKeys, override = false, recursive = true) =>
384
381
  }
385
382
  if (isSymbol(key) || !recursive) return clone(value);
386
383
  const ignoreChildKeys = [..._ignoreKeys].map(
387
- (x) => !isSymbol(x) && x.startsWith(key.concat(".")) && x.split(key.concat("."))[1]
384
+ (x) => String(x).startsWith(String(key).concat(".")) && String(x).split(String(key).concat("."))[1]
388
385
  ).filter(Boolean);
389
386
  if (!ignoreChildKeys.length) return clone(value);
390
387
  return objCopy(
391
388
  value,
392
- output[key],
389
+ _output[key],
393
390
  ignoreChildKeys,
394
391
  override,
395
392
  recursive
396
393
  );
397
394
  })();
398
395
  }
399
- return output;
396
+ return _output;
400
397
  };
401
398
 
402
399
  // src/obj/objCreate.ts
@@ -409,6 +406,16 @@ var objCreate = (keys = [], values = [], result) => {
409
406
  return result;
410
407
  };
411
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
+
412
419
  // src/obj/objReadOnly.ts
413
420
  var objReadOnly = (obj, config) => {
414
421
  if (!isObj(obj, false)) obj = {};
@@ -501,10 +508,10 @@ var ReadOnlyArrayHelper = class extends Array {
501
508
  this.shift = () => this.ignoreOrThrow(this[0]);
502
509
  this.splice = (..._ignoredArgs) => this.ignoreOrThrow([]);
503
510
  this.unshift = (..._ignoredArgs) => this.ignoreOrThrow(this.length);
504
- // fromAsync = super.fromAsync
505
- this.reduce = super.reduce;
506
- this.reduceRight = super.reduceRight;
507
511
  }
512
+ // fromAsync = super.fromAsync
513
+ // reduce = super.reduce
514
+ // reduceRight = super.reduceRight
508
515
  };
509
516
 
510
517
  // src/arr/arrReverse.ts
@@ -532,9 +539,10 @@ function arrToMap(arr, key, flatDepth = 0) {
532
539
  var arrUnique = (arr, flatDepth = 0) => !isArr(arr) ? [] : Array.from(new Set(arr.flat(flatDepth)));
533
540
 
534
541
  // src/iterable/filter.ts
535
- var filter = (data, predicate, limit = Infinity, asArray = false, result = /* @__PURE__ */ new Map()) => {
542
+ var filter = (data, predicate, limit, asArray, result) => {
536
543
  var _a;
537
544
  if (!isMap(result)) result = /* @__PURE__ */ new Map();
545
+ if (!isPositiveInteger(limit)) limit = Infinity;
538
546
  for (const [key, item] of ((_a = data == null ? void 0 : data.entries) == null ? void 0 : _a.call(data)) || []) {
539
547
  if (result.size >= limit) break;
540
548
  fallbackIfFails_default(predicate != null ? predicate : item, [item, key, data], false) && result.set(key, item);
@@ -611,20 +619,19 @@ function matchItemOrProp({
611
619
  matchExact,
612
620
  transform
613
621
  }, item, propertyName) {
614
- var _a, _b;
615
622
  const fuzzy = isStr(query) || isRegExp(query) || propertyName === void 0;
616
623
  const keyword = fuzzy ? query : query[propertyName];
617
624
  const propVal = fuzzy || !isObj(item) ? item : item[propertyName];
618
625
  let value = fallbackIfFails_default(
619
626
  () => {
620
- var _a2;
627
+ var _a;
621
628
  return isFn(transform) ? transform(
622
629
  item,
623
630
  fuzzy ? void 0 : propVal,
624
631
  propertyName
625
632
  ) : isObj(propVal, false) ? JSON.stringify(
626
633
  isArrLike(propVal) ? [...propVal.values()] : Object.values(propVal)
627
- ) : (_a2 = propVal == null ? void 0 : propVal.toString) == null ? void 0 : _a2.call(propVal);
634
+ ) : (_a = propVal == null ? void 0 : propVal.toString) == null ? void 0 : _a.call(propVal);
628
635
  },
629
636
  [],
630
637
  ""
@@ -633,7 +640,7 @@ function matchItemOrProp({
633
640
  if (isRegExp(keyword)) return keyword.test(`${value}`);
634
641
  if (ignoreCase && !matchExact) value = value.toLowerCase();
635
642
  if (value === keyword) return true;
636
- return !matchExact && `${value}`.includes((_b = (_a = keyword == null ? void 0 : keyword.toString) == null ? void 0 : _a.call(keyword)) != null ? _b : "");
643
+ return !matchExact && `${value}`.includes(String(keyword));
637
644
  }
638
645
  var search_default = search;
639
646
 
@@ -669,9 +676,13 @@ var reverse = (data, reverse2 = true, newInstance = false) => {
669
676
  if (!dataType) return [];
670
677
  const arr = dataType === 1 ? !newInstance ? data : [...data] : dataType === 2 ? [...data.entries()] : [...data.values()];
671
678
  if (reverse2) arr.reverse();
672
- if (dataType === 1) return arr;
673
- if (newInstance || !("clear" in data && isFn(data.clear))) {
674
- return dataType === 2 ? new Map(arr) : dataType === 3 && new Set(arr) || [];
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);
675
686
  }
676
687
  (_a = data == null ? void 0 : data.clear) == null ? void 0 : _a.call(data);
677
688
  for (const item of arr)
@@ -782,7 +793,7 @@ var copyToClipboard = (str) => fallbackIfFails(
782
793
  () => navigator.clipboard.writeText(str).then(() => 1),
783
794
  [],
784
795
  // If clipboard API is not available or fails, use the fallback method
785
- () => Promise.resolve(copyLegacy(str))
796
+ () => Promise.resolve(copyLegacy(str) ? 2 : 0)
786
797
  );
787
798
  var copyLegacy = (str) => fallbackIfFails(
788
799
  () => {
@@ -795,11 +806,11 @@ var copyLegacy = (str) => fallbackIfFails(
795
806
  el.select();
796
807
  const success = document.execCommand("copy");
797
808
  document.body.removeChild(el);
798
- return success ? 2 : 0;
809
+ return success;
799
810
  },
800
811
  [],
801
- 0
802
- // On error, resolve with 0
812
+ false
813
+ // On error, return false
803
814
  );
804
815
 
805
816
  // src/str/getUrlParam.ts
@@ -851,6 +862,9 @@ var EMAIL_REGEX = new RegExp(
851
862
  );
852
863
  var HEX_REGEX = /^0x[0-9a-f]+$/i;
853
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) || [];
854
868
  export {
855
869
  EMAIL_REGEX,
856
870
  HASH_REGEX,
@@ -916,6 +930,7 @@ export {
916
930
  objClean,
917
931
  objCopy,
918
932
  objCreate,
933
+ objHasKeys,
919
934
  objKeys,
920
935
  objReadOnly,
921
936
  objSetProp,
@@ -927,6 +942,7 @@ export {
927
942
  search,
928
943
  sliceMap,
929
944
  sort,
945
+ strToArr,
930
946
  throttled,
931
947
  toDatetimeLocal
932
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
- "test": "cd ../../ && npm run test promise"
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.4"
45
+ "version": "1.0.5"
45
46
  }