@jangaba/qube 1.0.0

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,72 @@
1
+ # qube
2
+
3
+ Compute all parameters of a cube from any single one.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install qube
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ const { cube } = require("qube");
15
+ // or
16
+ import { cube } from "qube";
17
+
18
+ cube({ edge: 5 });
19
+ // {
20
+ // edge: 5,
21
+ // faceDiagonal: 7.071,
22
+ // spaceDiagonal: 8.660,
23
+ // surfaceArea: 150,
24
+ // volume: 125,
25
+ // faceArea: 25,
26
+ // perimeter: 20,
27
+ // totalEdgeLength: 60,
28
+ // circumRadius: 4.330,
29
+ // inRadius: 2.5,
30
+ // midRadius: 3.536
31
+ // }
32
+
33
+ cube({ volume: 125 }); // from volume
34
+ cube({ surfaceArea: 150 }); // from surface area
35
+ cube({ spaceDiagonal: 8.66 }); // from space diagonal
36
+ ```
37
+
38
+ ## Supported inputs
39
+
40
+ | Parameter | Description |
41
+ |---|---|
42
+ | `edge` | Edge length |
43
+ | `faceDiagonal` | Face diagonal (a√2) |
44
+ | `spaceDiagonal` | Space diagonal (a√3) |
45
+ | `surfaceArea` | Surface area (6a²) |
46
+ | `volume` | Volume (a³) |
47
+ | `faceArea` | Area of one face (a²) |
48
+ | `perimeter` | Perimeter of one face (4a) |
49
+ | `totalEdgeLength` | Sum of all 12 edges (12a) |
50
+ | `circumRadius` | Circumscribed sphere radius |
51
+ | `inRadius` | Inscribed sphere radius |
52
+ | `midRadius` | Midsphere radius (touches edges) |
53
+
54
+ Pass **any one** parameter and get **all 11** back.
55
+
56
+ ## API
57
+
58
+ ### `cube(input): CubeResult`
59
+
60
+ Returns an object with all 11 cube parameters.
61
+
62
+ ### `printCube(input): CubeResult`
63
+
64
+ Same as `cube()` but also logs the results to the console.
65
+
66
+ ### `descriptions`
67
+
68
+ Object mapping parameter names to Slovak descriptions.
69
+
70
+ ## License
71
+
72
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ export interface CubeResult {
2
+ /** Dlzka hrany */
3
+ edge: number;
4
+ /** Uhlopriecka steny (podstavy): a√2 */
5
+ faceDiagonal: number;
6
+ /** Telesova uhlopriecka: a√3 */
7
+ spaceDiagonal: number;
8
+ /** Povrch kocky: 6a² */
9
+ surfaceArea: number;
10
+ /** Objem kocky: a³ */
11
+ volume: number;
12
+ /** Obsah jednej steny: a² */
13
+ faceArea: number;
14
+ /** Obvod jednej steny: 4a */
15
+ perimeter: number;
16
+ /** Sucet dlzok vsetkych hran: 12a */
17
+ totalEdgeLength: number;
18
+ /** Polomer opisanej gule: (a√3)/2 */
19
+ circumRadius: number;
20
+ /** Polomer vpisanej gule: a/2 */
21
+ inRadius: number;
22
+ /** Polomer strednej gule (dotyka sa hran): (a√2)/2 */
23
+ midRadius: number;
24
+ }
25
+
26
+ export type CubeInput = { [K in keyof CubeResult]?: number } & {
27
+ [key: string]: never;
28
+ };
29
+
30
+ /**
31
+ * Vypocita vsetky parametre kocky zo zadaneho jedneho parametra.
32
+ *
33
+ * @example
34
+ * cube({ edge: 5 })
35
+ * cube({ volume: 125 })
36
+ * cube({ surfaceArea: 150 })
37
+ */
38
+ export function cube(input: Partial<CubeResult>): CubeResult;
39
+
40
+ /**
41
+ * Vypise vsetky parametre kocky do konzoly a vrati vysledok.
42
+ */
43
+ export function printCube(input: Partial<CubeResult>): CubeResult;
44
+
45
+ /** Popisy parametrov v slovencine. */
46
+ export const descriptions: Record<keyof CubeResult, string>;
47
+
48
+ export default cube;
package/index.js ADDED
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Cube Calculator
3
+ *
4
+ * Vypocita vsetky parametre kocky zo zadaneho jedneho parametra.
5
+ *
6
+ * Parametre kocky:
7
+ * a - dlzka hrany
8
+ * faceDiagonal - uhlopriecka podstavy (steny): a√2
9
+ * spaceDiagonal - telesova uhlopriecka: a√3
10
+ * surfaceArea - povrch kocky: 6a²
11
+ * volume - objem kocky: a³
12
+ * faceArea - obsah jednej steny: a²
13
+ * perimeter - obvod jednej steny: 4a
14
+ * totalEdgeLength - sucet dlzok vsetkych hran: 12a
15
+ * circumRadius - polomer opisanej gule: (a√3)/2
16
+ * inRadius - polomer vpisanej gule: a/2
17
+ * midRadius - polomer strednej gule (dotyka sa hran): (a√2)/2
18
+ */
19
+
20
+ const SQRT2 = Math.sqrt(2);
21
+ const SQRT3 = Math.sqrt(3);
22
+
23
+ function fromEdge(a) {
24
+ return {
25
+ edge: a,
26
+ faceDiagonal: a * SQRT2,
27
+ spaceDiagonal: a * SQRT3,
28
+ surfaceArea: 6 * a * a,
29
+ volume: a * a * a,
30
+ faceArea: a * a,
31
+ perimeter: 4 * a,
32
+ totalEdgeLength: 12 * a,
33
+ circumRadius: (a * SQRT3) / 2,
34
+ inRadius: a / 2,
35
+ midRadius: (a * SQRT2) / 2,
36
+ };
37
+ }
38
+
39
+ const paramToEdge = {
40
+ edge: (v) => v,
41
+ faceDiagonal: (v) => v / SQRT2,
42
+ spaceDiagonal: (v) => v / SQRT3,
43
+ surfaceArea: (v) => Math.sqrt(v / 6),
44
+ volume: (v) => Math.cbrt(v),
45
+ faceArea: (v) => Math.sqrt(v),
46
+ perimeter: (v) => v / 4,
47
+ totalEdgeLength: (v) => v / 12,
48
+ circumRadius: (v) => (2 * v) / SQRT3,
49
+ inRadius: (v) => 2 * v,
50
+ midRadius: (v) => (2 * v) / SQRT2,
51
+ };
52
+
53
+ const descriptions = {
54
+ edge: "Dlzka hrany",
55
+ faceDiagonal: "Uhlopriecka steny (podstavy)",
56
+ spaceDiagonal: "Telesova uhlopriecka",
57
+ surfaceArea: "Povrch kocky",
58
+ volume: "Objem kocky",
59
+ faceArea: "Obsah jednej steny",
60
+ perimeter: "Obvod jednej steny",
61
+ totalEdgeLength: "Sucet dlzok vsetkych hran",
62
+ circumRadius: "Polomer opisanej gule",
63
+ inRadius: "Polomer vpisanej gule",
64
+ midRadius: "Polomer strednej gule",
65
+ };
66
+
67
+ function cube(input) {
68
+ const keys = Object.keys(input).filter((k) => k in paramToEdge);
69
+
70
+ if (keys.length === 0) {
71
+ throw new Error(
72
+ `Neznamy parameter. Povolene: ${Object.keys(paramToEdge).join(", ")}`
73
+ );
74
+ }
75
+ if (keys.length > 1) {
76
+ throw new Error("Zadaj prave jeden parameter.");
77
+ }
78
+
79
+ const key = keys[0];
80
+ const value = input[key];
81
+
82
+ if (typeof value !== "number" || value <= 0 || !isFinite(value)) {
83
+ throw new Error("Hodnota musi byt kladne konecne cislo.");
84
+ }
85
+
86
+ const a = paramToEdge[key](value);
87
+ return fromEdge(a);
88
+ }
89
+
90
+ function printCube(input) {
91
+ const result = cube(input);
92
+ console.log("=== Parametre kocky ===");
93
+ for (const [key, value] of Object.entries(result)) {
94
+ const desc = descriptions[key] || key;
95
+ console.log(` ${desc}: ${value}`);
96
+ }
97
+ return result;
98
+ }
99
+
100
+ module.exports = { cube, printCube, descriptions };
101
+ module.exports.default = cube;
package/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import { createRequire } from "module";
2
+ const require = createRequire(import.meta.url);
3
+ const mod = require("./index.js");
4
+
5
+ export const { cube, printCube, descriptions } = mod;
6
+ export default cube;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@jangaba/qube",
3
+ "version": "1.0.0",
4
+ "description": "Cube calculator – compute all cube parameters from any single one (edge, diagonal, volume, surface area, radius...)",
5
+ "main": "index.js",
6
+ "module": "index.mjs",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./index.mjs",
11
+ "require": "./index.js",
12
+ "types": "./index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "index.mjs",
18
+ "index.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "test": "node cube.test.js"
22
+ },
23
+ "keywords": [
24
+ "cube",
25
+ "geometry",
26
+ "calculator",
27
+ "math",
28
+ "kocka",
29
+ "diagonal",
30
+ "volume",
31
+ "surface-area"
32
+ ],
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": ""
37
+ }
38
+ }