@tkeron/tools 0.2.2 → 0.3.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/.github/workflows/npm_deploy.yml +12 -8
- package/bun.lock +8 -8
- package/changelog.md +25 -0
- package/package.json +13 -4
- package/readme.md +3 -6
- package/src/getPaths.ts +90 -103
- package/src/stack.ts +46 -63
- package/tests/getPaths.test.ts +528 -0
- package/{src → tests}/random.test.ts +1 -1
- package/{src → tests}/stack.test.ts +2 -2
- package/src/getPaths.test.ts +0 -513
|
@@ -4,22 +4,26 @@ on:
|
|
|
4
4
|
branches:
|
|
5
5
|
- main
|
|
6
6
|
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
7
11
|
jobs:
|
|
8
12
|
build-test-publish:
|
|
9
13
|
runs-on: ubuntu-latest
|
|
14
|
+
|
|
10
15
|
steps:
|
|
11
16
|
- uses: actions/checkout@v4
|
|
12
17
|
|
|
13
18
|
- uses: actions/setup-node@v4
|
|
14
19
|
with:
|
|
15
|
-
node-version:
|
|
16
|
-
registry-url: "https://registry.npmjs.org
|
|
20
|
+
node-version: "lts/*"
|
|
21
|
+
registry-url: "https://registry.npmjs.org"
|
|
17
22
|
|
|
18
23
|
- uses: oven-sh/setup-bun@v2
|
|
19
24
|
|
|
20
|
-
- run:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
25
|
+
- run: npm install -g npm@latest
|
|
26
|
+
- run: bun i
|
|
27
|
+
- run: bun run test
|
|
28
|
+
|
|
29
|
+
- run: npm publish --provenance
|
package/bun.lock
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"lockfileVersion": 1,
|
|
3
|
+
"configVersion": 0,
|
|
3
4
|
"workspaces": {
|
|
4
5
|
"": {
|
|
5
6
|
"name": "@tkeron/tools",
|
|
6
7
|
"devDependencies": {
|
|
7
|
-
"@types/bun": "
|
|
8
|
+
"@types/bun": "^1.3.9",
|
|
9
|
+
"prettier": "^3.8.1",
|
|
8
10
|
},
|
|
9
11
|
"peerDependencies": {
|
|
10
|
-
"typescript": "^5.
|
|
12
|
+
"typescript": "^5.9.3",
|
|
11
13
|
},
|
|
12
14
|
},
|
|
13
15
|
},
|
|
14
16
|
"packages": {
|
|
15
|
-
"@types/bun": ["@types/bun@1.
|
|
17
|
+
"@types/bun": ["@types/bun@1.3.9", "", { "dependencies": { "bun-types": "1.3.9" } }, "sha512-KQ571yULOdWJiMH+RIWIOZ7B2RXQGpL1YQrBtLIV3FqDcCu6FsbFUBwhdKUlCKUpS3PJDsHlJ1QKlpxoVR+xtw=="],
|
|
16
18
|
|
|
17
19
|
"@types/node": ["@types/node@22.13.1", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew=="],
|
|
18
20
|
|
|
19
|
-
"
|
|
21
|
+
"bun-types": ["bun-types@1.3.9", "", { "dependencies": { "@types/node": "*" } }, "sha512-+UBWWOakIP4Tswh0Bt0QD0alpTY8cb5hvgiYeWCMet9YukHbzuruIEeXC2D7nMJPB12kbh8C7XJykSexEqGKJg=="],
|
|
20
22
|
|
|
21
|
-
"
|
|
23
|
+
"prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="],
|
|
22
24
|
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
"typescript": ["typescript@5.7.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw=="],
|
|
25
|
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
|
26
26
|
|
|
27
27
|
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
|
|
28
28
|
}
|
package/changelog.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.3.0] - 2026-02-15
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Configured trusted publisher with OIDC for npm deployment
|
|
8
|
+
- Added `lint` script using Prettier for code formatting
|
|
9
|
+
- Added Prettier as devDependency
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Updated npm deployment workflow to use OIDC authentication instead of NPM_TOKEN
|
|
14
|
+
- Standardized repository URL format in package.json
|
|
15
|
+
- Code formatting applied across all source and test files
|
|
16
|
+
|
|
17
|
+
### Infrastructure
|
|
18
|
+
|
|
19
|
+
- GitHub Actions now uses `permissions: id-token: write` for secure publishing
|
|
20
|
+
- npm publish now includes `--provenance` flag for supply chain security
|
|
21
|
+
- Node.js version standardized to `lts/*` in CI workflow
|
|
22
|
+
|
|
23
|
+
## [0.2.2] - Previous releases
|
|
24
|
+
|
|
25
|
+
(Previous version history not documented)
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tkeron/tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Useful JavaScript utilities for Bun runtime",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"module": "src/index.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"author": "tkeron",
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "bun test --concurrent",
|
|
12
|
+
"lint": "prettier --write ."
|
|
13
|
+
},
|
|
10
14
|
"engines": {
|
|
11
15
|
"bun": ">=1.0.0"
|
|
12
16
|
},
|
|
13
17
|
"devDependencies": {
|
|
14
|
-
"@types/bun": "
|
|
18
|
+
"@types/bun": "^1.3.9",
|
|
19
|
+
"prettier": "^3.8.1"
|
|
15
20
|
},
|
|
16
21
|
"peerDependencies": {
|
|
17
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.9.3"
|
|
18
23
|
},
|
|
19
24
|
"keywords": [
|
|
20
25
|
"bun",
|
|
@@ -22,7 +27,11 @@
|
|
|
22
27
|
"utils",
|
|
23
28
|
"tools"
|
|
24
29
|
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
25
33
|
"repository": {
|
|
26
|
-
"
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/tkeron/tools.git"
|
|
27
36
|
}
|
|
28
37
|
}
|
package/readme.md
CHANGED
|
@@ -21,10 +21,10 @@ This package provides a growing collection of utility functions and data structu
|
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
23
|
// Import all utilities
|
|
24
|
-
import * as tools from
|
|
24
|
+
import * as tools from "@tkeron/tools";
|
|
25
25
|
|
|
26
26
|
// Or import specific utilities
|
|
27
|
-
import { rng, getLIFO, getPaths } from
|
|
27
|
+
import { rng, getLIFO, getPaths } from "@tkeron/tools";
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
## 📚 Documentation
|
|
@@ -39,7 +39,4 @@ The project includes comprehensive tests for all utilities:
|
|
|
39
39
|
bun test
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Built with ❤️ for the Bun ecosystem
|
|
42
|
+
Built with ❤️ for the Bun ecosystem
|
package/src/getPaths.ts
CHANGED
|
@@ -2,113 +2,100 @@ import { Glob } from "bun";
|
|
|
2
2
|
import { statSync } from "fs";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Gets file paths, directory paths, or both based on the specified parameters
|
|
7
|
-
* @param path - The base directory path to search in
|
|
8
|
-
* @param pattern - The glob pattern to match files/directories (default: **\/*)
|
|
9
|
-
* @param includeDirectories - Controls what to include: yes (files + dirs), no (files only), onlyDirectories (dirs only)
|
|
10
|
-
* @param absolute - Whether to return absolute paths (default: true)
|
|
11
|
-
* @returns Array of paths matching the criteria
|
|
12
|
-
*/
|
|
13
5
|
export const getPaths = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
path: string,
|
|
7
|
+
pattern: string = "**/*",
|
|
8
|
+
includeDirectories: "yes" | "no" | "onlyDirectories" = "no",
|
|
9
|
+
absolute: boolean = true,
|
|
18
10
|
): string[] => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
11
|
+
try {
|
|
12
|
+
if (includeDirectories === "no")
|
|
13
|
+
return getFilePaths(path, pattern, absolute);
|
|
14
|
+
if (includeDirectories === "onlyDirectories")
|
|
15
|
+
return getDirectoryPaths(path, pattern, absolute);
|
|
16
|
+
|
|
17
|
+
const paths: string[] = [];
|
|
18
|
+
|
|
19
|
+
const glob = new Glob(pattern);
|
|
20
|
+
|
|
21
|
+
const files = glob.scanSync({
|
|
22
|
+
cwd: path,
|
|
23
|
+
onlyFiles: false,
|
|
24
|
+
absolute: absolute,
|
|
25
|
+
dot: true,
|
|
26
|
+
followSymlinks: false,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
paths.push(...files);
|
|
30
|
+
|
|
31
|
+
return paths;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(`Error getting paths from ${path}:`, error);
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
42
36
|
};
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} catch (error) {
|
|
70
|
-
console.error(`Error getting file paths from ${path}:`, error);
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
38
|
+
export const getFilePaths = (
|
|
39
|
+
path: string,
|
|
40
|
+
pattern: string = "**/*",
|
|
41
|
+
absolute: boolean = true,
|
|
42
|
+
): string[] => {
|
|
43
|
+
try {
|
|
44
|
+
const paths: string[] = [];
|
|
45
|
+
|
|
46
|
+
const glob = new Glob(pattern);
|
|
47
|
+
|
|
48
|
+
const files = glob.scanSync({
|
|
49
|
+
cwd: path,
|
|
50
|
+
onlyFiles: true,
|
|
51
|
+
absolute: absolute,
|
|
52
|
+
dot: true,
|
|
53
|
+
followSymlinks: false,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
paths.push(...files);
|
|
57
|
+
|
|
58
|
+
return paths;
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(`Error getting file paths from ${path}:`, error);
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
73
63
|
};
|
|
74
64
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
65
|
+
export const getDirectoryPaths = (
|
|
66
|
+
path: string,
|
|
67
|
+
pattern: string = "**/*",
|
|
68
|
+
absolute: boolean = true,
|
|
69
|
+
): string[] => {
|
|
70
|
+
try {
|
|
71
|
+
const paths: string[] = [];
|
|
72
|
+
|
|
73
|
+
const glob = new Glob(pattern);
|
|
74
|
+
|
|
75
|
+
const allItems = [
|
|
76
|
+
...glob.scanSync({
|
|
77
|
+
cwd: path,
|
|
78
|
+
onlyFiles: false,
|
|
79
|
+
absolute: absolute,
|
|
80
|
+
dot: true,
|
|
81
|
+
followSymlinks: false,
|
|
82
|
+
}),
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
const directories = allItems.filter((item) => {
|
|
86
|
+
try {
|
|
87
|
+
const fullPath = absolute ? item : join(path, item);
|
|
88
|
+
return statSync(fullPath).isDirectory();
|
|
89
|
+
} catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
paths.push(...directories);
|
|
95
|
+
|
|
96
|
+
return paths;
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error(`Error getting directory paths from ${path}:`, error);
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
112
101
|
};
|
|
113
|
-
|
|
114
|
-
|
package/src/stack.ts
CHANGED
|
@@ -1,70 +1,53 @@
|
|
|
1
|
-
|
|
2
1
|
export interface Stack<T> {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
pop: () => T;
|
|
3
|
+
push: (item: T) => void;
|
|
4
|
+
readonly length: number;
|
|
5
|
+
current: T | null;
|
|
7
6
|
}
|
|
8
7
|
|
|
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
8
|
export const getLIFO = <T>(): Stack<T> => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return stack;
|
|
39
|
-
|
|
40
|
-
|
|
9
|
+
const _stack: T[] = [];
|
|
10
|
+
|
|
11
|
+
const stack = <Stack<T>>{
|
|
12
|
+
pop: () => _stack.pop(),
|
|
13
|
+
push: (item) => _stack.push(item),
|
|
14
|
+
length: 0,
|
|
15
|
+
current: <T>(<unknown>null),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(stack, "current", {
|
|
19
|
+
get: () => (_stack.length ? _stack[_stack.length - 1] : null),
|
|
20
|
+
set: (value) => {
|
|
21
|
+
if (_stack.length) _stack[_stack.length - 1] = value;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(stack, "length", {
|
|
26
|
+
get: () => _stack.length,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return stack;
|
|
41
30
|
};
|
|
42
31
|
|
|
43
|
-
/**
|
|
44
|
-
* Returns a FIFO (First In First Out) stack
|
|
45
|
-
* @returns an empty FIFO stack
|
|
46
|
-
*/
|
|
47
32
|
export const getFIFO = <T>(): Stack<T> => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
33
|
+
const _stack: T[] = [];
|
|
34
|
+
const stack = <Stack<T>>{
|
|
35
|
+
pop: () => _stack.shift(),
|
|
36
|
+
push: (item) => _stack.push(item),
|
|
37
|
+
length: 0,
|
|
38
|
+
current: <T>(<unknown>null),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(stack, "current", {
|
|
42
|
+
get: () => (_stack.length ? _stack[0] : null),
|
|
43
|
+
set: (value) => {
|
|
44
|
+
if (_stack.length) _stack[0] = value;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
Object.defineProperty(stack, "length", {
|
|
49
|
+
get: () => _stack.length,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return stack;
|
|
53
|
+
};
|