rattail 1.0.1 → 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 +3 -3
- package/README.zh-CN.md +3 -3
- package/lib/index.cjs +30 -19
- package/lib/index.d.cts +3 -2
- package/lib/index.d.ts +3 -2
- package/lib/index.js +30 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<a href="https://rattail.
|
|
3
|
-
<img src="https://rattail.
|
|
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.
|
|
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>
|
package/README.zh-CN.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<a href="https://rattail.
|
|
3
|
-
<img src="https://rattail.
|
|
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.
|
|
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>
|
package/lib/index.cjs
CHANGED
|
@@ -1066,34 +1066,45 @@ function cloneDeep(value) {
|
|
|
1066
1066
|
}
|
|
1067
1067
|
|
|
1068
1068
|
// src/collection/mergeWith.ts
|
|
1069
|
-
function mergeWith(object,
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
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
|
+
}
|
|
1081
1093
|
} else {
|
|
1082
|
-
target[key3] =
|
|
1094
|
+
target[key3] = srcValue;
|
|
1083
1095
|
}
|
|
1084
|
-
} else {
|
|
1085
|
-
target[key3] = srcValue;
|
|
1086
1096
|
}
|
|
1087
1097
|
}
|
|
1098
|
+
return target;
|
|
1088
1099
|
}
|
|
1089
|
-
return
|
|
1100
|
+
return baseMerge(object2, source);
|
|
1090
1101
|
}
|
|
1091
|
-
return
|
|
1102
|
+
return result;
|
|
1092
1103
|
}
|
|
1093
1104
|
|
|
1094
1105
|
// src/collection/merge.ts
|
|
1095
|
-
function merge(object,
|
|
1096
|
-
return mergeWith(object,
|
|
1106
|
+
function merge(object, ...sources) {
|
|
1107
|
+
return mergeWith(object, ...sources, () => void 0);
|
|
1097
1108
|
}
|
|
1098
1109
|
|
|
1099
1110
|
// src/file/toArrayBuffer.ts
|
package/lib/index.d.cts
CHANGED
|
@@ -203,9 +203,10 @@ declare function cloneDeep<T>(value: T): T;
|
|
|
203
203
|
|
|
204
204
|
declare function cloneDeepWith<T>(value: T, fn: (value: any) => any): T;
|
|
205
205
|
|
|
206
|
-
declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T,
|
|
206
|
+
declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: K[]): T & K;
|
|
207
207
|
|
|
208
|
-
|
|
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;
|
|
209
210
|
|
|
210
211
|
declare function toArrayBuffer(file: File): Promise<ArrayBuffer>;
|
|
211
212
|
|
package/lib/index.d.ts
CHANGED
|
@@ -203,9 +203,10 @@ declare function cloneDeep<T>(value: T): T;
|
|
|
203
203
|
|
|
204
204
|
declare function cloneDeepWith<T>(value: T, fn: (value: any) => any): T;
|
|
205
205
|
|
|
206
|
-
declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T,
|
|
206
|
+
declare function merge<T extends Record<string, any>, K extends Record<string, any>>(object: T, ...sources: K[]): T & K;
|
|
207
207
|
|
|
208
|
-
|
|
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;
|
|
209
210
|
|
|
210
211
|
declare function toArrayBuffer(file: File): Promise<ArrayBuffer>;
|
|
211
212
|
|
package/lib/index.js
CHANGED
|
@@ -933,34 +933,45 @@ function cloneDeep(value) {
|
|
|
933
933
|
}
|
|
934
934
|
|
|
935
935
|
// src/collection/mergeWith.ts
|
|
936
|
-
function mergeWith(object,
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
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
|
+
}
|
|
948
960
|
} else {
|
|
949
|
-
target[key3] =
|
|
961
|
+
target[key3] = srcValue;
|
|
950
962
|
}
|
|
951
|
-
} else {
|
|
952
|
-
target[key3] = srcValue;
|
|
953
963
|
}
|
|
954
964
|
}
|
|
965
|
+
return target;
|
|
955
966
|
}
|
|
956
|
-
return
|
|
967
|
+
return baseMerge(object2, source);
|
|
957
968
|
}
|
|
958
|
-
return
|
|
969
|
+
return result;
|
|
959
970
|
}
|
|
960
971
|
|
|
961
972
|
// src/collection/merge.ts
|
|
962
|
-
function merge(object,
|
|
963
|
-
return mergeWith(object,
|
|
973
|
+
function merge(object, ...sources) {
|
|
974
|
+
return mergeWith(object, ...sources, () => void 0);
|
|
964
975
|
}
|
|
965
976
|
|
|
966
977
|
// src/file/toArrayBuffer.ts
|