@helpers4/number 2.0.0-alpha.10 → 2.0.0-alpha.11
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 +1 -0
- package/lib/index.d.ts +17 -1
- package/lib/index.js +20 -1
- package/lib/index.js.map +1 -1
- package/meta/api.json +37 -1
- package/meta/examples.json +15 -0
- package/package.json +3 -2
package/README.md
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -49,4 +49,20 @@ declare function randomIntBetween(min: number, max: number): number;
|
|
|
49
49
|
*/
|
|
50
50
|
declare function roundTo(value: number, decimals: number): number;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* This file is part of helpers4.
|
|
54
|
+
* Copyright (C) 2025 baxyz
|
|
55
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Calculates the sum of an array of numbers.
|
|
59
|
+
* @param array - The array of numbers to sum
|
|
60
|
+
* @returns The sum of all values
|
|
61
|
+
* @example
|
|
62
|
+
* sum([1, 2, 3, 4])
|
|
63
|
+
* // => 10
|
|
64
|
+
* @since 2.0.0
|
|
65
|
+
*/
|
|
66
|
+
declare function sum(array: readonly number[]): number;
|
|
67
|
+
|
|
68
|
+
export { clamp, randomBetween, randomIntBetween, roundTo, sum };
|
package/lib/index.js
CHANGED
|
@@ -61,6 +61,25 @@ function roundTo(value, decimals) {
|
|
|
61
61
|
return Math.round(value * multiplier) / multiplier;
|
|
62
62
|
}
|
|
63
63
|
//#endregion
|
|
64
|
-
|
|
64
|
+
//#region helpers/number/sum.ts
|
|
65
|
+
/**
|
|
66
|
+
* This file is part of helpers4.
|
|
67
|
+
* Copyright (C) 2025 baxyz
|
|
68
|
+
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Calculates the sum of an array of numbers.
|
|
72
|
+
* @param array - The array of numbers to sum
|
|
73
|
+
* @returns The sum of all values
|
|
74
|
+
* @example
|
|
75
|
+
* sum([1, 2, 3, 4])
|
|
76
|
+
* // => 10
|
|
77
|
+
* @since 2.0.0
|
|
78
|
+
*/
|
|
79
|
+
function sum(array) {
|
|
80
|
+
return array.reduce((acc, n) => acc + n, 0);
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { clamp, randomBetween, randomIntBetween, roundTo, sum };
|
|
65
84
|
|
|
66
85
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/number/clamp.ts","../../../helpers/number/random.ts","../../../helpers/number/roundTo.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clamps a number between min and max values\n * @param value - The value to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped value\n * @since 1.9.0\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Generates a random number between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random number between min and max\n * @since 1.9.0\n */\nexport function randomBetween(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/**\n * Generates a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer between min and max\n * @since 1.9.0\n */\nexport function randomIntBetween(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Rounds a number to specified decimal places\n * @param value - The number to round\n * @param decimals - Number of decimal places\n * @returns Rounded number\n * @since 1.9.0\n */\nexport function roundTo(value: number, decimals: number): number {\n const multiplier = Math.pow(10, decimals);\n return Math.round(value * multiplier) / multiplier;\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,MAAM,OAAe,KAAa,KAAqB;AACrE,QAAO,KAAK,IAAI,KAAK,IAAI,OAAO,IAAI,EAAE,IAAI;;;;;;;;;;;;;;;;ACF5C,SAAgB,cAAc,KAAa,KAAqB;AAC9D,QAAO,KAAK,QAAQ,IAAI,MAAM,OAAO;;;;;;;;;AAUvC,SAAgB,iBAAiB,KAAa,KAAqB;AACjE,QAAO,KAAK,MAAM,KAAK,QAAQ,IAAI,MAAM,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;ACZvD,SAAgB,QAAQ,OAAe,UAA0B;CAC/D,MAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../helpers/number/clamp.ts","../../../helpers/number/random.ts","../../../helpers/number/roundTo.ts","../../../helpers/number/sum.ts"],"sourcesContent":["/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Clamps a number between min and max values\n * @param value - The value to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped value\n * @since 1.9.0\n */\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Generates a random number between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random number between min and max\n * @since 1.9.0\n */\nexport function randomBetween(min: number, max: number): number {\n return Math.random() * (max - min) + min;\n}\n\n/**\n * Generates a random integer between min and max (inclusive)\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Random integer between min and max\n * @since 1.9.0\n */\nexport function randomIntBetween(min: number, max: number): number {\n return Math.floor(Math.random() * (max - min + 1)) + min;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Rounds a number to specified decimal places\n * @param value - The number to round\n * @param decimals - Number of decimal places\n * @returns Rounded number\n * @since 1.9.0\n */\nexport function roundTo(value: number, decimals: number): number {\n const multiplier = Math.pow(10, decimals);\n return Math.round(value * multiplier) / multiplier;\n}\n","/**\n * This file is part of helpers4.\n * Copyright (C) 2025 baxyz\n * SPDX-License-Identifier: LGPL-3.0-or-later\n */\n\n/**\n * Calculates the sum of an array of numbers.\n * @param array - The array of numbers to sum\n * @returns The sum of all values\n * @example\n * sum([1, 2, 3, 4])\n * // => 10\n * @since 2.0.0\n */\nexport function sum(array: readonly number[]): number {\n return array.reduce((acc, n) => acc + n, 0);\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,SAAgB,MAAM,OAAe,KAAa,KAAqB;AACrE,QAAO,KAAK,IAAI,KAAK,IAAI,OAAO,IAAI,EAAE,IAAI;;;;;;;;;;;;;;;;ACF5C,SAAgB,cAAc,KAAa,KAAqB;AAC9D,QAAO,KAAK,QAAQ,IAAI,MAAM,OAAO;;;;;;;;;AAUvC,SAAgB,iBAAiB,KAAa,KAAqB;AACjE,QAAO,KAAK,MAAM,KAAK,QAAQ,IAAI,MAAM,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;ACZvD,SAAgB,QAAQ,OAAe,UAA0B;CAC/D,MAAM,aAAa,KAAK,IAAI,IAAI,SAAS;AACzC,QAAO,KAAK,MAAM,QAAQ,WAAW,GAAG;;;;;;;;;;;;;;;;;;ACA1C,SAAgB,IAAI,OAAkC;AACpD,QAAO,MAAM,QAAQ,KAAK,MAAM,MAAM,GAAG,EAAE"}
|
package/meta/api.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"category": "number",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.11",
|
|
4
4
|
"functions": [
|
|
5
5
|
{
|
|
6
6
|
"name": "clamp",
|
|
@@ -154,6 +154,42 @@
|
|
|
154
154
|
}
|
|
155
155
|
],
|
|
156
156
|
"sourceFile": "roundTo.ts"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"name": "sum",
|
|
160
|
+
"kind": "function",
|
|
161
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
162
|
+
"since": "2.0.0",
|
|
163
|
+
"signatures": [
|
|
164
|
+
{
|
|
165
|
+
"signature": "sum(array: readonly number[]): number",
|
|
166
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
167
|
+
"params": [
|
|
168
|
+
{
|
|
169
|
+
"name": "array",
|
|
170
|
+
"type": "readonly number[]",
|
|
171
|
+
"description": "The array of numbers to sum"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"returns": {
|
|
175
|
+
"type": "number",
|
|
176
|
+
"description": "The sum of all values"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"examples": [
|
|
181
|
+
{
|
|
182
|
+
"title": "Sum numbers",
|
|
183
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
184
|
+
"code": "sum([1, 2, 3, 4])\n// => 10"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"title": "Sum with negative numbers",
|
|
188
|
+
"description": "Handles negative numbers correctly.",
|
|
189
|
+
"code": "sum([10, -3, 5, -2])\n// => 10"
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
"sourceFile": "sum.ts"
|
|
157
193
|
}
|
|
158
194
|
]
|
|
159
195
|
}
|
package/meta/examples.json
CHANGED
|
@@ -40,6 +40,21 @@
|
|
|
40
40
|
"code": "roundTo(3.7, 0)\n// => 4"
|
|
41
41
|
}
|
|
42
42
|
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "sum",
|
|
46
|
+
"examples": [
|
|
47
|
+
{
|
|
48
|
+
"title": "Sum numbers",
|
|
49
|
+
"description": "Calculates the sum of an array of numbers.",
|
|
50
|
+
"code": "sum([1, 2, 3, 4])\n// => 10"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"title": "Sum with negative numbers",
|
|
54
|
+
"description": "Handles negative numbers correctly.",
|
|
55
|
+
"code": "sum([10, -3, 5, -2])\n// => 10"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
43
58
|
}
|
|
44
59
|
]
|
|
45
60
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helpers4/number",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.11",
|
|
4
4
|
"description": "A set of helpers in TS/JS, compatible with tree-shaking, for number.",
|
|
5
5
|
"author": "baxyz <baxy@etik.com>",
|
|
6
6
|
"license": "LGPL-3.0",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"number",
|
|
29
29
|
"clamp",
|
|
30
30
|
"random",
|
|
31
|
-
"roundTo"
|
|
31
|
+
"roundTo",
|
|
32
|
+
"sum"
|
|
32
33
|
],
|
|
33
34
|
"files": [
|
|
34
35
|
"lib/index.js",
|