@superutils/core 1.0.7 → 1.1.1

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/README.md CHANGED
@@ -53,8 +53,7 @@ is.map(new Map()) // true
53
53
  is.number(123) // true
54
54
  is.number(NaN) // false
55
55
  is.url('https://google.com') // true
56
- ...
57
-
56
+ //...
58
57
  ```
59
58
 
60
59
  All these functions can also be imported independantly.
@@ -80,16 +79,15 @@ import {
80
79
  `debounce()`, a sugar for `deferred()`, is also available.
81
80
 
82
81
  ```javascript
83
-
84
82
  import { deferred } from '@superutils/core'
85
83
 
86
84
  const handleChange = deferred(
87
- event => console.log(event.target.value),
88
- 300 // debounce delay in milliseconds
85
+ event => console.log(event.target.value),
86
+ 300, // debounce delay in milliseconds
89
87
  )
90
- handleChange({ target: { value 1 } }) // will be ignored
91
- handleChange({ target: { value 2 } }) // will be ignored
92
- handleChange({ target: { value 3 } }) // will be executed
88
+ handleChange({ target: { value: 1 } }) // will be ignored
89
+ handleChange({ target: { value: 2 } }) // will be ignored
90
+ handleChange({ target: { value: 3 } }) // will be executed
93
91
  ```
94
92
 
95
93
  <div id="throttle"></div>
@@ -100,12 +98,12 @@ handleChange({ target: { value 3 } }) // will be executed
100
98
  import { throttle } from '@superutils/core'
101
99
 
102
100
  const handleChange = throttle(
103
- event => console.log(event.target.value),
104
- 300 // throttle duration in milliseconds
101
+ event => console.log(event.target.value),
102
+ 300, // throttle duration in milliseconds
105
103
  )
106
- handleChange({ target: { value 1 } }) // will be executed
107
- handleChange({ target: { value 2 } }) // will be ignored
108
- handleChange({ target: { value 3 } }) // will be ignored
104
+ handleChange({ target: { value: 1 } }) // will be executed
105
+ handleChange({ target: { value: 2 } }) // will be ignored
106
+ handleChange({ target: { value: 3 } }) // will be ignored
109
107
  ```
110
108
 
111
109
  <div id="fallback-if-fails"></div>
@@ -150,11 +148,10 @@ fallbackIfFails(
150
148
  ).then(console.log)
151
149
  // Prints the result when request is successful or fallback value when request fails
152
150
 
153
-
154
151
  // use a promise
155
152
  fallbackIfFails(
156
153
  Promise.reject('error'),
157
- [], //
154
+ [], //
158
155
  )
159
156
  ```
160
157
 
package/dist/index.d.ts CHANGED
@@ -255,8 +255,8 @@ declare function curry<TData, TArgs extends unknown[], TArgsIsFinite extends boo
255
255
  ]): Curry<TData, CurriedArgs<TArgs, TArgsIsFinite, (...args: TArgs) => TData, TArity>>;
256
256
 
257
257
  /**
258
- * @function deferred AKA debounce
259
- * @summary returns a function that invokes the callback function after certain delay/timeout.
258
+ *
259
+ * Returns a function that invokes the callback function after certain delay/timeout.
260
260
  * All errors will be gracefully swallowed.
261
261
  *
262
262
  * @param callback function to be invoked after timeout
@@ -267,20 +267,18 @@ declare function curry<TData, TArgs extends unknown[], TArgsIsFinite extends boo
267
267
  * @param config.tid (optional) Timeout Id. If provided, will clear the timeout on first invocation.
268
268
  *
269
269
  * @example Debounce function calls
270
- * ```typescript
270
+ * ```javascript
271
271
  * import { deferred } from '@superutils/core'
272
272
  *
273
273
  * const handleChange = deferred(
274
- * event => console.log(event.target.value),
274
+ * event => console.log('Value:', event.target.value),
275
275
  * 300 // debounce delay in milliseconds
276
276
  * )
277
277
  *
278
- * handleChange({ target: { value 1 } }) // will be ignored
279
- * handleChange({ target: { value 2 } }) // will be ingored
280
- * handleChange({ target: { value 3 } }) // will be invoked
278
+ * handleChange({ target: { value: 1 } }) // will be ignored
279
+ * handleChange({ target: { value: 2 } }) // will be ingored
280
+ * handleChange({ target: { value: 3 } }) // will be invoked
281
281
  * ```
282
- *
283
- *
284
282
  */
285
283
  declare const deferred: {
286
284
  <TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?: DeferredOptions<ThisArg>): (...args: TArgs) => void;
@@ -299,7 +297,13 @@ declare const deferred: {
299
297
  };
300
298
 
301
299
  /** Super for `deferred()` function */
302
- declare function debounce(...args: Parameters<typeof deferred>): (...args: unknown[]) => void;
300
+ declare const debounce: {
301
+ <TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?: DeferredOptions<ThisArg>): (...args: TArgs) => void;
302
+ defaults: {
303
+ leading: false;
304
+ onError: undefined;
305
+ };
306
+ };
303
307
 
304
308
  /**
305
309
  * If `T` is a promise turn it into an union type by adding the value type
@@ -381,11 +385,6 @@ type IfPromiseAddValue<T> = T extends Promise<infer V> ? T | V : T;
381
385
  */
382
386
  declare const fallbackIfFails: <T, TArgs extends unknown[] = unknown[]>(target: T | ((...args: TArgs) => T), args: TArgs | (() => TArgs), fallbackValue: IfPromiseAddValue<T> | ((reason: unknown) => IfPromiseAddValue<T>)) => T;
383
387
 
384
- /** Cast a value as `any` type to bypass type check. Use with caution. */
385
- declare const asAny: <T = any>(x: unknown) => T;
386
- /** Force cast one type into another to bypass type checks. Use with caution. */
387
- declare const forceCast: <T>(x: unknown) => T;
388
-
389
388
  /** Check if value is an array */
390
389
  declare const isArr: <Item = unknown>(x: unknown) => x is Item[];
391
390
  /**
@@ -660,6 +659,19 @@ type ThrottleOptions<ThisArg = unknown> = {
660
659
  * @param config.tid (optional)
661
660
  * @param config.thisArg (optional) the special `thisArgs` to be used when invoking the callback.
662
661
  * @param config.trailing (optional) whether to enable trailing edge execution. Default: `true`
662
+ *
663
+ * @example
664
+ * ```javascript
665
+ * import { throttle } from '@superutils/core'
666
+ *
667
+ * const handleChange = throttle(
668
+ * event => console.log('Value:', event.target.value),
669
+ * 300, // throttle duration in milliseconds
670
+ * )
671
+ * handleChange({ target: { value: 1 } }) // will be executed
672
+ * handleChange({ target: { value: 2 } }) // will be ignored
673
+ * handleChange({ target: { value: 3 } }) // will be ignored
674
+ * ```
663
675
  */
664
676
  declare const throttled: {
665
677
  <TArgs extends unknown[], ThisArg>(callback: (this: ThisArg, ...args: TArgs) => ValueOrPromise<unknown>, delay?: number, config?: ThrottleOptions<ThisArg>): (...args: TArgs) => void;
@@ -712,7 +724,7 @@ declare const objClean: <T extends Record<PropertyKey, unknown>, Key extends key
712
724
  * Deep-copy an object to another object
713
725
  *
714
726
  * @param input input object
715
- * @param _output (optional) output object
727
+ * @param output (optional) output object
716
728
  * @param ignoreKeys (optional) input peroperties to be ignored. Prevents output's property to be overriden.
717
729
  *
718
730
  * For child object properties use "." (dot) separated path.
@@ -734,7 +746,7 @@ declare const objClean: <T extends Record<PropertyKey, unknown>, Key extends key
734
746
  *
735
747
  * Default: `false`
736
748
  *
737
- * @param reverse (optional) whether to reverse sort object properties. Default: `false`
749
+ * @param recursive (optional) whether to recursively copy nested objects. Default: `false`
738
750
  *
739
751
  *
740
752
  * @returns copied and/or merged object
@@ -774,7 +786,7 @@ declare const objCreate: <V, K extends PropertyKey, RV, RK extends PropertyKey,
774
786
  *
775
787
  * @param input
776
788
  * @param keys
777
- * @param equireValue (optional) whether each property should have some value.
789
+ * @param requireValue (optional) whether each property should have some value.
778
790
  */
779
791
  declare function objHasKeys(input?: object | unknown[], keys?: PropertyKey[], requireValue?: boolean): boolean;
780
792
 
@@ -1013,7 +1025,7 @@ type SearchOptions<K, V, MatchExact extends boolean = false, AsMap extends boole
1013
1025
  * 2. `key`: index/key
1014
1026
  * 3. `data`: value provided in the first argument (`data`)
1015
1027
  * @param limit (optional) limit number of results
1016
- * @param arArray
1028
+ * @param asArray
1017
1029
  *
1018
1030
  * @returns new Map with filtered items
1019
1031
  *
@@ -1374,4 +1386,4 @@ declare const HASH_REGEX: RegExp;
1374
1386
  */
1375
1387
  declare const strToArr: (value: unknown, seperator?: string) => string[];
1376
1388
 
1377
- 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, matchObjOrProp, noop, noopAsync, objClean, objCopy, objCreate, objHasKeys, objKeys, objReadOnly, objSetProp, objSetPropUndefined, objSort, objWithoutKeys, randomInt, reverse, search, sliceMap, sort, strToArr, throttled, toDatetimeLocal };
1389
+ 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, clearClutter, copyToClipboard, curry, debounce, deferred, fallbackIfFails, filter, find, 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, matchObjOrProp, 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
@@ -239,13 +239,7 @@ deferred.defaults = {
239
239
  var deferred_default = deferred;
240
240
 
241
241
  // src/debounce.ts
242
- function debounce(...args) {
243
- return deferred_default(...args);
244
- }
245
-
246
- // src/forceCast.ts
247
- var asAny = (x) => x;
248
- var forceCast = (x) => x;
242
+ var debounce = deferred_default;
249
243
 
250
244
  // src/throttled.ts
251
245
  var throttled = (callback, delay = 50, config = {}) => {
@@ -918,7 +912,6 @@ export {
918
912
  arrReverse,
919
913
  arrToMap,
920
914
  arrUnique,
921
- asAny,
922
915
  clearClutter,
923
916
  copyToClipboard,
924
917
  curry,
@@ -927,7 +920,6 @@ export {
927
920
  fallbackIfFails,
928
921
  filter,
929
922
  find,
930
- forceCast,
931
923
  getEntries,
932
924
  getKeys,
933
925
  getSize,
package/package.json CHANGED
@@ -42,5 +42,5 @@
42
42
  "sideEffects": false,
43
43
  "type": "module",
44
44
  "types": "dist/index.d.ts",
45
- "version": "1.0.7"
45
+ "version": "1.1.1"
46
46
  }