rattail 1.0.3 → 1.0.4
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 +44 -0
- package/lib/index.d.cts +12 -2
- package/lib/index.d.ts +12 -2
- package/lib/index.js +40 -0
- package/package.json +3 -4
package/lib/index.cjs
CHANGED
|
@@ -53,6 +53,8 @@ __export(src_exports, {
|
|
|
53
53
|
createStorage: () => createStorage,
|
|
54
54
|
debounce: () => debounce,
|
|
55
55
|
delay: () => delay,
|
|
56
|
+
difference: () => difference,
|
|
57
|
+
differenceWith: () => differenceWith,
|
|
56
58
|
doubleRaf: () => doubleRaf,
|
|
57
59
|
ensurePrefix: () => ensurePrefix,
|
|
58
60
|
ensureSuffix: () => ensureSuffix,
|
|
@@ -70,6 +72,8 @@ __export(src_exports, {
|
|
|
70
72
|
inBrowser: () => inBrowser,
|
|
71
73
|
inMobile: () => inMobile,
|
|
72
74
|
inViewport: () => inViewport,
|
|
75
|
+
intersection: () => intersection,
|
|
76
|
+
intersectionWith: () => intersectionWith,
|
|
73
77
|
isArray: () => isArray,
|
|
74
78
|
isArrayBuffer: () => isArrayBuffer,
|
|
75
79
|
isBlob: () => isBlob,
|
|
@@ -587,6 +591,42 @@ function normalizeToArray(value) {
|
|
|
587
591
|
return isArray(value) ? value : [value];
|
|
588
592
|
}
|
|
589
593
|
|
|
594
|
+
// src/array/differenceWith.ts
|
|
595
|
+
function differenceWith(arr, ...values) {
|
|
596
|
+
const fn = at(values, -1);
|
|
597
|
+
const targets = values.slice(0, -1).reduce((targets2, value) => [...targets2, ...value], []);
|
|
598
|
+
return arr.filter((item) => !targets.some((value) => fn(item, value)));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/array/difference.ts
|
|
602
|
+
function difference(arr, ...values) {
|
|
603
|
+
return differenceWith(arr, ...values, (a, b) => a === b);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/array/intersectionWith.ts
|
|
607
|
+
function intersectionWith(...values) {
|
|
608
|
+
const fn = at(values, -1);
|
|
609
|
+
const targets = values.slice(0, -1);
|
|
610
|
+
if (targets.length === 0) {
|
|
611
|
+
return [];
|
|
612
|
+
}
|
|
613
|
+
if (targets.length === 1) {
|
|
614
|
+
return uniqBy(targets[0], fn);
|
|
615
|
+
}
|
|
616
|
+
function baseIntersectionWith(arr1, arr2) {
|
|
617
|
+
return arr1.filter((item) => arr2.some((value) => fn(item, value)));
|
|
618
|
+
}
|
|
619
|
+
return uniqBy(
|
|
620
|
+
targets.reduce((result, target) => baseIntersectionWith(result, target)),
|
|
621
|
+
fn
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/array/intersection.ts
|
|
626
|
+
function intersection(...values) {
|
|
627
|
+
return intersectionWith(...values, (a, b) => a === b);
|
|
628
|
+
}
|
|
629
|
+
|
|
590
630
|
// src/object/pick.ts
|
|
591
631
|
function pick(object, keys) {
|
|
592
632
|
return keys.reduce(
|
|
@@ -1237,6 +1277,8 @@ function sample(arr) {
|
|
|
1237
1277
|
createStorage,
|
|
1238
1278
|
debounce,
|
|
1239
1279
|
delay,
|
|
1280
|
+
difference,
|
|
1281
|
+
differenceWith,
|
|
1240
1282
|
doubleRaf,
|
|
1241
1283
|
ensurePrefix,
|
|
1242
1284
|
ensureSuffix,
|
|
@@ -1254,6 +1296,8 @@ function sample(arr) {
|
|
|
1254
1296
|
inBrowser,
|
|
1255
1297
|
inMobile,
|
|
1256
1298
|
inViewport,
|
|
1299
|
+
intersection,
|
|
1300
|
+
intersectionWith,
|
|
1257
1301
|
isArray,
|
|
1258
1302
|
isArrayBuffer,
|
|
1259
1303
|
isBlob,
|
package/lib/index.d.cts
CHANGED
|
@@ -20,6 +20,16 @@ declare function removeArrayEmpty<T>(arr: Array<T | null | undefined | ''>): T[]
|
|
|
20
20
|
|
|
21
21
|
declare function normalizeToArray<T>(value: T | T[]): T[];
|
|
22
22
|
|
|
23
|
+
declare function difference<T>(arr: T[], ...values: T[][]): T[];
|
|
24
|
+
|
|
25
|
+
type Fn$2<T> = (a: T, b: T) => any;
|
|
26
|
+
declare function differenceWith<T>(arr: T[], ...values: [...T[][], fn: Fn$2<T>]): T[];
|
|
27
|
+
|
|
28
|
+
declare function intersection<T>(...values: T[][]): T[];
|
|
29
|
+
|
|
30
|
+
type Fn$1<T> = (a: T, b: T) => any;
|
|
31
|
+
declare function intersectionWith<T>(...values: [...T[][], fn: Fn$1<T>]): T[];
|
|
32
|
+
|
|
23
33
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
24
34
|
|
|
25
35
|
declare function pickBy<T extends object>(object: T, fn: (value: any, key: keyof T) => any): Partial<T>;
|
|
@@ -39,7 +49,7 @@ declare function copyText(value: string): void;
|
|
|
39
49
|
type BEM<S extends string | undefined, N extends string, NC extends string> = S extends undefined ? NC : S extends `$--${infer CM}` ? `${N}--${CM}` : S extends `--${infer M}` ? `${NC}--${M}` : `${NC}__${S}`;
|
|
40
50
|
declare function createNamespaceFn<N extends string>(namespace: N): <C extends string>(name: C) => {
|
|
41
51
|
name: string;
|
|
42
|
-
n: <S extends string | undefined = undefined>(suffix?: S) => BEM<S,
|
|
52
|
+
n: <S extends string | undefined = undefined>(suffix?: S | undefined) => BEM<S, N, `${N}-${C}`>;
|
|
43
53
|
classes: typeof classes;
|
|
44
54
|
};
|
|
45
55
|
|
|
@@ -230,4 +240,4 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
|
|
|
230
240
|
|
|
231
241
|
declare function sample<T>(arr: T[]): T | undefined;
|
|
232
242
|
|
|
233
|
-
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, doubleRaf, ensurePrefix, ensureSuffix, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, 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, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst };
|
|
243
|
+
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, 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, 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
|
@@ -20,6 +20,16 @@ declare function removeArrayEmpty<T>(arr: Array<T | null | undefined | ''>): T[]
|
|
|
20
20
|
|
|
21
21
|
declare function normalizeToArray<T>(value: T | T[]): T[];
|
|
22
22
|
|
|
23
|
+
declare function difference<T>(arr: T[], ...values: T[][]): T[];
|
|
24
|
+
|
|
25
|
+
type Fn$2<T> = (a: T, b: T) => any;
|
|
26
|
+
declare function differenceWith<T>(arr: T[], ...values: [...T[][], fn: Fn$2<T>]): T[];
|
|
27
|
+
|
|
28
|
+
declare function intersection<T>(...values: T[][]): T[];
|
|
29
|
+
|
|
30
|
+
type Fn$1<T> = (a: T, b: T) => any;
|
|
31
|
+
declare function intersectionWith<T>(...values: [...T[][], fn: Fn$1<T>]): T[];
|
|
32
|
+
|
|
23
33
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
24
34
|
|
|
25
35
|
declare function pickBy<T extends object>(object: T, fn: (value: any, key: keyof T) => any): Partial<T>;
|
|
@@ -39,7 +49,7 @@ declare function copyText(value: string): void;
|
|
|
39
49
|
type BEM<S extends string | undefined, N extends string, NC extends string> = S extends undefined ? NC : S extends `$--${infer CM}` ? `${N}--${CM}` : S extends `--${infer M}` ? `${NC}--${M}` : `${NC}__${S}`;
|
|
40
50
|
declare function createNamespaceFn<N extends string>(namespace: N): <C extends string>(name: C) => {
|
|
41
51
|
name: string;
|
|
42
|
-
n: <S extends string | undefined = undefined>(suffix?: S) => BEM<S,
|
|
52
|
+
n: <S extends string | undefined = undefined>(suffix?: S | undefined) => BEM<S, N, `${N}-${C}`>;
|
|
43
53
|
classes: typeof classes;
|
|
44
54
|
};
|
|
45
55
|
|
|
@@ -230,4 +240,4 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
|
|
|
230
240
|
|
|
231
241
|
declare function sample<T>(arr: T[]): T | undefined;
|
|
232
242
|
|
|
233
|
-
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, doubleRaf, ensurePrefix, ensureSuffix, find, genNumberKey, genStringKey, getAllParentScroller, getGlobalThis, getParentScroller, getRect, getScrollLeft, getScrollTop, getStyle, hasOwn, inBrowser, inMobile, inViewport, 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, sample, sessionStorage, shuffle, slash, sum, sumBy, sumHash, supportTouch, throttle, times, toArrayBuffer, toDataURL, toNumber, toRawType, toText, toTypeString, toggleItem, tryParseJSON, uniq, uniqBy, upperFirst };
|
|
243
|
+
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, 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, 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
|
@@ -454,6 +454,42 @@ function normalizeToArray(value) {
|
|
|
454
454
|
return isArray(value) ? value : [value];
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
+
// src/array/differenceWith.ts
|
|
458
|
+
function differenceWith(arr, ...values) {
|
|
459
|
+
const fn = at(values, -1);
|
|
460
|
+
const targets = values.slice(0, -1).reduce((targets2, value) => [...targets2, ...value], []);
|
|
461
|
+
return arr.filter((item) => !targets.some((value) => fn(item, value)));
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/array/difference.ts
|
|
465
|
+
function difference(arr, ...values) {
|
|
466
|
+
return differenceWith(arr, ...values, (a, b) => a === b);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// src/array/intersectionWith.ts
|
|
470
|
+
function intersectionWith(...values) {
|
|
471
|
+
const fn = at(values, -1);
|
|
472
|
+
const targets = values.slice(0, -1);
|
|
473
|
+
if (targets.length === 0) {
|
|
474
|
+
return [];
|
|
475
|
+
}
|
|
476
|
+
if (targets.length === 1) {
|
|
477
|
+
return uniqBy(targets[0], fn);
|
|
478
|
+
}
|
|
479
|
+
function baseIntersectionWith(arr1, arr2) {
|
|
480
|
+
return arr1.filter((item) => arr2.some((value) => fn(item, value)));
|
|
481
|
+
}
|
|
482
|
+
return uniqBy(
|
|
483
|
+
targets.reduce((result, target) => baseIntersectionWith(result, target)),
|
|
484
|
+
fn
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// src/array/intersection.ts
|
|
489
|
+
function intersection(...values) {
|
|
490
|
+
return intersectionWith(...values, (a, b) => a === b);
|
|
491
|
+
}
|
|
492
|
+
|
|
457
493
|
// src/object/pick.ts
|
|
458
494
|
function pick(object, keys) {
|
|
459
495
|
return keys.reduce(
|
|
@@ -1103,6 +1139,8 @@ export {
|
|
|
1103
1139
|
createStorage,
|
|
1104
1140
|
debounce,
|
|
1105
1141
|
delay,
|
|
1142
|
+
difference,
|
|
1143
|
+
differenceWith,
|
|
1106
1144
|
doubleRaf,
|
|
1107
1145
|
ensurePrefix,
|
|
1108
1146
|
ensureSuffix,
|
|
@@ -1120,6 +1158,8 @@ export {
|
|
|
1120
1158
|
inBrowser,
|
|
1121
1159
|
inMobile,
|
|
1122
1160
|
inViewport,
|
|
1161
|
+
intersection,
|
|
1162
|
+
intersectionWith,
|
|
1123
1163
|
isArray,
|
|
1124
1164
|
isArrayBuffer,
|
|
1125
1165
|
isBlob,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rattail",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^22.8.1",
|
|
47
|
-
"@varlet/eslint-config": "
|
|
47
|
+
"@varlet/eslint-config": "^3.6.5",
|
|
48
48
|
"@varlet/release": "^0.3.1",
|
|
49
49
|
"@vitest/coverage-istanbul": "^2.1.3",
|
|
50
50
|
"eslint": "^8.53.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"rimraf": "^6.0.1",
|
|
55
55
|
"simple-git-hooks": "^2.11.1",
|
|
56
56
|
"tsup": "8.3.5",
|
|
57
|
-
"typescript": "
|
|
57
|
+
"typescript": "5.3.3",
|
|
58
58
|
"vitepress": "^1.4.1",
|
|
59
59
|
"vitest": "^2.1.3"
|
|
60
60
|
},
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"mitt": "^3.0.1"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
|
-
"git-hooks": "simple-git-hooks",
|
|
69
68
|
"dev": "tsup src/index.ts --format esm --out-dir=lib --watch --dts",
|
|
70
69
|
"build": "tsup src/index.ts --format esm,cjs --out-dir=lib --dts --clean",
|
|
71
70
|
"lint": "eslint . --fix --ext .ts,.js",
|