@jdsalasc/solvejs-numbers 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 ADDED
@@ -0,0 +1,19 @@
1
+ # @jdsalasc/solvejs-numbers
2
+
3
+ Number utilities for common JavaScript and TypeScript math tasks.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i @jdsalasc/solvejs-numbers
9
+ ```
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ import { clamp, average, percent } from "@jdsalasc/solvejs-numbers";
15
+
16
+ clamp(120, 0, 100); // 100
17
+ average([10, 20, 30]); // 20
18
+ percent(25, 200, 1); // 12.5
19
+ ```
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clamp = clamp;
4
+ exports.roundTo = roundTo;
5
+ exports.sum = sum;
6
+ exports.average = average;
7
+ exports.median = median;
8
+ exports.percent = percent;
9
+ exports.randomInt = randomInt;
10
+ /**
11
+ * Ensures a number is finite.
12
+ *
13
+ * @param value - Input number.
14
+ * @param label - Parameter label for error messages.
15
+ * @throws {TypeError} If the value is not finite.
16
+ */
17
+ function assertFinite(value, label) {
18
+ if (!Number.isFinite(value)) {
19
+ throw new TypeError(`Expected ${label} to be a finite number.`);
20
+ }
21
+ }
22
+ /**
23
+ * Restricts a number to a closed interval.
24
+ *
25
+ * @param value - Number to clamp.
26
+ * @param min - Minimum allowed value.
27
+ * @param max - Maximum allowed value.
28
+ * @returns Clamped value between `min` and `max`.
29
+ * @throws {TypeError} If inputs are not finite numbers.
30
+ * @throws {RangeError} If `min` is greater than `max`.
31
+ */
32
+ function clamp(value, min, max) {
33
+ assertFinite(value, "value");
34
+ assertFinite(min, "min");
35
+ assertFinite(max, "max");
36
+ if (min > max) {
37
+ throw new RangeError("Expected min to be less than or equal to max.");
38
+ }
39
+ return Math.min(Math.max(value, min), max);
40
+ }
41
+ /**
42
+ * Rounds a number to a specific decimal precision.
43
+ *
44
+ * @param value - Number to round.
45
+ * @param decimals - Decimal precision.
46
+ * @returns Rounded number.
47
+ * @throws {TypeError} If `value` is not finite.
48
+ * @throws {TypeError} If `decimals` is not an integer.
49
+ * @throws {RangeError} If `decimals` is outside [-12, 12].
50
+ */
51
+ function roundTo(value, decimals = 0) {
52
+ assertFinite(value, "value");
53
+ if (!Number.isInteger(decimals)) {
54
+ throw new TypeError("Expected decimals to be an integer.");
55
+ }
56
+ if (decimals < -12 || decimals > 12) {
57
+ throw new RangeError("Expected decimals to be between -12 and 12.");
58
+ }
59
+ if (decimals === 0) {
60
+ return Math.round(value);
61
+ }
62
+ const factor = 10 ** decimals;
63
+ return Math.round((value + Number.EPSILON) * factor) / factor;
64
+ }
65
+ /**
66
+ * Sums a list of numbers.
67
+ *
68
+ * @param values - Numeric collection.
69
+ * @returns Sum of all values.
70
+ * @throws {TypeError} If any element is not finite.
71
+ */
72
+ function sum(values) {
73
+ return values.reduce((accumulator, value, index) => {
74
+ assertFinite(value, `values[${index}]`);
75
+ return accumulator + value;
76
+ }, 0);
77
+ }
78
+ /**
79
+ * Computes the arithmetic mean of a numeric collection.
80
+ *
81
+ * @param values - Numeric collection.
82
+ * @returns Average of the collection.
83
+ * @throws {TypeError} If any value is not finite.
84
+ * @throws {RangeError} If the collection is empty.
85
+ */
86
+ function average(values) {
87
+ if (values.length === 0) {
88
+ throw new RangeError("Expected at least one value to compute average.");
89
+ }
90
+ return sum(values) / values.length;
91
+ }
92
+ /**
93
+ * Computes the median of a numeric collection.
94
+ *
95
+ * @param values - Numeric collection.
96
+ * @returns Median value.
97
+ * @throws {TypeError} If any value is not finite.
98
+ * @throws {RangeError} If the collection is empty.
99
+ */
100
+ function median(values) {
101
+ if (values.length === 0) {
102
+ throw new RangeError("Expected at least one value to compute median.");
103
+ }
104
+ const sorted = [...values];
105
+ sorted.forEach((value, index) => assertFinite(value, `values[${index}]`));
106
+ sorted.sort((a, b) => a - b);
107
+ const middle = Math.floor(sorted.length / 2);
108
+ if (sorted.length % 2 === 1) {
109
+ return sorted[middle];
110
+ }
111
+ return (sorted[middle - 1] + sorted[middle]) / 2;
112
+ }
113
+ /**
114
+ * Calculates percentage as `(part / total) * 100`.
115
+ *
116
+ * @param part - Partial value.
117
+ * @param total - Total reference value.
118
+ * @param decimals - Optional decimal precision.
119
+ * @returns Percentage value.
120
+ * @throws {TypeError} If inputs are not finite numbers.
121
+ * @throws {RangeError} If `total` is zero.
122
+ */
123
+ function percent(part, total, decimals = 2) {
124
+ assertFinite(part, "part");
125
+ assertFinite(total, "total");
126
+ if (total === 0) {
127
+ throw new RangeError("Cannot compute percentage when total is zero.");
128
+ }
129
+ return roundTo((part / total) * 100, decimals);
130
+ }
131
+ /**
132
+ * Generates a random integer within an inclusive range.
133
+ *
134
+ * @param min - Minimum integer value.
135
+ * @param max - Maximum integer value.
136
+ * @returns Random integer in `[min, max]`.
137
+ * @throws {TypeError} If bounds are not integers.
138
+ * @throws {RangeError} If `min` is greater than `max`.
139
+ */
140
+ function randomInt(min, max) {
141
+ if (!Number.isInteger(min) || !Number.isInteger(max)) {
142
+ throw new TypeError("Expected min and max to be integers.");
143
+ }
144
+ if (min > max) {
145
+ throw new RangeError("Expected min to be less than or equal to max.");
146
+ }
147
+ return Math.floor(Math.random() * (max - min + 1)) + min;
148
+ }
149
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAuBA,sBAUC;AAYD,0BAeC;AASD,kBAKC;AAUD,0BAKC;AAUD,wBAeC;AAYD,0BASC;AAWD,8BASC;AA3JD;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,KAAa;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,YAAY,KAAK,yBAAyB,CAAC,CAAC;IAClE,CAAC;AACH,CAAC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gB,OAAO,CAAC,IAAY,EAAE,KAAa,EAAE,QAAQ,GAAG,CAAC;IAC/D,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC3B,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAE7B,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,MAAM,IAAI,UAAU,CAAC,+CAA+C,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,GAAG,GAAG,EAAE,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QACd,MAAM,IAAI,UAAU,CAAC,+CAA+C,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Restricts a number to a closed interval.
3
+ *
4
+ * @param value - Number to clamp.
5
+ * @param min - Minimum allowed value.
6
+ * @param max - Maximum allowed value.
7
+ * @returns Clamped value between `min` and `max`.
8
+ * @throws {TypeError} If inputs are not finite numbers.
9
+ * @throws {RangeError} If `min` is greater than `max`.
10
+ */
11
+ export declare function clamp(value: number, min: number, max: number): number;
12
+ /**
13
+ * Rounds a number to a specific decimal precision.
14
+ *
15
+ * @param value - Number to round.
16
+ * @param decimals - Decimal precision.
17
+ * @returns Rounded number.
18
+ * @throws {TypeError} If `value` is not finite.
19
+ * @throws {TypeError} If `decimals` is not an integer.
20
+ * @throws {RangeError} If `decimals` is outside [-12, 12].
21
+ */
22
+ export declare function roundTo(value: number, decimals?: number): number;
23
+ /**
24
+ * Sums a list of numbers.
25
+ *
26
+ * @param values - Numeric collection.
27
+ * @returns Sum of all values.
28
+ * @throws {TypeError} If any element is not finite.
29
+ */
30
+ export declare function sum(values: readonly number[]): number;
31
+ /**
32
+ * Computes the arithmetic mean of a numeric collection.
33
+ *
34
+ * @param values - Numeric collection.
35
+ * @returns Average of the collection.
36
+ * @throws {TypeError} If any value is not finite.
37
+ * @throws {RangeError} If the collection is empty.
38
+ */
39
+ export declare function average(values: readonly number[]): number;
40
+ /**
41
+ * Computes the median of a numeric collection.
42
+ *
43
+ * @param values - Numeric collection.
44
+ * @returns Median value.
45
+ * @throws {TypeError} If any value is not finite.
46
+ * @throws {RangeError} If the collection is empty.
47
+ */
48
+ export declare function median(values: readonly number[]): number;
49
+ /**
50
+ * Calculates percentage as `(part / total) * 100`.
51
+ *
52
+ * @param part - Partial value.
53
+ * @param total - Total reference value.
54
+ * @param decimals - Optional decimal precision.
55
+ * @returns Percentage value.
56
+ * @throws {TypeError} If inputs are not finite numbers.
57
+ * @throws {RangeError} If `total` is zero.
58
+ */
59
+ export declare function percent(part: number, total: number, decimals?: number): number;
60
+ /**
61
+ * Generates a random integer within an inclusive range.
62
+ *
63
+ * @param min - Minimum integer value.
64
+ * @param max - Maximum integer value.
65
+ * @returns Random integer in `[min, max]`.
66
+ * @throws {TypeError} If bounds are not integers.
67
+ * @throws {RangeError} If `min` is greater than `max`.
68
+ */
69
+ export declare function randomInt(min: number, max: number): number;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Ensures a number is finite.
3
+ *
4
+ * @param value - Input number.
5
+ * @param label - Parameter label for error messages.
6
+ * @throws {TypeError} If the value is not finite.
7
+ */
8
+ function assertFinite(value, label) {
9
+ if (!Number.isFinite(value)) {
10
+ throw new TypeError(`Expected ${label} to be a finite number.`);
11
+ }
12
+ }
13
+ /**
14
+ * Restricts a number to a closed interval.
15
+ *
16
+ * @param value - Number to clamp.
17
+ * @param min - Minimum allowed value.
18
+ * @param max - Maximum allowed value.
19
+ * @returns Clamped value between `min` and `max`.
20
+ * @throws {TypeError} If inputs are not finite numbers.
21
+ * @throws {RangeError} If `min` is greater than `max`.
22
+ */
23
+ export function clamp(value, min, max) {
24
+ assertFinite(value, "value");
25
+ assertFinite(min, "min");
26
+ assertFinite(max, "max");
27
+ if (min > max) {
28
+ throw new RangeError("Expected min to be less than or equal to max.");
29
+ }
30
+ return Math.min(Math.max(value, min), max);
31
+ }
32
+ /**
33
+ * Rounds a number to a specific decimal precision.
34
+ *
35
+ * @param value - Number to round.
36
+ * @param decimals - Decimal precision.
37
+ * @returns Rounded number.
38
+ * @throws {TypeError} If `value` is not finite.
39
+ * @throws {TypeError} If `decimals` is not an integer.
40
+ * @throws {RangeError} If `decimals` is outside [-12, 12].
41
+ */
42
+ export function roundTo(value, decimals = 0) {
43
+ assertFinite(value, "value");
44
+ if (!Number.isInteger(decimals)) {
45
+ throw new TypeError("Expected decimals to be an integer.");
46
+ }
47
+ if (decimals < -12 || decimals > 12) {
48
+ throw new RangeError("Expected decimals to be between -12 and 12.");
49
+ }
50
+ if (decimals === 0) {
51
+ return Math.round(value);
52
+ }
53
+ const factor = 10 ** decimals;
54
+ return Math.round((value + Number.EPSILON) * factor) / factor;
55
+ }
56
+ /**
57
+ * Sums a list of numbers.
58
+ *
59
+ * @param values - Numeric collection.
60
+ * @returns Sum of all values.
61
+ * @throws {TypeError} If any element is not finite.
62
+ */
63
+ export function sum(values) {
64
+ return values.reduce((accumulator, value, index) => {
65
+ assertFinite(value, `values[${index}]`);
66
+ return accumulator + value;
67
+ }, 0);
68
+ }
69
+ /**
70
+ * Computes the arithmetic mean of a numeric collection.
71
+ *
72
+ * @param values - Numeric collection.
73
+ * @returns Average of the collection.
74
+ * @throws {TypeError} If any value is not finite.
75
+ * @throws {RangeError} If the collection is empty.
76
+ */
77
+ export function average(values) {
78
+ if (values.length === 0) {
79
+ throw new RangeError("Expected at least one value to compute average.");
80
+ }
81
+ return sum(values) / values.length;
82
+ }
83
+ /**
84
+ * Computes the median of a numeric collection.
85
+ *
86
+ * @param values - Numeric collection.
87
+ * @returns Median value.
88
+ * @throws {TypeError} If any value is not finite.
89
+ * @throws {RangeError} If the collection is empty.
90
+ */
91
+ export function median(values) {
92
+ if (values.length === 0) {
93
+ throw new RangeError("Expected at least one value to compute median.");
94
+ }
95
+ const sorted = [...values];
96
+ sorted.forEach((value, index) => assertFinite(value, `values[${index}]`));
97
+ sorted.sort((a, b) => a - b);
98
+ const middle = Math.floor(sorted.length / 2);
99
+ if (sorted.length % 2 === 1) {
100
+ return sorted[middle];
101
+ }
102
+ return (sorted[middle - 1] + sorted[middle]) / 2;
103
+ }
104
+ /**
105
+ * Calculates percentage as `(part / total) * 100`.
106
+ *
107
+ * @param part - Partial value.
108
+ * @param total - Total reference value.
109
+ * @param decimals - Optional decimal precision.
110
+ * @returns Percentage value.
111
+ * @throws {TypeError} If inputs are not finite numbers.
112
+ * @throws {RangeError} If `total` is zero.
113
+ */
114
+ export function percent(part, total, decimals = 2) {
115
+ assertFinite(part, "part");
116
+ assertFinite(total, "total");
117
+ if (total === 0) {
118
+ throw new RangeError("Cannot compute percentage when total is zero.");
119
+ }
120
+ return roundTo((part / total) * 100, decimals);
121
+ }
122
+ /**
123
+ * Generates a random integer within an inclusive range.
124
+ *
125
+ * @param min - Minimum integer value.
126
+ * @param max - Maximum integer value.
127
+ * @returns Random integer in `[min, max]`.
128
+ * @throws {TypeError} If bounds are not integers.
129
+ * @throws {RangeError} If `min` is greater than `max`.
130
+ */
131
+ export function randomInt(min, max) {
132
+ if (!Number.isInteger(min) || !Number.isInteger(max)) {
133
+ throw new TypeError("Expected min and max to be integers.");
134
+ }
135
+ if (min > max) {
136
+ throw new RangeError("Expected min to be less than or equal to max.");
137
+ }
138
+ return Math.floor(Math.random() * (max - min + 1)) + min;
139
+ }
140
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAAa,EAAE,KAAa;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,SAAS,CAAC,YAAY,KAAK,yBAAyB,CAAC,CAAC;IAClE,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IAC3D,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7B,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzB,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAEzB,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QACd,MAAM,IAAI,UAAU,CAAC,+CAA+C,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,QAAQ,GAAG,CAAC;IACjD,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,QAAQ,GAAG,CAAC,EAAE,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,UAAU,CAAC,6CAA6C,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QAC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.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@jdsalasc/solvejs-numbers",
3
+ "version": "1.0.2",
4
+ "description": "Number utilities for rounding, percentages, clamping, median, average, and safe math helpers.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/cjs/index.cjs",
9
+ "module": "./dist/esm/index.js",
10
+ "types": "./dist/esm/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/esm/index.d.ts",
14
+ "import": "./dist/esm/index.js",
15
+ "require": "./dist/cjs/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "scripts": {
23
+ "build": "npm run clean && npm run build:esm && npm run build:cjs",
24
+ "build:esm": "tsc -p tsconfig.esm.json",
25
+ "build:cjs": "tsc -p tsconfig.cjs.json && node ./scripts/rename-cjs.mjs",
26
+ "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
27
+ "test": "npm run build && node --test test/*.test.mjs",
28
+ "lint": "node -e \"console.log('No lint configured for @jdsalasc/solvejs-numbers')\""
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "author": "jdsalasc",
34
+ "homepage": "https://github.com/jdsalasca/solvejs#readme",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/jdsalasca/solvejs.git"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/jdsalasca/solvejs/issues"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "keywords": [
46
+ "number utilities",
47
+ "round numbers",
48
+ "percentage",
49
+ "statistics",
50
+ "solvejs"
51
+ ]
52
+ }