rattail 1.0.16 → 1.0.18

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
@@ -49,6 +49,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
49
49
  var src_exports = {};
50
50
  __export(src_exports, {
51
51
  NOOP: () => NOOP,
52
+ assert: () => assert,
52
53
  at: () => at,
53
54
  baseRound: () => baseRound,
54
55
  call: () => call,
@@ -523,6 +524,13 @@ function isEmptyPlainObject(val) {
523
524
  return isPlainObject(val) && Object.keys(val).length === 0 && Object.getOwnPropertySymbols(val).length === 0;
524
525
  }
525
526
 
527
+ // src/general/assert.ts
528
+ function assert(condition, message) {
529
+ if (!condition) {
530
+ throw new Error(message);
531
+ }
532
+ }
533
+
526
534
  // src/number/toNumber.ts
527
535
  function toNumber(val) {
528
536
  if (val == null) {
@@ -668,8 +676,7 @@ function groupBy(arr, fn) {
668
676
  (result, item) => {
669
677
  var _a;
670
678
  const key3 = fn(item);
671
- result[key3] = (_a = result[key3]) != null ? _a : [];
672
- result[key3].push(item);
679
+ ((_a = result[key3]) != null ? _a : result[key3] = []).push(item);
673
680
  return result;
674
681
  },
675
682
  {}
@@ -1398,17 +1405,11 @@ function toText(file) {
1398
1405
 
1399
1406
  // src/math/maxBy.ts
1400
1407
  function maxBy(arr, fn) {
1401
- if (!arr.length) {
1402
- return;
1403
- }
1404
1408
  return arr.reduce((result, item) => fn(result) > fn(item) ? result : item, arr[0]);
1405
1409
  }
1406
1410
 
1407
1411
  // src/math/minBy.ts
1408
1412
  function minBy(arr, fn) {
1409
- if (!arr.length) {
1410
- return;
1411
- }
1412
1413
  return arr.reduce((result, item) => fn(result) < fn(item) ? result : item, arr[0]);
1413
1414
  }
1414
1415
 
@@ -1501,6 +1502,7 @@ function ceil(val, precision = 0) {
1501
1502
  // Annotate the CommonJS export names for ESM import in node:
1502
1503
  0 && (module.exports = {
1503
1504
  NOOP,
1505
+ assert,
1504
1506
  at,
1505
1507
  baseRound,
1506
1508
  call,
package/lib/index.d.cts CHANGED
@@ -219,6 +219,8 @@ declare function isPrimitive(val: unknown): boolean;
219
219
 
220
220
  declare function isEmptyPlainObject(val: unknown): val is Record<string, any>;
221
221
 
222
+ declare function assert(condition: boolean, message: string): asserts condition;
223
+
222
224
  declare function clamp(num: number, min: number, max: number): number;
223
225
 
224
226
  declare function clampArrayRange(index: number, arr: unknown[]): number;
@@ -270,9 +272,9 @@ declare function toDataURL(file: File): Promise<string>;
270
272
 
271
273
  declare function toText(file: File): Promise<string>;
272
274
 
273
- declare function maxBy<T>(arr: T[], fn: (val: T) => number): T | undefined;
275
+ declare function maxBy<T>(arr: T[], fn: (val: T) => number): T;
274
276
 
275
- declare function minBy<T>(arr: T[], fn: (val: T) => number): T | undefined;
277
+ declare function minBy<T>(arr: T[], fn: (val: T) => number): T;
276
278
 
277
279
  declare function sum(arr: number[]): number;
278
280
 
@@ -293,4 +295,4 @@ declare function floor(val: number, precision?: number): number;
293
295
 
294
296
  declare function ceil(val: number, precision?: number): number;
295
297
 
296
- export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, 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, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
298
+ export { type BEM, type ClassName, type Classes, 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, 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, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, 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
@@ -219,6 +219,8 @@ declare function isPrimitive(val: unknown): boolean;
219
219
 
220
220
  declare function isEmptyPlainObject(val: unknown): val is Record<string, any>;
221
221
 
222
+ declare function assert(condition: boolean, message: string): asserts condition;
223
+
222
224
  declare function clamp(num: number, min: number, max: number): number;
223
225
 
224
226
  declare function clampArrayRange(index: number, arr: unknown[]): number;
@@ -270,9 +272,9 @@ declare function toDataURL(file: File): Promise<string>;
270
272
 
271
273
  declare function toText(file: File): Promise<string>;
272
274
 
273
- declare function maxBy<T>(arr: T[], fn: (val: T) => number): T | undefined;
275
+ declare function maxBy<T>(arr: T[], fn: (val: T) => number): T;
274
276
 
275
- declare function minBy<T>(arr: T[], fn: (val: T) => number): T | undefined;
277
+ declare function minBy<T>(arr: T[], fn: (val: T) => number): T;
276
278
 
277
279
  declare function sum(arr: number[]): number;
278
280
 
@@ -293,4 +295,4 @@ declare function floor(val: number, precision?: number): number;
293
295
 
294
296
  declare function ceil(val: number, precision?: number): number;
295
297
 
296
- export { type BEM, type ClassName, type Classes, type Motion, type MotionOptions, type MotionState, NOOP, type PromiseWithResolvers, type Storage, at, baseRound, call, camelize, cancelAnimationFrame, ceil, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, download, 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, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
298
+ export { type BEM, type ClassName, type Classes, 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, 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, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, promiseWithResolvers, raf, randomColor, randomNumber, randomString, removeArrayBlank, removeArrayEmpty, removeItem, requestAnimationFrame, round, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst, xor, xorWith };
@@ -39,6 +39,7 @@ var Rattail = (() => {
39
39
  var src_exports = {};
40
40
  __export(src_exports, {
41
41
  NOOP: () => NOOP,
42
+ assert: () => assert,
42
43
  at: () => at,
43
44
  baseRound: () => baseRound,
44
45
  call: () => call,
@@ -512,6 +513,13 @@ var Rattail = (() => {
512
513
  return isPlainObject(val) && Object.keys(val).length === 0 && Object.getOwnPropertySymbols(val).length === 0;
513
514
  }
514
515
 
516
+ // src/general/assert.ts
517
+ function assert(condition, message) {
518
+ if (!condition) {
519
+ throw new Error(message);
520
+ }
521
+ }
522
+
515
523
  // src/number/toNumber.ts
516
524
  function toNumber(val) {
517
525
  if (val == null) {
@@ -657,8 +665,7 @@ var Rattail = (() => {
657
665
  (result, item) => {
658
666
  var _a;
659
667
  const key3 = fn(item);
660
- result[key3] = (_a = result[key3]) != null ? _a : [];
661
- result[key3].push(item);
668
+ ((_a = result[key3]) != null ? _a : result[key3] = []).push(item);
662
669
  return result;
663
670
  },
664
671
  {}
@@ -1370,17 +1377,11 @@ var Rattail = (() => {
1370
1377
 
1371
1378
  // src/math/maxBy.ts
1372
1379
  function maxBy(arr, fn) {
1373
- if (!arr.length) {
1374
- return;
1375
- }
1376
1380
  return arr.reduce((result, item) => fn(result) > fn(item) ? result : item, arr[0]);
1377
1381
  }
1378
1382
 
1379
1383
  // src/math/minBy.ts
1380
1384
  function minBy(arr, fn) {
1381
- if (!arr.length) {
1382
- return;
1383
- }
1384
1385
  return arr.reduce((result, item) => fn(result) < fn(item) ? result : item, arr[0]);
1385
1386
  }
1386
1387
 
package/lib/index.js CHANGED
@@ -37,6 +37,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
37
37
  var src_exports = {};
38
38
  __export(src_exports, {
39
39
  NOOP: () => NOOP,
40
+ assert: () => assert,
40
41
  at: () => at,
41
42
  baseRound: () => baseRound,
42
43
  call: () => call,
@@ -510,6 +511,13 @@ function isEmptyPlainObject(val) {
510
511
  return isPlainObject(val) && Object.keys(val).length === 0 && Object.getOwnPropertySymbols(val).length === 0;
511
512
  }
512
513
 
514
+ // src/general/assert.ts
515
+ function assert(condition, message) {
516
+ if (!condition) {
517
+ throw new Error(message);
518
+ }
519
+ }
520
+
513
521
  // src/number/toNumber.ts
514
522
  function toNumber(val) {
515
523
  if (val == null) {
@@ -655,8 +663,7 @@ function groupBy(arr, fn) {
655
663
  (result, item) => {
656
664
  var _a;
657
665
  const key3 = fn(item);
658
- result[key3] = (_a = result[key3]) != null ? _a : [];
659
- result[key3].push(item);
666
+ ((_a = result[key3]) != null ? _a : result[key3] = []).push(item);
660
667
  return result;
661
668
  },
662
669
  {}
@@ -1386,17 +1393,11 @@ function toText(file) {
1386
1393
 
1387
1394
  // src/math/maxBy.ts
1388
1395
  function maxBy(arr, fn) {
1389
- if (!arr.length) {
1390
- return;
1391
- }
1392
1396
  return arr.reduce((result, item) => fn(result) > fn(item) ? result : item, arr[0]);
1393
1397
  }
1394
1398
 
1395
1399
  // src/math/minBy.ts
1396
1400
  function minBy(arr, fn) {
1397
- if (!arr.length) {
1398
- return;
1399
- }
1400
1401
  return arr.reduce((result, item) => fn(result) < fn(item) ? result : item, arr[0]);
1401
1402
  }
1402
1403
 
@@ -1488,6 +1489,7 @@ function ceil(val, precision = 0) {
1488
1489
  }
1489
1490
  export {
1490
1491
  NOOP,
1492
+ assert,
1491
1493
  at,
1492
1494
  baseRound,
1493
1495
  call,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",