es-toolkit 1.18.0-dev.575 → 1.18.0-dev.577
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/dist/_chunk/range-BXlMmn.js +68 -0
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/decimalAdjust.mjs +19 -0
- package/dist/compat/index.d.mts +3 -1
- package/dist/compat/index.d.ts +3 -1
- package/dist/compat/index.js +70 -18
- package/dist/compat/index.mjs +3 -1
- package/dist/compat/math/ceil.d.mts +15 -0
- package/dist/compat/math/ceil.d.ts +15 -0
- package/dist/compat/math/ceil.mjs +7 -0
- package/dist/compat/math/floor.d.mts +15 -0
- package/dist/compat/math/floor.d.ts +15 -0
- package/dist/compat/math/floor.mjs +7 -0
- package/dist/compat/math/round.d.mts +15 -0
- package/dist/compat/math/round.d.ts +15 -0
- package/dist/compat/math/round.mjs +7 -0
- package/dist/compat/object/pick.d.mts +20 -2
- package/dist/compat/object/pick.d.ts +20 -2
- package/dist/compat/object/pick.mjs +26 -16
- package/dist/compat/predicate/isNil.mjs +5 -0
- package/dist/index.js +10 -9
- package/dist/math/index.js +8 -66
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function decimalAdjust(type, number, precision = 0) {
|
|
2
|
+
number = Number(number);
|
|
3
|
+
if (Object.is(number, -0)) {
|
|
4
|
+
number = '-0';
|
|
5
|
+
}
|
|
6
|
+
precision = Math.min(Number.parseInt(precision, 10), 292);
|
|
7
|
+
if (precision) {
|
|
8
|
+
const [magnitude, exponent = 0] = number.toString().split('e');
|
|
9
|
+
let adjustedValue = Math[type](Number(`${magnitude}e${Number(exponent) + precision}`));
|
|
10
|
+
if (Object.is(adjustedValue, -0)) {
|
|
11
|
+
adjustedValue = '-0';
|
|
12
|
+
}
|
|
13
|
+
const [newMagnitude, newExponent = 0] = adjustedValue.toString().split('e');
|
|
14
|
+
return Number(`${newMagnitude}e${Number(newExponent) - precision}`);
|
|
15
|
+
}
|
|
16
|
+
return Math[type](Number(number));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { decimalAdjust };
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -66,7 +66,6 @@ export { mean } from '../math/mean.mjs';
|
|
|
66
66
|
export { meanBy } from '../math/meanBy.mjs';
|
|
67
67
|
export { random } from '../math/random.mjs';
|
|
68
68
|
export { randomInt } from '../math/randomInt.mjs';
|
|
69
|
-
export { round } from '../math/round.mjs';
|
|
70
69
|
export { sum } from '../math/sum.mjs';
|
|
71
70
|
export { sumBy } from '../math/sumBy.mjs';
|
|
72
71
|
export { range } from '../math/range.mjs';
|
|
@@ -163,4 +162,7 @@ export { padEnd } from './string/padEnd.mjs';
|
|
|
163
162
|
export { repeat } from './string/repeat.mjs';
|
|
164
163
|
export { max } from './math/max.mjs';
|
|
165
164
|
export { min } from './math/min.mjs';
|
|
165
|
+
export { ceil } from './math/ceil.mjs';
|
|
166
|
+
export { floor } from './math/floor.mjs';
|
|
167
|
+
export { round } from './math/round.mjs';
|
|
166
168
|
export { parseInt } from './math/parseInt.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -66,7 +66,6 @@ export { mean } from '../math/mean.js';
|
|
|
66
66
|
export { meanBy } from '../math/meanBy.js';
|
|
67
67
|
export { random } from '../math/random.js';
|
|
68
68
|
export { randomInt } from '../math/randomInt.js';
|
|
69
|
-
export { round } from '../math/round.js';
|
|
70
69
|
export { sum } from '../math/sum.js';
|
|
71
70
|
export { sumBy } from '../math/sumBy.js';
|
|
72
71
|
export { range } from '../math/range.js';
|
|
@@ -163,4 +162,7 @@ export { padEnd } from './string/padEnd.js';
|
|
|
163
162
|
export { repeat } from './string/repeat.js';
|
|
164
163
|
export { max } from './math/max.js';
|
|
165
164
|
export { min } from './math/min.js';
|
|
165
|
+
export { ceil } from './math/ceil.js';
|
|
166
|
+
export { floor } from './math/floor.js';
|
|
167
|
+
export { round } from './math/round.js';
|
|
166
168
|
export { parseInt } from './math/parseInt.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
5
5
|
const zipWith = require('../_chunk/zipWith-CYaH1Y.js');
|
|
6
6
|
const promise_index = require('../_chunk/index-BGZDR9.js');
|
|
7
7
|
const rest$1 = require('../_chunk/rest-CXt9w3.js');
|
|
8
|
-
const
|
|
8
|
+
const range = require('../_chunk/range-BXlMmn.js');
|
|
9
9
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
10
10
|
const toMerged = require('../_chunk/toMerged-Bmrr2j.js');
|
|
11
11
|
const isWeakSet$1 = require('../_chunk/isWeakSet-BerD1A.js');
|
|
@@ -782,19 +782,39 @@ function rearg(func, ...indices) {
|
|
|
782
782
|
};
|
|
783
783
|
}
|
|
784
784
|
|
|
785
|
-
function
|
|
786
|
-
|
|
785
|
+
function isNil(x) {
|
|
786
|
+
return x == null;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function pick(obj, ...keysArr) {
|
|
790
|
+
if (isNil(obj)) {
|
|
787
791
|
return {};
|
|
788
792
|
}
|
|
789
|
-
const typedObject = obj;
|
|
790
793
|
const result = {};
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
794
|
+
for (let keys of keysArr) {
|
|
795
|
+
switch (typeof keys) {
|
|
796
|
+
case 'object': {
|
|
797
|
+
if (!Array.isArray(keys)) {
|
|
798
|
+
keys = Array.from(keys);
|
|
799
|
+
}
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
case 'string':
|
|
803
|
+
case 'symbol':
|
|
804
|
+
case 'number': {
|
|
805
|
+
keys = [keys];
|
|
806
|
+
break;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
for (const key of keys) {
|
|
810
|
+
const value = get(obj, key);
|
|
811
|
+
if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
812
|
+
result[key] = value;
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
set(result, key, value);
|
|
816
|
+
}
|
|
796
817
|
}
|
|
797
|
-
set(result, arg, get(typedObject, arg));
|
|
798
818
|
}
|
|
799
819
|
return result;
|
|
800
820
|
}
|
|
@@ -1064,6 +1084,36 @@ function min(items = []) {
|
|
|
1064
1084
|
return minElement;
|
|
1065
1085
|
}
|
|
1066
1086
|
|
|
1087
|
+
function decimalAdjust(type, number, precision = 0) {
|
|
1088
|
+
number = Number(number);
|
|
1089
|
+
if (Object.is(number, -0)) {
|
|
1090
|
+
number = '-0';
|
|
1091
|
+
}
|
|
1092
|
+
precision = Math.min(Number.parseInt(precision, 10), 292);
|
|
1093
|
+
if (precision) {
|
|
1094
|
+
const [magnitude, exponent = 0] = number.toString().split('e');
|
|
1095
|
+
let adjustedValue = Math[type](Number(`${magnitude}e${Number(exponent) + precision}`));
|
|
1096
|
+
if (Object.is(adjustedValue, -0)) {
|
|
1097
|
+
adjustedValue = '-0';
|
|
1098
|
+
}
|
|
1099
|
+
const [newMagnitude, newExponent = 0] = adjustedValue.toString().split('e');
|
|
1100
|
+
return Number(`${newMagnitude}e${Number(newExponent) - precision}`);
|
|
1101
|
+
}
|
|
1102
|
+
return Math[type](Number(number));
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function ceil(number, precision = 0) {
|
|
1106
|
+
return decimalAdjust('ceil', number, precision);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
function floor(number, precision = 0) {
|
|
1110
|
+
return decimalAdjust('floor', number, precision);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
function round(number, precision = 0) {
|
|
1114
|
+
return decimalAdjust('round', number, precision);
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1067
1117
|
function parseInt(string, radix = 0, guard) {
|
|
1068
1118
|
if (guard) {
|
|
1069
1119
|
radix = 0;
|
|
@@ -1137,14 +1187,13 @@ exports.partial = rest$1.partial;
|
|
|
1137
1187
|
exports.partialRight = rest$1.partialRight;
|
|
1138
1188
|
exports.throttle = rest$1.throttle;
|
|
1139
1189
|
exports.unary = rest$1.unary;
|
|
1140
|
-
exports.clamp =
|
|
1141
|
-
exports.inRange =
|
|
1142
|
-
exports.mean =
|
|
1143
|
-
exports.meanBy =
|
|
1144
|
-
exports.range =
|
|
1145
|
-
exports.
|
|
1146
|
-
exports.
|
|
1147
|
-
exports.sumBy = math_index.sumBy;
|
|
1190
|
+
exports.clamp = range.clamp;
|
|
1191
|
+
exports.inRange = range.inRange;
|
|
1192
|
+
exports.mean = range.mean;
|
|
1193
|
+
exports.meanBy = range.meanBy;
|
|
1194
|
+
exports.range = range.range;
|
|
1195
|
+
exports.sum = range.sum;
|
|
1196
|
+
exports.sumBy = range.sumBy;
|
|
1148
1197
|
exports.random = randomInt.random;
|
|
1149
1198
|
exports.randomInt = randomInt.randomInt;
|
|
1150
1199
|
exports.clone = toMerged.clone;
|
|
@@ -1183,6 +1232,7 @@ exports.bind = bind;
|
|
|
1183
1232
|
exports.bindKey = bindKey;
|
|
1184
1233
|
exports.camelCase = camelCase;
|
|
1185
1234
|
exports.castArray = castArray;
|
|
1235
|
+
exports.ceil = ceil;
|
|
1186
1236
|
exports.chunk = chunk;
|
|
1187
1237
|
exports.concat = concat;
|
|
1188
1238
|
exports.conforms = conforms;
|
|
@@ -1196,6 +1246,7 @@ exports.findLastIndex = findLastIndex;
|
|
|
1196
1246
|
exports.flatten = flatten;
|
|
1197
1247
|
exports.flattenDeep = flattenDeep;
|
|
1198
1248
|
exports.flattenDepth = flattenDepth;
|
|
1249
|
+
exports.floor = floor;
|
|
1199
1250
|
exports.fromPairs = fromPairs;
|
|
1200
1251
|
exports.get = get;
|
|
1201
1252
|
exports.has = has;
|
|
@@ -1231,6 +1282,7 @@ exports.property = property;
|
|
|
1231
1282
|
exports.rearg = rearg;
|
|
1232
1283
|
exports.repeat = repeat;
|
|
1233
1284
|
exports.rest = rest;
|
|
1285
|
+
exports.round = round;
|
|
1234
1286
|
exports.set = set;
|
|
1235
1287
|
exports.size = size;
|
|
1236
1288
|
exports.some = some;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -66,7 +66,6 @@ export { mean } from '../math/mean.mjs';
|
|
|
66
66
|
export { meanBy } from '../math/meanBy.mjs';
|
|
67
67
|
export { random } from '../math/random.mjs';
|
|
68
68
|
export { randomInt } from '../math/randomInt.mjs';
|
|
69
|
-
export { round } from '../math/round.mjs';
|
|
70
69
|
export { sum } from '../math/sum.mjs';
|
|
71
70
|
export { sumBy } from '../math/sumBy.mjs';
|
|
72
71
|
export { range } from '../math/range.mjs';
|
|
@@ -163,4 +162,7 @@ export { padEnd } from './string/padEnd.mjs';
|
|
|
163
162
|
export { repeat } from './string/repeat.mjs';
|
|
164
163
|
export { max } from './math/max.mjs';
|
|
165
164
|
export { min } from './math/min.mjs';
|
|
165
|
+
export { ceil } from './math/ceil.mjs';
|
|
166
|
+
export { floor } from './math/floor.mjs';
|
|
167
|
+
export { round } from './math/round.mjs';
|
|
166
168
|
export { parseInt } from './math/parseInt.mjs';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded up to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round up.
|
|
5
|
+
* @param {number | string} precision The precision to round up to.
|
|
6
|
+
* @returns {number} Returns the rounded up number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ceil(4.006); // => 5
|
|
10
|
+
* ceil(6.004, 2); // => 6.01
|
|
11
|
+
* ceil(6040, -2); // => 6100
|
|
12
|
+
*/
|
|
13
|
+
declare function ceil(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { ceil };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded up to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round up.
|
|
5
|
+
* @param {number | string} precision The precision to round up to.
|
|
6
|
+
* @returns {number} Returns the rounded up number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ceil(4.006); // => 5
|
|
10
|
+
* ceil(6.004, 2); // => 6.01
|
|
11
|
+
* ceil(6040, -2); // => 6100
|
|
12
|
+
*/
|
|
13
|
+
declare function ceil(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { ceil };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded down to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round down.
|
|
5
|
+
* @param {number | string} precision The precision to round down to.
|
|
6
|
+
* @returns {number} Returns the rounded down number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* floor(4.006); // => 4
|
|
10
|
+
* floor(0.046, 2); // => 0.04
|
|
11
|
+
* floor(4060, -2); // => 4000
|
|
12
|
+
*/
|
|
13
|
+
declare function floor(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { floor };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded down to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round down.
|
|
5
|
+
* @param {number | string} precision The precision to round down to.
|
|
6
|
+
* @returns {number} Returns the rounded down number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* floor(4.006); // => 4
|
|
10
|
+
* floor(0.046, 2); // => 0.04
|
|
11
|
+
* floor(4060, -2); // => 4000
|
|
12
|
+
*/
|
|
13
|
+
declare function floor(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { floor };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round.
|
|
5
|
+
* @param {number | string} precision The precision to round to.
|
|
6
|
+
* @returns {number} Returns the rounded number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* round(4.006); // => 4
|
|
10
|
+
* round(4.006, 2); // => 4.01
|
|
11
|
+
* round(4060, -2); // => 4100
|
|
12
|
+
*/
|
|
13
|
+
declare function round(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { round };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes number rounded to precision.
|
|
3
|
+
*
|
|
4
|
+
* @param {number | string} number The number to round.
|
|
5
|
+
* @param {number | string} precision The precision to round to.
|
|
6
|
+
* @returns {number} Returns the rounded number.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* round(4.006); // => 4
|
|
10
|
+
* round(4.006, 2); // => 4.01
|
|
11
|
+
* round(4060, -2); // => 4100
|
|
12
|
+
*/
|
|
13
|
+
declare function round(number: number | string, precision?: number | string): number;
|
|
14
|
+
|
|
15
|
+
export { round };
|
|
@@ -5,8 +5,26 @@
|
|
|
5
5
|
* includes only the properties corresponding to the specified keys.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
8
9
|
* @param {T} obj - The object to pick keys from.
|
|
9
|
-
* @param {
|
|
10
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
*/
|
|
18
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object composed of the picked object properties.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
23
|
+
* includes only the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of object.
|
|
26
|
+
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
10
28
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
11
29
|
*
|
|
12
30
|
* @example
|
|
@@ -23,6 +41,6 @@
|
|
|
23
41
|
* const result = pick(obj, 'a.b');
|
|
24
42
|
* // result will be { 'a.b': 1 }
|
|
25
43
|
*/
|
|
26
|
-
declare function pick<T>(obj: T
|
|
44
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | PropertyKey[] | PropertyKey[][]>): Partial<T>;
|
|
27
45
|
|
|
28
46
|
export { pick };
|
|
@@ -5,8 +5,26 @@
|
|
|
5
5
|
* includes only the properties corresponding to the specified keys.
|
|
6
6
|
*
|
|
7
7
|
* @template T - The type of object.
|
|
8
|
+
* @template K - The type of keys in object.
|
|
8
9
|
* @param {T} obj - The object to pick keys from.
|
|
9
|
-
* @param {
|
|
10
|
+
* @param {K[]} keys - An array of keys to be picked from the object.
|
|
11
|
+
* @returns {Pick<T, K>} A new object with the specified keys picked.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
15
|
+
* const result = pick(obj, ['a', 'c']);
|
|
16
|
+
* // result will be { a: 1, c: 3 }
|
|
17
|
+
*/
|
|
18
|
+
declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new object composed of the picked object properties.
|
|
21
|
+
*
|
|
22
|
+
* This function takes an object and an array of keys, and returns a new object that
|
|
23
|
+
* includes only the properties corresponding to the specified keys.
|
|
24
|
+
*
|
|
25
|
+
* @template T - The type of object.
|
|
26
|
+
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
|
+
* @param {PropertyKey | PropertyKey[] | ProperyKey[][]}} keys - An array of keys to be picked from the object. received keysgoes through a flattening process before being used.
|
|
10
28
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
11
29
|
*
|
|
12
30
|
* @example
|
|
@@ -23,6 +41,6 @@
|
|
|
23
41
|
* const result = pick(obj, 'a.b');
|
|
24
42
|
* // result will be { 'a.b': 1 }
|
|
25
43
|
*/
|
|
26
|
-
declare function pick<T>(obj: T
|
|
44
|
+
declare function pick<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | PropertyKey[] | PropertyKey[][]>): Partial<T>;
|
|
27
45
|
|
|
28
46
|
export { pick };
|
|
@@ -1,26 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { flattenDeep } from '../../array/flattenDeep.mjs';
|
|
1
|
+
import { isNil } from '../predicate/isNil.mjs';
|
|
3
2
|
import { get } from './get.mjs';
|
|
4
|
-
import '
|
|
5
|
-
import '../../function/partialRight.mjs';
|
|
6
|
-
import { isNil } from '../../predicate/isNil.mjs';
|
|
7
|
-
import '../../string/deburr.mjs';
|
|
8
|
-
import '../function/bind.mjs';
|
|
9
|
-
import '../function/bindKey.mjs';
|
|
3
|
+
import { set } from './set.mjs';
|
|
10
4
|
|
|
11
|
-
function pick(obj, ...
|
|
5
|
+
function pick(obj, ...keysArr) {
|
|
12
6
|
if (isNil(obj)) {
|
|
13
7
|
return {};
|
|
14
8
|
}
|
|
15
|
-
const typedObject = obj;
|
|
16
9
|
const result = {};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
for (let keys of keysArr) {
|
|
11
|
+
switch (typeof keys) {
|
|
12
|
+
case 'object': {
|
|
13
|
+
if (!Array.isArray(keys)) {
|
|
14
|
+
keys = Array.from(keys);
|
|
15
|
+
}
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
case 'string':
|
|
19
|
+
case 'symbol':
|
|
20
|
+
case 'number': {
|
|
21
|
+
keys = [keys];
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
const value = get(obj, key);
|
|
27
|
+
if (typeof key === 'string' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
28
|
+
result[key] = value;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
set(result, key, value);
|
|
32
|
+
}
|
|
22
33
|
}
|
|
23
|
-
set(result, arg, get(typedObject, arg));
|
|
24
34
|
}
|
|
25
35
|
return result;
|
|
26
36
|
}
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,9 @@ const array_index = require('./array/index.js');
|
|
|
7
7
|
const promise_index = require('./_chunk/index-BGZDR9.js');
|
|
8
8
|
const rest = require('./_chunk/rest-CXt9w3.js');
|
|
9
9
|
const function_index = require('./function/index.js');
|
|
10
|
-
const
|
|
10
|
+
const range = require('./_chunk/range-BXlMmn.js');
|
|
11
11
|
const randomInt = require('./_chunk/randomInt-CF7bZK.js');
|
|
12
|
+
const math_index = require('./math/index.js');
|
|
12
13
|
const toMerged = require('./_chunk/toMerged-Bmrr2j.js');
|
|
13
14
|
const object_index = require('./object/index.js');
|
|
14
15
|
const isWeakSet = require('./_chunk/isWeakSet-BerD1A.js');
|
|
@@ -93,16 +94,16 @@ exports.rest = rest.rest;
|
|
|
93
94
|
exports.throttle = rest.throttle;
|
|
94
95
|
exports.unary = rest.unary;
|
|
95
96
|
exports.spread = function_index.spread;
|
|
96
|
-
exports.clamp =
|
|
97
|
-
exports.inRange =
|
|
98
|
-
exports.mean =
|
|
99
|
-
exports.meanBy =
|
|
100
|
-
exports.range =
|
|
101
|
-
exports.
|
|
102
|
-
exports.
|
|
103
|
-
exports.sumBy = math_index.sumBy;
|
|
97
|
+
exports.clamp = range.clamp;
|
|
98
|
+
exports.inRange = range.inRange;
|
|
99
|
+
exports.mean = range.mean;
|
|
100
|
+
exports.meanBy = range.meanBy;
|
|
101
|
+
exports.range = range.range;
|
|
102
|
+
exports.sum = range.sum;
|
|
103
|
+
exports.sumBy = range.sumBy;
|
|
104
104
|
exports.random = randomInt.random;
|
|
105
105
|
exports.randomInt = randomInt.randomInt;
|
|
106
|
+
exports.round = math_index.round;
|
|
106
107
|
exports.clone = toMerged.clone;
|
|
107
108
|
exports.cloneDeep = toMerged.cloneDeep;
|
|
108
109
|
exports.flattenObject = toMerged.flattenObject;
|
package/dist/math/index.js
CHANGED
|
@@ -2,43 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
+
const range = require('../_chunk/range-BXlMmn.js');
|
|
5
6
|
const randomInt = require('../_chunk/randomInt-CF7bZK.js');
|
|
6
7
|
|
|
7
|
-
function clamp(value, bound1, bound2) {
|
|
8
|
-
if (bound2 == null) {
|
|
9
|
-
return Math.min(value, bound1);
|
|
10
|
-
}
|
|
11
|
-
return Math.min(Math.max(value, bound1), bound2);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function inRange(value, minimum, maximum) {
|
|
15
|
-
if (maximum == null) {
|
|
16
|
-
maximum = minimum;
|
|
17
|
-
minimum = 0;
|
|
18
|
-
}
|
|
19
|
-
if (minimum >= maximum) {
|
|
20
|
-
throw new Error('The maximum value must be greater than the minimum value.');
|
|
21
|
-
}
|
|
22
|
-
return minimum <= value && value < maximum;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function sum(nums) {
|
|
26
|
-
let result = 0;
|
|
27
|
-
for (let i = 0; i < nums.length; i++) {
|
|
28
|
-
result += nums[i];
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function mean(nums) {
|
|
34
|
-
return sum(nums) / nums.length;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function meanBy(items, getValue) {
|
|
38
|
-
const nums = items.map(x => getValue(x));
|
|
39
|
-
return mean(nums);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
8
|
function round(value, precision = 0) {
|
|
43
9
|
if (!Number.isInteger(precision)) {
|
|
44
10
|
throw new Error('Precision must be an integer.');
|
|
@@ -47,37 +13,13 @@ function round(value, precision = 0) {
|
|
|
47
13
|
return Math.round(value * multiplier) / multiplier;
|
|
48
14
|
}
|
|
49
15
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
end = start;
|
|
58
|
-
start = 0;
|
|
59
|
-
}
|
|
60
|
-
if (step == null) {
|
|
61
|
-
step = 1;
|
|
62
|
-
}
|
|
63
|
-
if (!Number.isInteger(step) || step === 0) {
|
|
64
|
-
throw new Error(`The step value must be a non-zero integer.`);
|
|
65
|
-
}
|
|
66
|
-
const length = Math.max(Math.ceil((end - start) / step), 0);
|
|
67
|
-
const result = new Array(length);
|
|
68
|
-
for (let i = 0; i < length; i++) {
|
|
69
|
-
result[i] = start + i * step;
|
|
70
|
-
}
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
|
|
16
|
+
exports.clamp = range.clamp;
|
|
17
|
+
exports.inRange = range.inRange;
|
|
18
|
+
exports.mean = range.mean;
|
|
19
|
+
exports.meanBy = range.meanBy;
|
|
20
|
+
exports.range = range.range;
|
|
21
|
+
exports.sum = range.sum;
|
|
22
|
+
exports.sumBy = range.sumBy;
|
|
74
23
|
exports.random = randomInt.random;
|
|
75
24
|
exports.randomInt = randomInt.randomInt;
|
|
76
|
-
exports.clamp = clamp;
|
|
77
|
-
exports.inRange = inRange;
|
|
78
|
-
exports.mean = mean;
|
|
79
|
-
exports.meanBy = meanBy;
|
|
80
|
-
exports.range = range;
|
|
81
25
|
exports.round = round;
|
|
82
|
-
exports.sum = sum;
|
|
83
|
-
exports.sumBy = sumBy;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
3
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
4
|
-
"version": "1.18.0-dev.
|
|
4
|
+
"version": "1.18.0-dev.577+34fcd212",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|