@adriangalilea/utils 0.0.10
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 +99 -0
- package/dist/browser.d.ts +14 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +18 -0
- package/dist/browser.js.map +1 -0
- package/dist/currency/crypto-symbols-data.d.ts +10 -0
- package/dist/currency/crypto-symbols-data.d.ts.map +1 -0
- package/dist/currency/crypto-symbols-data.js +13765 -0
- package/dist/currency/crypto-symbols-data.js.map +1 -0
- package/dist/currency/crypto-symbols.d.ts +20 -0
- package/dist/currency/crypto-symbols.d.ts.map +1 -0
- package/dist/currency/crypto-symbols.js +23 -0
- package/dist/currency/crypto-symbols.js.map +1 -0
- package/dist/currency/download-crypto-list.d.ts +10 -0
- package/dist/currency/download-crypto-list.d.ts.map +1 -0
- package/dist/currency/download-crypto-list.js +69 -0
- package/dist/currency/download-crypto-list.js.map +1 -0
- package/dist/currency/index.d.ts +84 -0
- package/dist/currency/index.d.ts.map +1 -0
- package/dist/currency/index.js +230 -0
- package/dist/currency/index.js.map +1 -0
- package/dist/dir.d.ts +40 -0
- package/dist/dir.d.ts.map +1 -0
- package/dist/dir.js +108 -0
- package/dist/dir.js.map +1 -0
- package/dist/file.d.ts +53 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/file.js +211 -0
- package/dist/file.js.map +1 -0
- package/dist/format.d.ts +40 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +83 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/kev.d.ts +149 -0
- package/dist/kev.d.ts.map +1 -0
- package/dist/kev.js +761 -0
- package/dist/kev.js.map +1 -0
- package/dist/log.d.ts +91 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +300 -0
- package/dist/log.js.map +1 -0
- package/dist/logger.d.ts +91 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +269 -0
- package/dist/logger.js.map +1 -0
- package/dist/offensive.d.ts +73 -0
- package/dist/offensive.d.ts.map +1 -0
- package/dist/offensive.js +103 -0
- package/dist/offensive.js.map +1 -0
- package/dist/path.d.ts +67 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +107 -0
- package/dist/path.js.map +1 -0
- package/dist/platform/dir.d.ts +40 -0
- package/dist/platform/dir.d.ts.map +1 -0
- package/dist/platform/dir.js +108 -0
- package/dist/platform/dir.js.map +1 -0
- package/dist/platform/file.d.ts +53 -0
- package/dist/platform/file.d.ts.map +1 -0
- package/dist/platform/file.js +211 -0
- package/dist/platform/file.js.map +1 -0
- package/dist/platform/kev.d.ts +149 -0
- package/dist/platform/kev.d.ts.map +1 -0
- package/dist/platform/kev.js +762 -0
- package/dist/platform/kev.js.map +1 -0
- package/dist/platform/path.d.ts +67 -0
- package/dist/platform/path.d.ts.map +1 -0
- package/dist/platform/path.js +108 -0
- package/dist/platform/path.js.map +1 -0
- package/dist/platform/project.d.ts +35 -0
- package/dist/platform/project.d.ts.map +1 -0
- package/dist/platform/project.js +155 -0
- package/dist/platform/project.js.map +1 -0
- package/dist/project.d.ts +35 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +154 -0
- package/dist/project.js.map +1 -0
- package/dist/runtime.d.ts +65 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +193 -0
- package/dist/runtime.js.map +1 -0
- package/dist/universal/currency/crypto-symbols-data.d.ts +10 -0
- package/dist/universal/currency/crypto-symbols-data.d.ts.map +1 -0
- package/dist/universal/currency/crypto-symbols-data.js +13765 -0
- package/dist/universal/currency/crypto-symbols-data.js.map +1 -0
- package/dist/universal/currency/crypto-symbols.d.ts +20 -0
- package/dist/universal/currency/crypto-symbols.d.ts.map +1 -0
- package/dist/universal/currency/crypto-symbols.js +23 -0
- package/dist/universal/currency/crypto-symbols.js.map +1 -0
- package/dist/universal/currency/download-crypto-list.d.ts +10 -0
- package/dist/universal/currency/download-crypto-list.d.ts.map +1 -0
- package/dist/universal/currency/download-crypto-list.js +69 -0
- package/dist/universal/currency/download-crypto-list.js.map +1 -0
- package/dist/universal/currency/index.d.ts +90 -0
- package/dist/universal/currency/index.d.ts.map +1 -0
- package/dist/universal/currency/index.js +276 -0
- package/dist/universal/currency/index.js.map +1 -0
- package/dist/universal/format.d.ts +40 -0
- package/dist/universal/format.d.ts.map +1 -0
- package/dist/universal/format.js +83 -0
- package/dist/universal/format.js.map +1 -0
- package/dist/universal/log.d.ts +91 -0
- package/dist/universal/log.d.ts.map +1 -0
- package/dist/universal/log.js +309 -0
- package/dist/universal/log.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directory operations that exit on error (offensive programming style)
|
|
3
|
+
*/
|
|
4
|
+
declare class DirOps {
|
|
5
|
+
/**
|
|
6
|
+
* Create a directory (including parents) and exit on error
|
|
7
|
+
*/
|
|
8
|
+
create(path: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Check if directory exists
|
|
11
|
+
*/
|
|
12
|
+
exists(path: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Remove a directory and all its contents, exit on error
|
|
15
|
+
*/
|
|
16
|
+
remove(path: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* List all entries in a directory, exit on error
|
|
19
|
+
*/
|
|
20
|
+
list(path: string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* List full paths of all entries in a directory
|
|
23
|
+
*/
|
|
24
|
+
listFull(dirPath: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* List only subdirectories
|
|
27
|
+
*/
|
|
28
|
+
listDirs(path: string): string[];
|
|
29
|
+
/**
|
|
30
|
+
* List only files (not directories)
|
|
31
|
+
*/
|
|
32
|
+
listFiles(path: string): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if directory is empty
|
|
35
|
+
*/
|
|
36
|
+
isEmpty(path: string): boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare const dir: DirOps;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=dir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dir.d.ts","sourceRoot":"","sources":["../../src/platform/dir.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,cAAM,MAAM;IACV;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ1B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAU7B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ1B;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAS5B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAKnC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAYhC;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAYjC;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAS/B;AAED,eAAO,MAAM,GAAG,QAAe,CAAA"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { mkdirSync, existsSync, statSync, rmSync, readdirSync } from 'fs';
|
|
2
|
+
import { check } from '../offensive.js';
|
|
3
|
+
import { path } from './path.js';
|
|
4
|
+
/**
|
|
5
|
+
* Directory operations that exit on error (offensive programming style)
|
|
6
|
+
*/
|
|
7
|
+
class DirOps {
|
|
8
|
+
/**
|
|
9
|
+
* Create a directory (including parents) and exit on error
|
|
10
|
+
*/
|
|
11
|
+
create(path) {
|
|
12
|
+
try {
|
|
13
|
+
mkdirSync(path, { recursive: true, mode: 0o755 });
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
check(err);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if directory exists
|
|
21
|
+
*/
|
|
22
|
+
exists(path) {
|
|
23
|
+
try {
|
|
24
|
+
if (!existsSync(path))
|
|
25
|
+
return false;
|
|
26
|
+
const stats = statSync(path);
|
|
27
|
+
return stats.isDirectory();
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Remove a directory and all its contents, exit on error
|
|
35
|
+
*/
|
|
36
|
+
remove(path) {
|
|
37
|
+
try {
|
|
38
|
+
rmSync(path, { recursive: true, force: true });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
check(err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* List all entries in a directory, exit on error
|
|
46
|
+
*/
|
|
47
|
+
list(path) {
|
|
48
|
+
try {
|
|
49
|
+
return readdirSync(path);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
check(err);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* List full paths of all entries in a directory
|
|
58
|
+
*/
|
|
59
|
+
listFull(dirPath) {
|
|
60
|
+
const names = this.list(dirPath);
|
|
61
|
+
return names.map(name => path.join(dirPath, name));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* List only subdirectories
|
|
65
|
+
*/
|
|
66
|
+
listDirs(path) {
|
|
67
|
+
try {
|
|
68
|
+
const entries = readdirSync(path, { withFileTypes: true });
|
|
69
|
+
return entries
|
|
70
|
+
.filter(entry => entry.isDirectory())
|
|
71
|
+
.map(entry => entry.name);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
check(err);
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* List only files (not directories)
|
|
80
|
+
*/
|
|
81
|
+
listFiles(path) {
|
|
82
|
+
try {
|
|
83
|
+
const entries = readdirSync(path, { withFileTypes: true });
|
|
84
|
+
return entries
|
|
85
|
+
.filter(entry => entry.isFile())
|
|
86
|
+
.map(entry => entry.name);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
check(err);
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if directory is empty
|
|
95
|
+
*/
|
|
96
|
+
isEmpty(path) {
|
|
97
|
+
try {
|
|
98
|
+
const entries = readdirSync(path);
|
|
99
|
+
return entries.length === 0;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
check(err);
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export const dir = new DirOps();
|
|
108
|
+
//# sourceMappingURL=dir.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dir.js","sourceRoot":"","sources":["../../src/platform/dir.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,IAAI,CAAA;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;GAEG;AACH,MAAM,MAAM;IACV;;OAEG;IACH,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC;YACH,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QACnD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,CAAC,GAAG,CAAC,CAAA;QACZ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAY;QACjB,IAAI,CAAC;YACH,IAA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CAAA;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,CAAC,GAAG,CAAC,CAAA;YACV,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,IAAY;QACpB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;YAC1D,OAAO,OAAO;iBACX,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;iBAC/B,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,CAAC,GAAG,CAAC,CAAA;YACV,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,IAAY;QAClB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;YACjC,OAAO,OAAO,CAAC,MAAM,KAAK,CAAC,CAAA;QAC7B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,KAAK,CAAC,GAAG,CAAC,CAAA;YACV,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,GAAG,GAAG,IAAI,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File operations that exit on error (offensive programming style)
|
|
3
|
+
*/
|
|
4
|
+
declare class FileOps {
|
|
5
|
+
/**
|
|
6
|
+
* Get the caller's file URL from the stack trace
|
|
7
|
+
* This allows us to resolve relative paths from the calling module
|
|
8
|
+
*/
|
|
9
|
+
getCallerUrl(): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Read a file and exit on error
|
|
12
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
13
|
+
* Absolute paths are used as-is
|
|
14
|
+
*/
|
|
15
|
+
read(filePath: string): Buffer;
|
|
16
|
+
/**
|
|
17
|
+
* Read a file as string and exit on error
|
|
18
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
19
|
+
* Absolute paths are used as-is
|
|
20
|
+
*
|
|
21
|
+
* @param filePath - Path to the file
|
|
22
|
+
* @param encodingOrUrl - Optional: encoding (e.g. 'utf-8') or import.meta.url for explicit resolution
|
|
23
|
+
* @param encoding - Optional: encoding when second param is import.meta.url
|
|
24
|
+
*/
|
|
25
|
+
readText(filePath: string, encodingOrUrl?: BufferEncoding | string, encoding?: BufferEncoding): string;
|
|
26
|
+
/**
|
|
27
|
+
* Write data to a file and exit on error
|
|
28
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
29
|
+
* Absolute paths are used as-is
|
|
30
|
+
*/
|
|
31
|
+
write(filePath: string, data: string | Buffer): void;
|
|
32
|
+
/**
|
|
33
|
+
* Check if file exists (not a directory)
|
|
34
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
35
|
+
* Absolute paths are used as-is
|
|
36
|
+
*/
|
|
37
|
+
exists(filePath: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Remove a file and exit on error
|
|
40
|
+
*/
|
|
41
|
+
remove(path: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get file size in bytes
|
|
44
|
+
*/
|
|
45
|
+
size(path: string): number;
|
|
46
|
+
/**
|
|
47
|
+
* Get file modification time
|
|
48
|
+
*/
|
|
49
|
+
mtime(path: string): Date;
|
|
50
|
+
}
|
|
51
|
+
export declare const file: FileOps;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/platform/file.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,cAAM,OAAO;IACX;;;OAGG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS;IA2DlC;;;;OAIG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAkB9B;;;;;;;;OAQG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,cAAc,GAAG,MAAM,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,MAAM;IAkCtG;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAiBpD;;;;OAIG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAmBjC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ1B;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAU1B;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAS1B;AAED,eAAO,MAAM,IAAI,SAAgB,CAAA"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync, existsSync, unlinkSync, statSync } from 'fs';
|
|
2
|
+
import { check } from '../offensive.js';
|
|
3
|
+
import { path } from './path.js';
|
|
4
|
+
/**
|
|
5
|
+
* File operations that exit on error (offensive programming style)
|
|
6
|
+
*/
|
|
7
|
+
class FileOps {
|
|
8
|
+
/**
|
|
9
|
+
* Get the caller's file URL from the stack trace
|
|
10
|
+
* This allows us to resolve relative paths from the calling module
|
|
11
|
+
*/
|
|
12
|
+
getCallerUrl() {
|
|
13
|
+
const err = new Error();
|
|
14
|
+
const stack = err.stack;
|
|
15
|
+
if (!stack)
|
|
16
|
+
return undefined;
|
|
17
|
+
// Parse stack to find file URLs
|
|
18
|
+
// Stack looks like:
|
|
19
|
+
// Error
|
|
20
|
+
// at FileOps.getCallerUrl (file:///path/to/file.ts:line:col)
|
|
21
|
+
// at FileOps.readText (file:///path/to/file.ts:line:col)
|
|
22
|
+
// at caller (file:///path/to/caller.ts:line:col) <- we want this
|
|
23
|
+
const lines = stack.split('\n');
|
|
24
|
+
// Try multiple regex patterns for different environments
|
|
25
|
+
const patterns = [
|
|
26
|
+
/\(file:\/\/([^:)]+)(?::\d+:\d+)?\)/, // Node ESM: (file:///path/file.js:1:2)
|
|
27
|
+
/at file:\/\/([^:)]+)(?::\d+:\d+)?/, // Node ESM alternate: at file:///path/file.js:1:2
|
|
28
|
+
/\(([^:)]+\.m?js)(?::\d+:\d+)?\)/, // Node CJS: (/path/file.js:1:2)
|
|
29
|
+
/at ([^:)]+\.m?js)(?::\d+:\d+)?/, // Node CJS alternate: at /path/file.js:1:2
|
|
30
|
+
];
|
|
31
|
+
// Start at line 3 to skip: Error, getCallerUrl, and the calling method (read/readText/etc)
|
|
32
|
+
for (let i = 3; i < lines.length && i < 10; i++) { // Limit search depth
|
|
33
|
+
const line = lines[i];
|
|
34
|
+
// Skip internal file.ts/file.js lines
|
|
35
|
+
if (line.includes('/file.js') || line.includes('/file.ts') ||
|
|
36
|
+
line.includes('\\file.js') || line.includes('\\file.ts')) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
for (const pattern of patterns) {
|
|
40
|
+
const match = line.match(pattern);
|
|
41
|
+
if (match) {
|
|
42
|
+
// Found a match - build file URL
|
|
43
|
+
let filePath = match[1] || match[0];
|
|
44
|
+
// Handle Windows paths
|
|
45
|
+
if (process.platform === 'win32' && !filePath.startsWith('file://')) {
|
|
46
|
+
filePath = filePath.replace(/\\/g, '/');
|
|
47
|
+
}
|
|
48
|
+
// Ensure we have a file:// URL
|
|
49
|
+
if (!filePath.startsWith('file://')) {
|
|
50
|
+
filePath = 'file://' + (filePath.startsWith('/') ? '' : '/') + filePath;
|
|
51
|
+
}
|
|
52
|
+
// Remove line and column numbers if present
|
|
53
|
+
filePath = filePath.replace(/:\d+:\d+$/, '');
|
|
54
|
+
return filePath;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Read a file and exit on error
|
|
62
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
63
|
+
* Absolute paths are used as-is
|
|
64
|
+
*/
|
|
65
|
+
read(filePath) {
|
|
66
|
+
try {
|
|
67
|
+
// Auto-detect caller for relative paths
|
|
68
|
+
let resolvedPath = filePath;
|
|
69
|
+
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
|
70
|
+
const callerUrl = this.getCallerUrl();
|
|
71
|
+
resolvedPath = path.resolve(filePath, callerUrl);
|
|
72
|
+
}
|
|
73
|
+
else if (!path.isAbsolute(filePath)) {
|
|
74
|
+
resolvedPath = path.resolve(filePath);
|
|
75
|
+
}
|
|
76
|
+
return readFileSync(resolvedPath);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
check(err);
|
|
80
|
+
throw err; // TypeScript needs this even though check exits
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Read a file as string and exit on error
|
|
85
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
86
|
+
* Absolute paths are used as-is
|
|
87
|
+
*
|
|
88
|
+
* @param filePath - Path to the file
|
|
89
|
+
* @param encodingOrUrl - Optional: encoding (e.g. 'utf-8') or import.meta.url for explicit resolution
|
|
90
|
+
* @param encoding - Optional: encoding when second param is import.meta.url
|
|
91
|
+
*/
|
|
92
|
+
readText(filePath, encodingOrUrl, encoding) {
|
|
93
|
+
try {
|
|
94
|
+
// Determine if second param is encoding or URL
|
|
95
|
+
let callerUrl;
|
|
96
|
+
let actualEncoding = 'utf-8';
|
|
97
|
+
if (encodingOrUrl) {
|
|
98
|
+
if (encodingOrUrl.startsWith('file://') || encodingOrUrl.includes('/')) {
|
|
99
|
+
// It's a URL/path
|
|
100
|
+
callerUrl = encodingOrUrl;
|
|
101
|
+
actualEncoding = encoding || 'utf-8';
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// It's an encoding
|
|
105
|
+
actualEncoding = encodingOrUrl;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Auto-detect caller for relative paths
|
|
109
|
+
let resolvedPath = filePath;
|
|
110
|
+
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
|
111
|
+
// Use explicit URL if provided, otherwise detect from stack
|
|
112
|
+
const url = callerUrl || this.getCallerUrl();
|
|
113
|
+
resolvedPath = path.resolve(filePath, url);
|
|
114
|
+
}
|
|
115
|
+
else if (!path.isAbsolute(filePath)) {
|
|
116
|
+
resolvedPath = path.resolve(filePath);
|
|
117
|
+
}
|
|
118
|
+
return readFileSync(resolvedPath, actualEncoding);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
check(err);
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Write data to a file and exit on error
|
|
127
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
128
|
+
* Absolute paths are used as-is
|
|
129
|
+
*/
|
|
130
|
+
write(filePath, data) {
|
|
131
|
+
try {
|
|
132
|
+
// Auto-detect caller for relative paths
|
|
133
|
+
let resolvedPath = filePath;
|
|
134
|
+
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
|
135
|
+
const callerUrl = this.getCallerUrl();
|
|
136
|
+
resolvedPath = path.resolve(filePath, callerUrl);
|
|
137
|
+
}
|
|
138
|
+
else if (!path.isAbsolute(filePath)) {
|
|
139
|
+
resolvedPath = path.resolve(filePath);
|
|
140
|
+
}
|
|
141
|
+
writeFileSync(resolvedPath, data, { mode: 0o644 });
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
check(err);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Check if file exists (not a directory)
|
|
149
|
+
* Relative paths (./file.txt) are resolved from the calling module
|
|
150
|
+
* Absolute paths are used as-is
|
|
151
|
+
*/
|
|
152
|
+
exists(filePath) {
|
|
153
|
+
try {
|
|
154
|
+
// Auto-detect caller for relative paths
|
|
155
|
+
let resolvedPath = filePath;
|
|
156
|
+
if (filePath.startsWith('./') || filePath.startsWith('../')) {
|
|
157
|
+
const callerUrl = this.getCallerUrl();
|
|
158
|
+
resolvedPath = path.resolve(filePath, callerUrl);
|
|
159
|
+
}
|
|
160
|
+
else if (!path.isAbsolute(filePath)) {
|
|
161
|
+
resolvedPath = path.resolve(filePath);
|
|
162
|
+
}
|
|
163
|
+
if (!existsSync(resolvedPath))
|
|
164
|
+
return false;
|
|
165
|
+
const stats = statSync(resolvedPath);
|
|
166
|
+
return stats.isFile();
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Remove a file and exit on error
|
|
174
|
+
*/
|
|
175
|
+
remove(path) {
|
|
176
|
+
try {
|
|
177
|
+
unlinkSync(path);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
check(err);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get file size in bytes
|
|
185
|
+
*/
|
|
186
|
+
size(path) {
|
|
187
|
+
try {
|
|
188
|
+
const stats = statSync(path);
|
|
189
|
+
return stats.size;
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
check(err);
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get file modification time
|
|
198
|
+
*/
|
|
199
|
+
mtime(path) {
|
|
200
|
+
try {
|
|
201
|
+
const stats = statSync(path);
|
|
202
|
+
return stats.mtime;
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
check(err);
|
|
206
|
+
throw err;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
export const file = new FileOps();
|
|
211
|
+
//# sourceMappingURL=file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,IAAI,GAAG,IAAI,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KEV - A Redis-style KV store for environment variables
|
|
3
|
+
*
|
|
4
|
+
* DEFAULT USAGE (no namespaces needed!):
|
|
5
|
+
* apiKey = KEV.mustGet("API_KEY") // Panics if not found (required config)
|
|
6
|
+
* apiKey = KEV.get("API_KEY") // Returns "" if not found
|
|
7
|
+
* apiKey = KEV.get("API_KEY", "dev") // Returns "dev" if not found
|
|
8
|
+
* port = KEV.int("PORT", 8080) // With type conversion
|
|
9
|
+
* KEV.set("DEBUG", "true") // Sets in memory (fast)
|
|
10
|
+
*
|
|
11
|
+
* KEV.get("DATABASE_URL") // memory → process.env → .env → cache result
|
|
12
|
+
* KEV.get("DATABASE_URL") // memory (cached!) ✓
|
|
13
|
+
*
|
|
14
|
+
* CUSTOMIZE THE SEARCH ORDER:
|
|
15
|
+
* KEV.source.remove("os") // Ignore OS env (perfect for tests!)
|
|
16
|
+
* KEV.source.add(".env.local") // Add more fallbacks
|
|
17
|
+
* KEV.source.set(".env.test") // Or replace entirely
|
|
18
|
+
*
|
|
19
|
+
* REDIS-STYLE NAMESPACING (when you need control):
|
|
20
|
+
* KEV.get("os:PATH") // ONLY from OS, no fallback
|
|
21
|
+
* KEV.get(".env:API_KEY") // ONLY from .env file
|
|
22
|
+
* KEV.set("os:DEBUG", "true") // Write directly to OS
|
|
23
|
+
* KEV.set(".env:API_KEY", "secret") // Update .env file
|
|
24
|
+
*
|
|
25
|
+
* // Pattern matching
|
|
26
|
+
* KEV.keys("API_*") // Find all API_ keys
|
|
27
|
+
* KEV.all("os:*") // Get all OS vars
|
|
28
|
+
* KEV.clear("TEMP_*") // Clean up temp vars
|
|
29
|
+
*
|
|
30
|
+
* SOURCE TRACKING & OBSERVABILITY:
|
|
31
|
+
* const [value, source] = KEV.getWithSource("API_KEY") // Returns value + where it came from
|
|
32
|
+
* source = KEV.sourceOf("API_KEY") // "/path/to/project/.env"
|
|
33
|
+
* KEV.debug = true // Shows lookup chain
|
|
34
|
+
* KEV.export("backup.env") // Includes # from: comments
|
|
35
|
+
*/
|
|
36
|
+
interface MemEntry {
|
|
37
|
+
value: string;
|
|
38
|
+
source: string;
|
|
39
|
+
}
|
|
40
|
+
declare class SourceOps {
|
|
41
|
+
private kev;
|
|
42
|
+
constructor(kev: KevOps);
|
|
43
|
+
/**
|
|
44
|
+
* Replace all sources
|
|
45
|
+
*/
|
|
46
|
+
set(...sources: string[]): void;
|
|
47
|
+
/**
|
|
48
|
+
* Add sources to the search list
|
|
49
|
+
*/
|
|
50
|
+
add(...sources: string[]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Remove specific sources
|
|
53
|
+
*/
|
|
54
|
+
remove(...sources: string[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* List current sources
|
|
57
|
+
*/
|
|
58
|
+
list(): string[];
|
|
59
|
+
/**
|
|
60
|
+
* Clear all sources
|
|
61
|
+
*/
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
64
|
+
export declare class KevOps {
|
|
65
|
+
memory: Map<string, MemEntry>;
|
|
66
|
+
sources: string[];
|
|
67
|
+
source: SourceOps;
|
|
68
|
+
debug: boolean;
|
|
69
|
+
constructor();
|
|
70
|
+
initializeSmartDefaults(): void;
|
|
71
|
+
parseKey(key: string): [string, string];
|
|
72
|
+
/**
|
|
73
|
+
* Get environment variable with optional default.
|
|
74
|
+
*/
|
|
75
|
+
get(key: string, defaultValue?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Get environment variable or panic if not found
|
|
78
|
+
*/
|
|
79
|
+
mustGet(key: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Get where a cached key came from
|
|
82
|
+
*/
|
|
83
|
+
sourceOf(key: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Get both value and its source
|
|
86
|
+
*/
|
|
87
|
+
getWithSource(key: string, defaultValue?: string): [string, string];
|
|
88
|
+
getFromNamespace(namespace: string, key: string): string;
|
|
89
|
+
getFromFile(filePath: string, key: string): string;
|
|
90
|
+
/**
|
|
91
|
+
* Set environment variable
|
|
92
|
+
*/
|
|
93
|
+
set(key: string, value: string): void;
|
|
94
|
+
setToNamespace(namespace: string, key: string, value: string): void;
|
|
95
|
+
setToFile(path: string, key: string, value: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Check if key exists
|
|
98
|
+
*/
|
|
99
|
+
has(key: string): boolean;
|
|
100
|
+
hasInNamespace(namespace: string, key: string): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Get all keys matching pattern
|
|
103
|
+
*/
|
|
104
|
+
keys(pattern?: string): string[];
|
|
105
|
+
keysFromNamespace(namespace: string, pattern: string): string[];
|
|
106
|
+
getNamespaceData(namespace: string, pattern: string, keysOnly: boolean): Record<string, string>;
|
|
107
|
+
parseEnvFile(path: string, pattern: string, result: Record<string, string>, keysOnly: boolean): void;
|
|
108
|
+
matchPattern(key: string, pattern: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Get all variables matching patterns
|
|
111
|
+
*/
|
|
112
|
+
all(pattern?: string | string[]): Record<string, Record<string, string>>;
|
|
113
|
+
getAllFromNamespace(namespace: string, pattern: string): Record<string, string>;
|
|
114
|
+
/**
|
|
115
|
+
* Clear variables from memory
|
|
116
|
+
*/
|
|
117
|
+
clear(...patterns: string[]): void;
|
|
118
|
+
/**
|
|
119
|
+
* Clear from namespaces (dangerous!)
|
|
120
|
+
*/
|
|
121
|
+
clearUnsafe(...patterns: string[]): void;
|
|
122
|
+
/**
|
|
123
|
+
* Remove specific keys
|
|
124
|
+
*/
|
|
125
|
+
unset(...keys: string[]): void;
|
|
126
|
+
/**
|
|
127
|
+
* Get as integer with default
|
|
128
|
+
*/
|
|
129
|
+
int(key: string, defaultValue: number): number;
|
|
130
|
+
/**
|
|
131
|
+
* Get as boolean with default
|
|
132
|
+
*/
|
|
133
|
+
bool(key: string, defaultValue: boolean): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Get as float with default
|
|
136
|
+
*/
|
|
137
|
+
float(key: string, defaultValue: number): number;
|
|
138
|
+
/**
|
|
139
|
+
* Export all memory variables to a file
|
|
140
|
+
*/
|
|
141
|
+
export(path: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Print all environment variables (masks sensitive keys)
|
|
144
|
+
*/
|
|
145
|
+
dump(): void;
|
|
146
|
+
}
|
|
147
|
+
export declare const kev: KevOps;
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=kev.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kev.d.ts","sourceRoot":"","sources":["../../src/platform/kev.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAQH,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,cAAM,SAAS;IACD,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,MAAM;IAE/B;;OAEG;IACH,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAI/B;;OAEG;IACH,GAAG,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAI/B;;OAEG;IACH,MAAM,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAIlC;;OAEG;IACH,IAAI,IAAI,MAAM,EAAE;IAIhB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED,qBAAa,MAAM;IACjB,MAAM,wBAA8B;IACpC,OAAO,EAAE,MAAM,EAAE,CAAiB;IAClC,MAAM,EAAE,SAAS,CAAA;IACjB,KAAK,UAAQ;;IAOb,uBAAuB,IAAI,IAAI;IAqC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAkBvC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,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