rattail 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/lib/index.cjs +28 -0
- package/lib/index.d.cts +10 -5
- package/lib/index.d.ts +10 -5
- package/lib/index.js +26 -0
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -68,6 +68,7 @@ __export(src_exports, {
|
|
|
68
68
|
getScrollLeft: () => getScrollLeft,
|
|
69
69
|
getScrollTop: () => getScrollTop,
|
|
70
70
|
getStyle: () => getStyle,
|
|
71
|
+
groupBy: () => groupBy,
|
|
71
72
|
hasOwn: () => hasOwn,
|
|
72
73
|
inBrowser: () => inBrowser,
|
|
73
74
|
inMobile: () => inMobile,
|
|
@@ -131,6 +132,7 @@ __export(src_exports, {
|
|
|
131
132
|
removeArrayEmpty: () => removeArrayEmpty,
|
|
132
133
|
removeItem: () => removeItem,
|
|
133
134
|
requestAnimationFrame: () => requestAnimationFrame,
|
|
135
|
+
round: () => round,
|
|
134
136
|
sample: () => sample,
|
|
135
137
|
sessionStorage: () => sessionStorage,
|
|
136
138
|
shuffle: () => shuffle,
|
|
@@ -627,6 +629,20 @@ function intersection(...values) {
|
|
|
627
629
|
return intersectionWith(...values, (a, b) => a === b);
|
|
628
630
|
}
|
|
629
631
|
|
|
632
|
+
// src/array/groupBy.ts
|
|
633
|
+
function groupBy(arr, fn) {
|
|
634
|
+
return arr.reduce(
|
|
635
|
+
(result, item) => {
|
|
636
|
+
var _a;
|
|
637
|
+
const key3 = fn(item);
|
|
638
|
+
result[key3] = (_a = result[key3]) != null ? _a : [];
|
|
639
|
+
result[key3].push(item);
|
|
640
|
+
return result;
|
|
641
|
+
},
|
|
642
|
+
{}
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
|
|
630
646
|
// src/object/pick.ts
|
|
631
647
|
function pick(object, keys) {
|
|
632
648
|
return keys.reduce(
|
|
@@ -1259,6 +1275,16 @@ function sample(arr) {
|
|
|
1259
1275
|
}
|
|
1260
1276
|
return arr[randomNumber(0, arr.length - 1)];
|
|
1261
1277
|
}
|
|
1278
|
+
|
|
1279
|
+
// src/math/round.ts
|
|
1280
|
+
function round(val, precision = 0) {
|
|
1281
|
+
precision = clamp(precision, -292, 292);
|
|
1282
|
+
if (!precision) {
|
|
1283
|
+
return Math.round(val);
|
|
1284
|
+
}
|
|
1285
|
+
const value = Math.round(`${val}e${precision}`);
|
|
1286
|
+
return +`${value}e${-precision}`;
|
|
1287
|
+
}
|
|
1262
1288
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1263
1289
|
0 && (module.exports = {
|
|
1264
1290
|
NOOP,
|
|
@@ -1292,6 +1318,7 @@ function sample(arr) {
|
|
|
1292
1318
|
getScrollLeft,
|
|
1293
1319
|
getScrollTop,
|
|
1294
1320
|
getStyle,
|
|
1321
|
+
groupBy,
|
|
1295
1322
|
hasOwn,
|
|
1296
1323
|
inBrowser,
|
|
1297
1324
|
inMobile,
|
|
@@ -1355,6 +1382,7 @@ function sample(arr) {
|
|
|
1355
1382
|
removeArrayEmpty,
|
|
1356
1383
|
removeItem,
|
|
1357
1384
|
requestAnimationFrame,
|
|
1385
|
+
round,
|
|
1358
1386
|
sample,
|
|
1359
1387
|
sessionStorage,
|
|
1360
1388
|
shuffle,
|
package/lib/index.d.cts
CHANGED
|
@@ -22,13 +22,16 @@ declare function normalizeToArray<T>(value: T | T[]): T[];
|
|
|
22
22
|
|
|
23
23
|
declare function difference<T>(arr: T[], ...values: T[][]): T[];
|
|
24
24
|
|
|
25
|
-
type Fn$
|
|
26
|
-
declare function differenceWith<T>(arr: T[], ...values: [...T[][], fn: Fn$
|
|
25
|
+
type Fn$3<T> = (a: T, b: T) => any;
|
|
26
|
+
declare function differenceWith<T>(arr: T[], ...values: [...T[][], fn: Fn$3<T>]): T[];
|
|
27
27
|
|
|
28
28
|
declare function intersection<T>(...values: T[][]): T[];
|
|
29
29
|
|
|
30
|
-
type Fn$
|
|
31
|
-
declare function intersectionWith<T>(...values: [...T[][], fn: Fn$
|
|
30
|
+
type Fn$2<T> = (a: T, b: T) => any;
|
|
31
|
+
declare function intersectionWith<T>(...values: [...T[][], fn: Fn$2<T>]): T[];
|
|
32
|
+
|
|
33
|
+
type Fn$1<T> = (val: T) => any;
|
|
34
|
+
declare function groupBy<T>(arr: T[], fn: Fn$1<T>): Record<string, T[]>;
|
|
32
35
|
|
|
33
36
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
34
37
|
|
|
@@ -240,4 +243,6 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
|
|
|
240
243
|
|
|
241
244
|
declare function sample<T>(arr: T[]): T | undefined;
|
|
242
245
|
|
|
243
|
-
|
|
246
|
+
declare function round(val: number, precision?: number): number;
|
|
247
|
+
|
|
248
|
+
export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, ensurePrefix, ensureSuffix, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, 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 };
|
package/lib/index.d.ts
CHANGED
|
@@ -22,13 +22,16 @@ declare function normalizeToArray<T>(value: T | T[]): T[];
|
|
|
22
22
|
|
|
23
23
|
declare function difference<T>(arr: T[], ...values: T[][]): T[];
|
|
24
24
|
|
|
25
|
-
type Fn$
|
|
26
|
-
declare function differenceWith<T>(arr: T[], ...values: [...T[][], fn: Fn$
|
|
25
|
+
type Fn$3<T> = (a: T, b: T) => any;
|
|
26
|
+
declare function differenceWith<T>(arr: T[], ...values: [...T[][], fn: Fn$3<T>]): T[];
|
|
27
27
|
|
|
28
28
|
declare function intersection<T>(...values: T[][]): T[];
|
|
29
29
|
|
|
30
|
-
type Fn$
|
|
31
|
-
declare function intersectionWith<T>(...values: [...T[][], fn: Fn$
|
|
30
|
+
type Fn$2<T> = (a: T, b: T) => any;
|
|
31
|
+
declare function intersectionWith<T>(...values: [...T[][], fn: Fn$2<T>]): T[];
|
|
32
|
+
|
|
33
|
+
type Fn$1<T> = (val: T) => any;
|
|
34
|
+
declare function groupBy<T>(arr: T[], fn: Fn$1<T>): Record<string, T[]>;
|
|
32
35
|
|
|
33
36
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
34
37
|
|
|
@@ -240,4 +243,6 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
|
|
|
240
243
|
|
|
241
244
|
declare function sample<T>(arr: T[]): T | undefined;
|
|
242
245
|
|
|
243
|
-
|
|
246
|
+
declare function round(val: number, precision?: number): number;
|
|
247
|
+
|
|
248
|
+
export { type BEM, type ClassName, type Classes, NOOP, type Storage, at, call, camelize, cancelAnimationFrame, chunk, clamp, clampArrayRange, classes, cloneDeep, cloneDeepWith, copyText, createNamespaceFn, createStorage, debounce, delay, difference, differenceWith, doubleRaf, ensurePrefix, ensureSuffix, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, groupBy, hasOwn, inBrowser, inMobile, inViewport, intersection, intersectionWith, isArray, isArrayBuffer, isBlob, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEqual, isEqualWith, isError, isFile, isFunction, isMap, isNonEmptyArray, isNullish, isNumber, isNumeric, isObject, isPlainObject, isPromise, isRegExp, isSet, isString, isSymbol, isTruthy, isTypedArray, isWeakMap, isWeakSet, isWindow, kebabCase, localStorage, lowerFirst, maxBy, mean, meanBy, merge, mergeWith, minBy, normalizeToArray, objectToString, omit, omitBy, once, pascalCase, pick, pickBy, prettyJSONObject, preventDefault, 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 };
|
package/lib/index.js
CHANGED
|
@@ -490,6 +490,20 @@ function intersection(...values) {
|
|
|
490
490
|
return intersectionWith(...values, (a, b) => a === b);
|
|
491
491
|
}
|
|
492
492
|
|
|
493
|
+
// src/array/groupBy.ts
|
|
494
|
+
function groupBy(arr, fn) {
|
|
495
|
+
return arr.reduce(
|
|
496
|
+
(result, item) => {
|
|
497
|
+
var _a;
|
|
498
|
+
const key3 = fn(item);
|
|
499
|
+
result[key3] = (_a = result[key3]) != null ? _a : [];
|
|
500
|
+
result[key3].push(item);
|
|
501
|
+
return result;
|
|
502
|
+
},
|
|
503
|
+
{}
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
|
|
493
507
|
// src/object/pick.ts
|
|
494
508
|
function pick(object, keys) {
|
|
495
509
|
return keys.reduce(
|
|
@@ -1122,6 +1136,16 @@ function sample(arr) {
|
|
|
1122
1136
|
}
|
|
1123
1137
|
return arr[randomNumber(0, arr.length - 1)];
|
|
1124
1138
|
}
|
|
1139
|
+
|
|
1140
|
+
// src/math/round.ts
|
|
1141
|
+
function round(val, precision = 0) {
|
|
1142
|
+
precision = clamp(precision, -292, 292);
|
|
1143
|
+
if (!precision) {
|
|
1144
|
+
return Math.round(val);
|
|
1145
|
+
}
|
|
1146
|
+
const value = Math.round(`${val}e${precision}`);
|
|
1147
|
+
return +`${value}e${-precision}`;
|
|
1148
|
+
}
|
|
1125
1149
|
export {
|
|
1126
1150
|
NOOP,
|
|
1127
1151
|
at,
|
|
@@ -1154,6 +1178,7 @@ export {
|
|
|
1154
1178
|
getScrollLeft,
|
|
1155
1179
|
getScrollTop,
|
|
1156
1180
|
getStyle,
|
|
1181
|
+
groupBy,
|
|
1157
1182
|
hasOwn,
|
|
1158
1183
|
inBrowser,
|
|
1159
1184
|
inMobile,
|
|
@@ -1217,6 +1242,7 @@ export {
|
|
|
1217
1242
|
removeArrayEmpty,
|
|
1218
1243
|
removeItem,
|
|
1219
1244
|
requestAnimationFrame,
|
|
1245
|
+
round,
|
|
1220
1246
|
sample,
|
|
1221
1247
|
sessionStorage,
|
|
1222
1248
|
shuffle,
|