es-toolkit 1.18.0-dev.576 → 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 +41 -9
- 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/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');
|
|
@@ -1084,6 +1084,36 @@ function min(items = []) {
|
|
|
1084
1084
|
return minElement;
|
|
1085
1085
|
}
|
|
1086
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
|
+
|
|
1087
1117
|
function parseInt(string, radix = 0, guard) {
|
|
1088
1118
|
if (guard) {
|
|
1089
1119
|
radix = 0;
|
|
@@ -1157,14 +1187,13 @@ exports.partial = rest$1.partial;
|
|
|
1157
1187
|
exports.partialRight = rest$1.partialRight;
|
|
1158
1188
|
exports.throttle = rest$1.throttle;
|
|
1159
1189
|
exports.unary = rest$1.unary;
|
|
1160
|
-
exports.clamp =
|
|
1161
|
-
exports.inRange =
|
|
1162
|
-
exports.mean =
|
|
1163
|
-
exports.meanBy =
|
|
1164
|
-
exports.range =
|
|
1165
|
-
exports.
|
|
1166
|
-
exports.
|
|
1167
|
-
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;
|
|
1168
1197
|
exports.random = randomInt.random;
|
|
1169
1198
|
exports.randomInt = randomInt.randomInt;
|
|
1170
1199
|
exports.clone = toMerged.clone;
|
|
@@ -1203,6 +1232,7 @@ exports.bind = bind;
|
|
|
1203
1232
|
exports.bindKey = bindKey;
|
|
1204
1233
|
exports.camelCase = camelCase;
|
|
1205
1234
|
exports.castArray = castArray;
|
|
1235
|
+
exports.ceil = ceil;
|
|
1206
1236
|
exports.chunk = chunk;
|
|
1207
1237
|
exports.concat = concat;
|
|
1208
1238
|
exports.conforms = conforms;
|
|
@@ -1216,6 +1246,7 @@ exports.findLastIndex = findLastIndex;
|
|
|
1216
1246
|
exports.flatten = flatten;
|
|
1217
1247
|
exports.flattenDeep = flattenDeep;
|
|
1218
1248
|
exports.flattenDepth = flattenDepth;
|
|
1249
|
+
exports.floor = floor;
|
|
1219
1250
|
exports.fromPairs = fromPairs;
|
|
1220
1251
|
exports.get = get;
|
|
1221
1252
|
exports.has = has;
|
|
@@ -1251,6 +1282,7 @@ exports.property = property;
|
|
|
1251
1282
|
exports.rearg = rearg;
|
|
1252
1283
|
exports.repeat = repeat;
|
|
1253
1284
|
exports.rest = rest;
|
|
1285
|
+
exports.round = round;
|
|
1254
1286
|
exports.set = set;
|
|
1255
1287
|
exports.size = size;
|
|
1256
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 };
|
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": {
|