rattail 1.1.0 → 1.2.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/lib/index.cjs CHANGED
@@ -53,6 +53,7 @@ __export(src_exports, {
53
53
  at: () => at,
54
54
  baseRound: () => baseRound,
55
55
  call: () => call,
56
+ callOrReturn: () => callOrReturn,
56
57
  camelize: () => camelize,
57
58
  cancelAnimationFrame: () => cancelAnimationFrame,
58
59
  ceil: () => ceil,
@@ -86,6 +87,8 @@ __export(src_exports, {
86
87
  getScrollTop: () => getScrollTop,
87
88
  getStyle: () => getStyle,
88
89
  groupBy: () => groupBy,
90
+ hasDuplicates: () => hasDuplicates,
91
+ hasDuplicatesBy: () => hasDuplicatesBy,
89
92
  hasOwn: () => hasOwn,
90
93
  inBrowser: () => inBrowser,
91
94
  inMobile: () => inMobile,
@@ -537,6 +540,16 @@ function assert(condition, message) {
537
540
  }
538
541
  }
539
542
 
543
+ // src/general/hasDuplicates.ts
544
+ function hasDuplicates(arr) {
545
+ return uniq(arr).length !== arr.length;
546
+ }
547
+
548
+ // src/general/hasDuplicatesBy.ts
549
+ function hasDuplicatesBy(arr, fn) {
550
+ return uniqBy(arr, fn).length !== arr.length;
551
+ }
552
+
540
553
  // src/number/toNumber.ts
541
554
  function toNumber(val) {
542
555
  if (val == null) {
@@ -1357,6 +1370,14 @@ function throttle(fn, delay2 = 200) {
1357
1370
  function NOOP() {
1358
1371
  }
1359
1372
 
1373
+ // src/function/callOrReturn.ts
1374
+ function callOrReturn(fnOrValue, ...args) {
1375
+ if (isFunction(fnOrValue)) {
1376
+ return fnOrValue(...args);
1377
+ }
1378
+ return fnOrValue;
1379
+ }
1380
+
1360
1381
  // src/collection/cloneDeepWith.ts
1361
1382
  function cloneDeepWith(value, fn) {
1362
1383
  const cache = /* @__PURE__ */ new WeakMap();
@@ -1621,6 +1642,7 @@ function ceil(val, precision = 0) {
1621
1642
  at,
1622
1643
  baseRound,
1623
1644
  call,
1645
+ callOrReturn,
1624
1646
  camelize,
1625
1647
  cancelAnimationFrame,
1626
1648
  ceil,
@@ -1654,6 +1676,8 @@ function ceil(val, precision = 0) {
1654
1676
  getScrollTop,
1655
1677
  getStyle,
1656
1678
  groupBy,
1679
+ hasDuplicates,
1680
+ hasDuplicatesBy,
1657
1681
  hasOwn,
1658
1682
  inBrowser,
1659
1683
  inMobile,
package/lib/index.d.cts CHANGED
@@ -165,6 +165,8 @@ declare function throttle<F extends (...args: any[]) => any>(fn: F, delay?: numb
165
165
 
166
166
  declare function NOOP(): void;
167
167
 
168
+ declare function callOrReturn<T, A extends any[]>(fnOrValue: T | ((...args: A) => T), ...args: A): T;
169
+
168
170
  declare function getGlobalThis(): typeof globalThis;
169
171
 
170
172
  declare function hasOwn<T extends object>(val: T, key: PropertyKey): key is keyof T;
@@ -199,7 +201,7 @@ declare function isMap(val: unknown): val is Map<any, any>;
199
201
 
200
202
  declare function isNonEmptyArray(val: unknown): val is any[];
201
203
 
202
- declare function isNullish<T>(val: T | null | undefined): val is NonNullable<T>;
204
+ declare function isNullish(val: unknown): val is null | undefined;
203
205
 
204
206
  declare function isNumber(val: unknown): val is number;
205
207
 
@@ -246,6 +248,10 @@ declare function isEmptyPlainObject(val: unknown): val is Record<string, any>;
246
248
 
247
249
  declare function assert(condition: boolean, message: string): asserts condition;
248
250
 
251
+ declare function hasDuplicates<T>(arr: T[]): boolean;
252
+
253
+ declare function hasDuplicatesBy<T>(arr: T[], fn: (a: T, b: T) => any): boolean;
254
+
249
255
  declare function clamp(num: number, min: number, max: number): number;
250
256
 
251
257
  declare function clampArrayRange(index: number, arr: unknown[]): number;
@@ -320,4 +326,4 @@ declare function floor(val: number, precision?: number): number;
320
326
 
321
327
  declare function ceil(val: number, precision?: number): number;
322
328
 
323
- export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
329
+ export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
package/lib/index.d.ts CHANGED
@@ -165,6 +165,8 @@ declare function throttle<F extends (...args: any[]) => any>(fn: F, delay?: numb
165
165
 
166
166
  declare function NOOP(): void;
167
167
 
168
+ declare function callOrReturn<T, A extends any[]>(fnOrValue: T | ((...args: A) => T), ...args: A): T;
169
+
168
170
  declare function getGlobalThis(): typeof globalThis;
169
171
 
170
172
  declare function hasOwn<T extends object>(val: T, key: PropertyKey): key is keyof T;
@@ -199,7 +201,7 @@ declare function isMap(val: unknown): val is Map<any, any>;
199
201
 
200
202
  declare function isNonEmptyArray(val: unknown): val is any[];
201
203
 
202
- declare function isNullish<T>(val: T | null | undefined): val is NonNullable<T>;
204
+ declare function isNullish(val: unknown): val is null | undefined;
203
205
 
204
206
  declare function isNumber(val: unknown): val is number;
205
207
 
@@ -246,6 +248,10 @@ declare function isEmptyPlainObject(val: unknown): val is Record<string, any>;
246
248
 
247
249
  declare function assert(condition: boolean, message: string): asserts condition;
248
250
 
251
+ declare function hasDuplicates<T>(arr: T[]): boolean;
252
+
253
+ declare function hasDuplicatesBy<T>(arr: T[], fn: (a: T, b: T) => any): boolean;
254
+
249
255
  declare function clamp(num: number, min: number, max: number): number;
250
256
 
251
257
  declare function clampArrayRange(index: number, arr: unknown[]): number;
@@ -320,4 +326,4 @@ declare function floor(val: number, precision?: number): number;
320
326
 
321
327
  declare function ceil(val: number, precision?: number): number;
322
328
 
323
- export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
329
+ export { type BEM, type ClassName, type Classes, type DurationContext, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, assert, at, baseRound, call, callOrReturn, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, duration, ensurePrefix, ensureSuffix, find, floor, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasDuplicates, hasDuplicatesBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEmptyPlainObject, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, mapObject, maxBy, mean, meanBy, merge, mergeWith, minBy, motion, normalizeToArray, objectEntries, objectKeys, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, removeItemBy, removeItemsBy, requestAnimationFrame, round, sample, sessionStorage, set, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
@@ -43,6 +43,7 @@ var Rattail = (() => {
43
43
  at: () => at,
44
44
  baseRound: () => baseRound,
45
45
  call: () => call,
46
+ callOrReturn: () => callOrReturn,
46
47
  camelize: () => camelize,
47
48
  cancelAnimationFrame: () => cancelAnimationFrame,
48
49
  ceil: () => ceil,
@@ -76,6 +77,8 @@ var Rattail = (() => {
76
77
  getScrollTop: () => getScrollTop,
77
78
  getStyle: () => getStyle,
78
79
  groupBy: () => groupBy,
80
+ hasDuplicates: () => hasDuplicates,
81
+ hasDuplicatesBy: () => hasDuplicatesBy,
79
82
  hasOwn: () => hasOwn,
80
83
  inBrowser: () => inBrowser,
81
84
  inMobile: () => inMobile,
@@ -526,6 +529,16 @@ var Rattail = (() => {
526
529
  }
527
530
  }
528
531
 
532
+ // src/general/hasDuplicates.ts
533
+ function hasDuplicates(arr) {
534
+ return uniq(arr).length !== arr.length;
535
+ }
536
+
537
+ // src/general/hasDuplicatesBy.ts
538
+ function hasDuplicatesBy(arr, fn) {
539
+ return uniqBy(arr, fn).length !== arr.length;
540
+ }
541
+
529
542
  // src/number/toNumber.ts
530
543
  function toNumber(val) {
531
544
  if (val == null) {
@@ -1328,6 +1341,14 @@ var Rattail = (() => {
1328
1341
  function NOOP() {
1329
1342
  }
1330
1343
 
1344
+ // src/function/callOrReturn.ts
1345
+ function callOrReturn(fnOrValue, ...args) {
1346
+ if (isFunction(fnOrValue)) {
1347
+ return fnOrValue(...args);
1348
+ }
1349
+ return fnOrValue;
1350
+ }
1351
+
1331
1352
  // src/collection/cloneDeepWith.ts
1332
1353
  function cloneDeepWith(value, fn) {
1333
1354
  const cache = /* @__PURE__ */ new WeakMap();
package/lib/index.js CHANGED
@@ -41,6 +41,7 @@ __export(src_exports, {
41
41
  at: () => at,
42
42
  baseRound: () => baseRound,
43
43
  call: () => call,
44
+ callOrReturn: () => callOrReturn,
44
45
  camelize: () => camelize,
45
46
  cancelAnimationFrame: () => cancelAnimationFrame,
46
47
  ceil: () => ceil,
@@ -74,6 +75,8 @@ __export(src_exports, {
74
75
  getScrollTop: () => getScrollTop,
75
76
  getStyle: () => getStyle,
76
77
  groupBy: () => groupBy,
78
+ hasDuplicates: () => hasDuplicates,
79
+ hasDuplicatesBy: () => hasDuplicatesBy,
77
80
  hasOwn: () => hasOwn,
78
81
  inBrowser: () => inBrowser,
79
82
  inMobile: () => inMobile,
@@ -524,6 +527,16 @@ function assert(condition, message) {
524
527
  }
525
528
  }
526
529
 
530
+ // src/general/hasDuplicates.ts
531
+ function hasDuplicates(arr) {
532
+ return uniq(arr).length !== arr.length;
533
+ }
534
+
535
+ // src/general/hasDuplicatesBy.ts
536
+ function hasDuplicatesBy(arr, fn) {
537
+ return uniqBy(arr, fn).length !== arr.length;
538
+ }
539
+
527
540
  // src/number/toNumber.ts
528
541
  function toNumber(val) {
529
542
  if (val == null) {
@@ -1345,6 +1358,14 @@ function throttle(fn, delay2 = 200) {
1345
1358
  function NOOP() {
1346
1359
  }
1347
1360
 
1361
+ // src/function/callOrReturn.ts
1362
+ function callOrReturn(fnOrValue, ...args) {
1363
+ if (isFunction(fnOrValue)) {
1364
+ return fnOrValue(...args);
1365
+ }
1366
+ return fnOrValue;
1367
+ }
1368
+
1348
1369
  // src/collection/cloneDeepWith.ts
1349
1370
  function cloneDeepWith(value, fn) {
1350
1371
  const cache = /* @__PURE__ */ new WeakMap();
@@ -1608,6 +1629,7 @@ export {
1608
1629
  at,
1609
1630
  baseRound,
1610
1631
  call,
1632
+ callOrReturn,
1611
1633
  camelize,
1612
1634
  cancelAnimationFrame,
1613
1635
  ceil,
@@ -1641,6 +1663,8 @@ export {
1641
1663
  getScrollTop,
1642
1664
  getStyle,
1643
1665
  groupBy,
1666
+ hasDuplicates,
1667
+ hasDuplicatesBy,
1644
1668
  hasOwn,
1645
1669
  inBrowser,
1646
1670
  inMobile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "A utilities library for front-end developers, lightweight and ts-friendly",
5
5
  "keywords": [
6
6
  "utilities library",