@tkeron/tools 0.1.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.
@@ -0,0 +1,28 @@
1
+ name: tools package
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ jobs:
8
+ build-test-publish:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+
13
+ - uses: actions/setup-node@v4
14
+ with:
15
+ node-version: 22.x
16
+ registry-url: "https://registry.npmjs.org/"
17
+
18
+ - uses: oven-sh/setup-bun@v2
19
+
20
+ - run: |
21
+ bun i
22
+ bun test
23
+
24
+ - name: Authenticate npm
25
+ run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
26
+
27
+ - name: Publish to npm
28
+ run: npm publish --access public
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 tkeron
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bun.lock ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "workspaces": {
4
+ "": {
5
+ "name": "@tkeron/tools",
6
+ "devDependencies": {
7
+ "@types/bun": "latest",
8
+ },
9
+ "peerDependencies": {
10
+ "typescript": "^5.0.0",
11
+ },
12
+ },
13
+ },
14
+ "packages": {
15
+ "@types/bun": ["@types/bun@1.2.2", "", { "dependencies": { "bun-types": "1.2.2" } }, "sha512-tr74gdku+AEDN5ergNiBnplr7hpDp3V1h7fqI2GcR/rsUaM39jpSeKH0TFibRvU0KwniRx5POgaYnaXbk0hU+w=="],
16
+
17
+ "@types/node": ["@types/node@22.13.1", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew=="],
18
+
19
+ "@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
20
+
21
+ "bun-types": ["bun-types@1.2.2", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-RCbMH5elr9gjgDGDhkTTugA21XtJAy/9jkKe/G3WR2q17VPGhcquf9Sir6uay9iW+7P/BV0CAHA1XlHXMAVKHg=="],
22
+
23
+ "typescript": ["typescript@5.7.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw=="],
24
+
25
+ "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
26
+ }
27
+ }
package/changelog.md ADDED
@@ -0,0 +1,3 @@
1
+ # v0.1.0
2
+
3
+ - initial repo with useful tools.
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@tkeron/tools",
3
+ "version": "0.1.0",
4
+ "description": "Useful JavaScript utilities",
5
+ "main": "src/index.ts",
6
+ "module": "src/index.ts",
7
+ "type": "module",
8
+ "author": "tkeron",
9
+ "license": "MIT",
10
+ "devDependencies": {
11
+ "@types/bun": "latest"
12
+ },
13
+ "peerDependencies": {
14
+ "typescript": "^5.0.0"
15
+ },
16
+ "keywords": [
17
+ "utilities",
18
+ "utils"
19
+ ],
20
+ "repository": {
21
+ "url": "git@github.com:tkeron/tools.git"
22
+ }
23
+ }
package/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # Tkeron Commands
2
+
3
+ Simple package to evaluate cli arguments, with minimun dependencies.
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./random";
2
+ export * from "./stack";
@@ -0,0 +1,135 @@
1
+ import { describe, it, expect } from "bun:test";
2
+ import { rng } from "./random";
3
+
4
+ describe("testing rng", () => {
5
+ it("should return the same 10 random numbers for seed=344", () => {
6
+ const numbers = [...rng(344, 10)];
7
+ const expected = [
8
+ 88811757, 1786880006, -1901549690, -783089686, 1532981021, 1629592611,
9
+ 102726481, -941665653, -1672827444, -141168747,
10
+ ];
11
+ expect(numbers).toEqual(expected);
12
+ });
13
+
14
+ it("should return the same 100 random numbers for seed=158484", () => {
15
+ const numbers = [...rng(158484, 100)];
16
+ const expected = [
17
+ -512132828, 98688842, -15169138, 721513946, -771752345, -397269314,
18
+ 1010577276, -2086534859, -1290576361, -1025237601, 1806465972, 2139370233,
19
+ -1028051820, 39829281, 1120459388, 1768530271, -183529410, -436067078,
20
+ -248249548, 1527105597, -1571897668, -960918928, 151404779, -495137626,
21
+ 116267794, 1946452820, 1773133059, -738265980, -1600113581, 1667592070,
22
+ 472076620, -1218993303, 611253364, -2014334716, 1210987907, 1565772620,
23
+ -1552845967, 787622462, 487465828, -181095051, 283030456, 329010540,
24
+ -603058444, -1480555620, 1104662757, -1029632768, -2094961536, 2023342296,
25
+ 1356788665, 1536461133, -1659154829, 1852856121, -159388878, 1747745150,
26
+ 125113631, 521001332, 541976517, 169589375, -673644939, -891357762,
27
+ -1722888502, 1382186657, -1417912518, 872079767, -1764820973, 1885020757,
28
+ -1776253955, 1304230546, -1891946683, -1331478612, 1032049895,
29
+ -1526859160, 1840120240, 513620220, -1982733411, 32420044, 689159639,
30
+ -1954077981, -1800022834, -341018408, -228713757, 290336290, 1170540679,
31
+ 2120828749, -2036773459, 1253342555, 1727989076, 1289914814, -1484935724,
32
+ 1243853399, -1321156605, -2125340477, 343773831, 1669764017, -1881013655,
33
+ 977826430, -1259165731, -517468935, -162314014, 1990733797,
34
+ ];
35
+ expect(numbers).toEqual(expected);
36
+ });
37
+ it.skip("should return info about series of 98688842", () => {
38
+ const seed = 98688842;
39
+ const gen = rng(seed);
40
+ const info = {
41
+ seed,
42
+ period: 0,
43
+ max: Number.MIN_SAFE_INTEGER,
44
+ min: Number.MAX_SAFE_INTEGER,
45
+ minPositive: Number.MAX_SAFE_INTEGER,
46
+ maxNegative: Number.MIN_SAFE_INTEGER,
47
+ };
48
+ while (true) {
49
+ const num = gen.next().value!;
50
+
51
+ if (num > info.max) info.max = num;
52
+ if (num < info.min) info.min = num;
53
+
54
+ if (num > 0 && num < info.minPositive) info.minPositive = num;
55
+ if (num < 0 && num > info.maxNegative) info.maxNegative = num;
56
+
57
+ info.period++;
58
+
59
+ if (num === seed) break;
60
+ }
61
+
62
+ console.log(JSON.stringify(info, null, 4));
63
+
64
+ expect(info).toEqual({
65
+ seed: 98688842,
66
+ period: 1073741822,
67
+ max: 2147483647,
68
+ min: -2147483646,
69
+ minPositive: 1,
70
+ maxNegative: -4,
71
+ });
72
+ });
73
+ it.skip("should return info about series of numbers...", () => {
74
+ const seeds = [1, 4, 8];
75
+ const gens = seeds.map((s) => rng(s));
76
+ const infos = seeds.map((seed) => ({
77
+ seed,
78
+ period: 0,
79
+ max: Number.MIN_SAFE_INTEGER,
80
+ min: Number.MAX_SAFE_INTEGER,
81
+ minPositive: Number.MAX_SAFE_INTEGER,
82
+ maxNegative: Number.MIN_SAFE_INTEGER,
83
+ }));
84
+ let i = 0;
85
+ while (true) {
86
+ const info = infos[i];
87
+ const gen = gens[i];
88
+ const seed = seeds[i];
89
+
90
+ const num = gen.next().value!;
91
+
92
+ if (num > info.max) info.max = num;
93
+ if (num < info.min) info.min = num;
94
+
95
+ if (num > 0 && num < info.minPositive) info.minPositive = num;
96
+ if (num < 0 && num > info.maxNegative) info.maxNegative = num;
97
+
98
+ info.period++;
99
+
100
+ if (num === seed) break;
101
+
102
+ i++;
103
+ if (i >= seeds.length) i = 0;
104
+ }
105
+
106
+ console.log(JSON.stringify(infos, null, 4));
107
+
108
+ expect(infos).toEqual([
109
+ {
110
+ seed: 1,
111
+ period: 1073741822,
112
+ max: 2147483647,
113
+ min: -2147483646,
114
+ minPositive: 1,
115
+ maxNegative: -4,
116
+ },
117
+ {
118
+ seed: 4,
119
+ period: 1073741821,
120
+ max: 2147483647,
121
+ min: -2147483646,
122
+ minPositive: 1,
123
+ maxNegative: -4,
124
+ },
125
+ {
126
+ seed: 8,
127
+ period: 1073741821,
128
+ max: 2147483647,
129
+ min: -2147483646,
130
+ minPositive: 1,
131
+ maxNegative: -4,
132
+ },
133
+ ]);
134
+ });
135
+ });
package/src/random.ts ADDED
@@ -0,0 +1,11 @@
1
+ export function* rng(seed = 0, limit = 0) {
2
+ let current = 0;
3
+ while (true) {
4
+ seed ^= seed << 13;
5
+ seed ^= seed >> 17;
6
+ seed ^= seed << 5;
7
+ yield seed;
8
+ if (limit > 0) current++;
9
+ if (limit > 0 && current >= limit) break;
10
+ }
11
+ }
@@ -0,0 +1,102 @@
1
+ import { describe, it, expect } from "bun:test";
2
+ import { getFIFO } from "./stack";
3
+ import { getLIFO } from "./stack";
4
+
5
+ describe("LIFO stack tests", () => {
6
+ it("should create an empty lifo stack", () => {
7
+ const lifo = getLIFO<number>();
8
+ expect(lifo.length).toBe(0);
9
+ expect(lifo.current).toBe(null);
10
+ });
11
+
12
+ it("should push an item to the lifo stack", () => {
13
+ const lifo = getLIFO<number>();
14
+ lifo.push(1);
15
+ expect(lifo.length).toBe(1);
16
+ expect(lifo.current).toBe(1);
17
+ });
18
+
19
+ it("should pop an item from the lifo stack", () => {
20
+ const lifo = getLIFO<number>();
21
+ lifo.push(1);
22
+ expect(lifo.current).toBe(1);
23
+ expect(lifo.pop()).toBe(1);
24
+ expect(lifo.length).toBe(0);
25
+ expect(lifo.current).toBe(null);
26
+ });
27
+
28
+ it("should push multiple items to the lifo stack", () => {
29
+ const lifo = getLIFO<number>();
30
+ lifo.push(1);
31
+ lifo.push(2);
32
+ lifo.push(3);
33
+ expect(lifo.length).toBe(3);
34
+ expect(lifo.current).toBe(3);
35
+ });
36
+
37
+ it("should pop multiple items from the lifo stack", () => {
38
+ const lifo = getLIFO<number>();
39
+ lifo.push(1);
40
+ lifo.push(2);
41
+ lifo.push(3);
42
+ expect(lifo.pop()).toBe(3);
43
+ expect(lifo.pop()).toBe(2);
44
+ expect(lifo.pop()).toBe(1);
45
+ expect(lifo.length).toBe(0);
46
+ expect(lifo.current).toBe(null);
47
+ });
48
+
49
+ it("verify LIFO behavior with direct current modification", () => {
50
+ const lifo = getLIFO<number>();
51
+ lifo.push(1);
52
+ lifo.push(2);
53
+ lifo.current = 3;
54
+ expect(lifo.length).toBe(2);
55
+ expect(lifo.current).toBe(3);
56
+ });
57
+ });
58
+
59
+ describe("FIFO stack tests", () => {
60
+ it("should create an empty fifo stack", () => {
61
+ const fifo = getFIFO<number>();
62
+ expect(fifo.length).toBe(0);
63
+ expect(fifo.current).toBe(null);
64
+ });
65
+
66
+ it("should push an item to the fifo stack", () => {
67
+ const fifo = getFIFO<number>();
68
+ fifo.push(1);
69
+ expect(fifo.length).toBe(1);
70
+ expect(fifo.current).toBe(1);
71
+ });
72
+
73
+ it("should pop an item from the fifo stack", () => {
74
+ const fifo = getFIFO<number>();
75
+ fifo.push(1);
76
+ expect(fifo.current).toBe(1);
77
+ expect(fifo.pop()).toBe(1);
78
+ expect(fifo.length).toBe(0);
79
+ expect(fifo.current).toBe(null);
80
+ });
81
+
82
+ it("should push multiple items to the fifo stack", () => {
83
+ const fifo = getFIFO<number>();
84
+ fifo.push(1);
85
+ fifo.push(2);
86
+ fifo.push(3);
87
+ expect(fifo.length).toBe(3);
88
+ expect(fifo.current).toBe(1);
89
+ });
90
+
91
+ it("should pop multiple items from the fifo stack", () => {
92
+ const fifo = getFIFO<number>();
93
+ fifo.push(1);
94
+ fifo.push(2);
95
+ fifo.push(3);
96
+ expect(fifo.pop()).toBe(1);
97
+ expect(fifo.pop()).toBe(2);
98
+ expect(fifo.pop()).toBe(3);
99
+ expect(fifo.length).toBe(0);
100
+ expect(fifo.current).toBe(null);
101
+ });
102
+ });
package/src/stack.ts ADDED
@@ -0,0 +1,70 @@
1
+
2
+ export interface Stack<T> {
3
+ pop: () => T;
4
+ push: (item: T) => void;
5
+ readonly length: number;
6
+ current: T | null;
7
+ }
8
+
9
+ /**
10
+ * Returns a LIFO (Last In First Out) stack.
11
+ * Same as FILO (First In Last Out) stack.
12
+ * @returns an empty LIFO stack.
13
+ */
14
+ export const getLIFO = <T>(): Stack<T> => {
15
+
16
+ const _stack: T[] = [];
17
+
18
+
19
+ const stack = <Stack<T>>{
20
+ pop: () => _stack.pop(),
21
+ push: (item) => _stack.push(item),
22
+ length: 0,
23
+ current: <T><unknown>null
24
+ };
25
+
26
+ Object.defineProperty(stack, "current", {
27
+ get: () => _stack.length ? _stack[_stack.length - 1] : null,
28
+ set: (value) => {
29
+ if (_stack.length) _stack[_stack.length - 1] = value;
30
+ }
31
+ });
32
+
33
+ Object.defineProperty(stack, "length", {
34
+ get: () => _stack.length,
35
+ });
36
+
37
+
38
+ return stack;
39
+
40
+
41
+ };
42
+
43
+ /**
44
+ * Returns a FIFO (First In First Out) stack
45
+ * @returns an empty FIFO stack
46
+ */
47
+ export const getFIFO = <T>(): Stack<T> => {
48
+
49
+ const _stack: T[] = [];
50
+ const stack = <Stack<T>>{
51
+ pop: () => _stack.shift(),
52
+ push: (item) => _stack.push(item),
53
+ length: 0,
54
+ current: <T><unknown>null
55
+ };
56
+
57
+ Object.defineProperty(stack, "current", {
58
+ get: () => _stack.length ? _stack[0] : null,
59
+ set: (value) => {
60
+ if (_stack.length) _stack[0] = value;
61
+ }
62
+ });
63
+
64
+ Object.defineProperty(stack, "length", {
65
+ get: () => _stack.length,
66
+ });
67
+
68
+ return stack;
69
+
70
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Enable latest features
4
+ "lib": ["ESNext", "DOM"],
5
+ "target": "ESNext",
6
+ "module": "ESNext",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+
22
+ // Some stricter flags (disabled by default)
23
+ "noUnusedLocals": false,
24
+ "noUnusedParameters": false,
25
+ "noPropertyAccessFromIndexSignature": false
26
+ }
27
+ }