rattail 1.0.0 → 1.0.2

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
@@ -1,11 +1,11 @@
1
1
  <div align="center">
2
- <a href="https://rattail.pages.dev">
3
- <img src="https://rattail.pages.dev/logo.svg" width="150">
2
+ <a href="https://rattail.varletjs.org">
3
+ <img src="https://rattail.varletjs.org/logo.svg" width="150">
4
4
  </a>
5
5
  <h1>Rattail</h1>
6
6
  <p>A utilities library for front-end developers, lightweight and ts-friendly.</p>
7
7
  <p>
8
- <a href="https://rattail.pages.dev">Documentation</a> |
8
+ <a href="https://rattail.varletjs.org">Documentation</a> |
9
9
  <a href="https://github.com/varletjs/rattail/blob/main/README.zh-CN.md">中文介绍</a>
10
10
  </p>
11
11
  <p>
@@ -24,7 +24,7 @@
24
24
  - 🛠️ &nbsp; Provide utilities frequently used in daily development
25
25
  - 🛠️ &nbsp; Utilities implementation is very lightweight
26
26
  - 🛠️ &nbsp; Written based on ts, providing complete ts types
27
- - 💪 &nbsp; Make sure more than 90% unit test coverage, providing stability assurance
27
+ - 💪 &nbsp; Make sure more than 99% unit test coverage, providing stability assurance
28
28
 
29
29
  ### Installation
30
30
 
package/README.zh-CN.md CHANGED
@@ -1,11 +1,11 @@
1
1
  <div align="center">
2
- <a href="https://rattail.pages.dev/zh">
3
- <img src="https://rattail.pages.dev/logo.svg" width="150">
2
+ <a href="https://rattail.varletjs.org/zh">
3
+ <img src="https://rattail.varletjs.org/logo.svg" width="150">
4
4
  </a>
5
5
  <h1>Rattail</h1>
6
6
  <p>面向前端开发人员的实用工具库,轻量级且 ts 友好</p>
7
7
  <p>
8
- <a href="https://rattail.pages.dev/zh">文档</a> |
8
+ <a href="https://rattail.varletjs.org/zh">文档</a> |
9
9
  <a href="https://github.com/varletjs/rattail/blob/main/README.md">ENGLISH README</a>
10
10
  </p>
11
11
  <p>
@@ -24,7 +24,7 @@
24
24
  - 🛠️ &nbsp; 提供日常开发中经常使用的实用工具
25
25
  - 🛠️ &nbsp; 工具实现非常轻量
26
26
  - 🛠️ &nbsp; 使用 ts 编写,提供完善的类型支持
27
- - 💪 &nbsp; 确保 90% 以上单元测试覆盖率,提供稳定性保证
27
+ - 💪 &nbsp; 确保 99% 以上单元测试覆盖率,提供稳定性保证
28
28
 
29
29
  ### 安装
30
30
 
package/lib/index.cjs CHANGED
@@ -72,6 +72,7 @@ __export(src_exports, {
72
72
  inViewport: () => inViewport,
73
73
  isArray: () => isArray,
74
74
  isArrayBuffer: () => isArrayBuffer,
75
+ isBlob: () => isBlob,
75
76
  isBoolean: () => isBoolean,
76
77
  isDOMException: () => isDOMException,
77
78
  isDataView: () => isDataView,
@@ -80,6 +81,7 @@ __export(src_exports, {
80
81
  isEqual: () => isEqual,
81
82
  isEqualWith: () => isEqualWith,
82
83
  isError: () => isError,
84
+ isFile: () => isFile,
83
85
  isFunction: () => isFunction,
84
86
  isMap: () => isMap,
85
87
  isNonEmptyArray: () => isNonEmptyArray,
@@ -472,6 +474,16 @@ function supportTouch() {
472
474
  return inBrowser() && "ontouchstart" in window;
473
475
  }
474
476
 
477
+ // src/general/isFile.ts
478
+ function isFile(val) {
479
+ return toRawType(val) === "File";
480
+ }
481
+
482
+ // src/general/isBlob.ts
483
+ function isBlob(val) {
484
+ return toRawType(val) === "Blob";
485
+ }
486
+
475
487
  // src/number/toNumber.ts
476
488
  function toNumber(val) {
477
489
  if (val == null) {
@@ -1054,34 +1066,45 @@ function cloneDeep(value) {
1054
1066
  }
1055
1067
 
1056
1068
  // src/collection/mergeWith.ts
1057
- function mergeWith(object, source, fn) {
1058
- function baseMerge(target, src) {
1059
- for (const key3 in src) {
1060
- if (hasOwn(src, key3)) {
1061
- const srcValue = src[key3];
1062
- const targetValue = target[key3];
1063
- const customResult = fn(targetValue, srcValue, key3, object, source);
1064
- if (customResult !== void 0) {
1065
- target[key3] = customResult;
1066
- } else if (isObject(srcValue)) {
1067
- if (isObject(targetValue)) {
1068
- target[key3] = baseMerge(targetValue, srcValue);
1069
+ function mergeWith(object, ...sources) {
1070
+ const fn = at(sources, -1);
1071
+ const targets = [object, ...sources.slice(0, -1)];
1072
+ let len = targets.length - 1;
1073
+ let result = targets[len];
1074
+ while (len) {
1075
+ result = baseMergeWith(targets[len - 1], result, fn);
1076
+ len--;
1077
+ }
1078
+ function baseMergeWith(object2, source, fn2) {
1079
+ function baseMerge(target, src) {
1080
+ for (const key3 in src) {
1081
+ if (hasOwn(src, key3)) {
1082
+ const srcValue = src[key3];
1083
+ const targetValue = target[key3];
1084
+ const customResult = fn2(targetValue, srcValue, key3, object2, source);
1085
+ if (customResult !== void 0) {
1086
+ target[key3] = customResult;
1087
+ } else if (isObject(srcValue)) {
1088
+ if (isObject(targetValue)) {
1089
+ target[key3] = baseMerge(targetValue, srcValue);
1090
+ } else {
1091
+ target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
1092
+ }
1069
1093
  } else {
1070
- target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
1094
+ target[key3] = srcValue;
1071
1095
  }
1072
- } else {
1073
- target[key3] = srcValue;
1074
1096
  }
1075
1097
  }
1098
+ return target;
1076
1099
  }
1077
- return target;
1100
+ return baseMerge(object2, source);
1078
1101
  }
1079
- return baseMerge(object, source);
1102
+ return result;
1080
1103
  }
1081
1104
 
1082
1105
  // src/collection/merge.ts
1083
- function merge(object, source) {
1084
- return mergeWith(object, source, () => void 0);
1106
+ function merge(object, ...sources) {
1107
+ return mergeWith(object, ...sources, () => void 0);
1085
1108
  }
1086
1109
 
1087
1110
  // src/file/toArrayBuffer.ts
@@ -1233,6 +1256,7 @@ function sample(arr) {
1233
1256
  inViewport,
1234
1257
  isArray,
1235
1258
  isArrayBuffer,
1259
+ isBlob,
1236
1260
  isBoolean,
1237
1261
  isDOMException,
1238
1262
  isDataView,
@@ -1241,6 +1265,7 @@ function sample(arr) {
1241
1265
  isEqual,
1242
1266
  isEqualWith,
1243
1267
  isError,
1268
+ isFile,
1244
1269
  isFunction,
1245
1270
  isMap,
1246
1271
  isNonEmptyArray,
package/lib/index.d.cts CHANGED
@@ -159,6 +159,10 @@ declare function toRawType(value: unknown): string;
159
159
  declare const objectToString: typeof Object.prototype.toString;
160
160
  declare function toTypeString(value: unknown): string;
161
161
 
162
+ declare function isFile(val: unknown): val is File;
163
+
164
+ declare function isBlob(val: unknown): val is Blob;
165
+
162
166
  declare function clamp(num: number, min: number, max: number): number;
163
167
 
164
168
  declare function clampArrayRange(index: number, arr: Array<unknown>): number;
@@ -199,9 +203,10 @@ declare function cloneDeep<T>(value: T): T;
199
203
 
200
204
  declare function cloneDeepWith<T>(value: T, fn: (value: any) => any): T;
201
205
 
202
- declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T, source: K): T & K;
206
+ declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: K[]): T & K;
203
207
 
204
- declare function mergeWith<T extends Record<string, any>, K extends Record<string, any>>(object: T, source: K, fn: (objValue: any, srcValue: any, key: string | number | symbol, object?: T, source?: K) => any): T & K;
208
+ type Fn = (objValue: any, srcValue: any, key: string | number | symbol, object?: any, source?: any) => any;
209
+ declare function mergeWith<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: [...K[], fn: Fn]): T & K;
205
210
 
206
211
  declare function toArrayBuffer(file: File): Promise<ArrayBuffer>;
207
212
 
@@ -225,4 +230,4 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
225
230
 
226
231
  declare function sample<T>(arr: T[]): T | undefined;
227
232
 
228
- 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, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEqual, isEqualWith, isError, 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 };
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 };
package/lib/index.d.ts CHANGED
@@ -159,6 +159,10 @@ declare function toRawType(value: unknown): string;
159
159
  declare const objectToString: typeof Object.prototype.toString;
160
160
  declare function toTypeString(value: unknown): string;
161
161
 
162
+ declare function isFile(val: unknown): val is File;
163
+
164
+ declare function isBlob(val: unknown): val is Blob;
165
+
162
166
  declare function clamp(num: number, min: number, max: number): number;
163
167
 
164
168
  declare function clampArrayRange(index: number, arr: Array<unknown>): number;
@@ -199,9 +203,10 @@ declare function cloneDeep<T>(value: T): T;
199
203
 
200
204
  declare function cloneDeepWith<T>(value: T, fn: (value: any) => any): T;
201
205
 
202
- declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T, source: K): T & K;
206
+ declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: K[]): T & K;
203
207
 
204
- declare function mergeWith<T extends Record<string, any>, K extends Record<string, any>>(object: T, source: K, fn: (objValue: any, srcValue: any, key: string | number | symbol, object?: T, source?: K) => any): T & K;
208
+ type Fn = (objValue: any, srcValue: any, key: string | number | symbol, object?: any, source?: any) => any;
209
+ declare function mergeWith<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: [...K[], fn: Fn]): T & K;
205
210
 
206
211
  declare function toArrayBuffer(file: File): Promise<ArrayBuffer>;
207
212
 
@@ -225,4 +230,4 @@ declare function meanBy<T>(arr: T[], fn: (val: T) => number): number;
225
230
 
226
231
  declare function sample<T>(arr: T[]): T | undefined;
227
232
 
228
- 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, isBoolean, isDOMException, isDataView, isDate, isEmpty, isEqual, isEqualWith, isError, 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 };
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 };
package/lib/index.js CHANGED
@@ -341,6 +341,16 @@ function supportTouch() {
341
341
  return inBrowser() && "ontouchstart" in window;
342
342
  }
343
343
 
344
+ // src/general/isFile.ts
345
+ function isFile(val) {
346
+ return toRawType(val) === "File";
347
+ }
348
+
349
+ // src/general/isBlob.ts
350
+ function isBlob(val) {
351
+ return toRawType(val) === "Blob";
352
+ }
353
+
344
354
  // src/number/toNumber.ts
345
355
  function toNumber(val) {
346
356
  if (val == null) {
@@ -923,34 +933,45 @@ function cloneDeep(value) {
923
933
  }
924
934
 
925
935
  // src/collection/mergeWith.ts
926
- function mergeWith(object, source, fn) {
927
- function baseMerge(target, src) {
928
- for (const key3 in src) {
929
- if (hasOwn(src, key3)) {
930
- const srcValue = src[key3];
931
- const targetValue = target[key3];
932
- const customResult = fn(targetValue, srcValue, key3, object, source);
933
- if (customResult !== void 0) {
934
- target[key3] = customResult;
935
- } else if (isObject(srcValue)) {
936
- if (isObject(targetValue)) {
937
- target[key3] = baseMerge(targetValue, srcValue);
936
+ function mergeWith(object, ...sources) {
937
+ const fn = at(sources, -1);
938
+ const targets = [object, ...sources.slice(0, -1)];
939
+ let len = targets.length - 1;
940
+ let result = targets[len];
941
+ while (len) {
942
+ result = baseMergeWith(targets[len - 1], result, fn);
943
+ len--;
944
+ }
945
+ function baseMergeWith(object2, source, fn2) {
946
+ function baseMerge(target, src) {
947
+ for (const key3 in src) {
948
+ if (hasOwn(src, key3)) {
949
+ const srcValue = src[key3];
950
+ const targetValue = target[key3];
951
+ const customResult = fn2(targetValue, srcValue, key3, object2, source);
952
+ if (customResult !== void 0) {
953
+ target[key3] = customResult;
954
+ } else if (isObject(srcValue)) {
955
+ if (isObject(targetValue)) {
956
+ target[key3] = baseMerge(targetValue, srcValue);
957
+ } else {
958
+ target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
959
+ }
938
960
  } else {
939
- target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
961
+ target[key3] = srcValue;
940
962
  }
941
- } else {
942
- target[key3] = srcValue;
943
963
  }
944
964
  }
965
+ return target;
945
966
  }
946
- return target;
967
+ return baseMerge(object2, source);
947
968
  }
948
- return baseMerge(object, source);
969
+ return result;
949
970
  }
950
971
 
951
972
  // src/collection/merge.ts
952
- function merge(object, source) {
953
- return mergeWith(object, source, () => void 0);
973
+ function merge(object, ...sources) {
974
+ return mergeWith(object, ...sources, () => void 0);
954
975
  }
955
976
 
956
977
  // src/file/toArrayBuffer.ts
@@ -1101,6 +1122,7 @@ export {
1101
1122
  inViewport,
1102
1123
  isArray,
1103
1124
  isArrayBuffer,
1125
+ isBlob,
1104
1126
  isBoolean,
1105
1127
  isDOMException,
1106
1128
  isDataView,
@@ -1109,6 +1131,7 @@ export {
1109
1131
  isEqual,
1110
1132
  isEqualWith,
1111
1133
  isError,
1134
+ isFile,
1112
1135
  isFunction,
1113
1136
  isMap,
1114
1137
  isNonEmptyArray,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",