@kyvrixon/utils 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kyvrixon
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/README.md ADDED
@@ -0,0 +1 @@
1
+ General utility files I use for alot of projects! Does not include any larger scale items, just the little things
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./lib/Logger";
@@ -0,0 +1,104 @@
1
+ import { env } from "bun";
2
+ import chalk from "chalk";
3
+ const { cyan, yellow, red, magenta, dim, gray, bold } = chalk;
4
+ const formatter = new Intl.DateTimeFormat("en-AU", {
5
+ weekday: "short",
6
+ hour: "2-digit",
7
+ minute: "2-digit",
8
+ second: "2-digit",
9
+ hour12: false,
10
+ });
11
+ /**
12
+ * To enable debuging make the env variable `__DEBUG_MODE` equal to "1"
13
+ */
14
+ export class Logger {
15
+ colors = {
16
+ notif: cyan,
17
+ alert: yellow,
18
+ error: red,
19
+ debug: magenta,
20
+ };
21
+ logMethods = {
22
+ notif: "log",
23
+ alert: "warn",
24
+ error: "error",
25
+ debug: "debug",
26
+ };
27
+ getTimestamp() {
28
+ const now = new Date();
29
+ const ms = now.getMilliseconds().toString().padStart(3, "0");
30
+ const base = formatter.format(now).replace(",", " @");
31
+ return `${base}:${ms}`;
32
+ }
33
+ formatMessage(level, message) {
34
+ const timestamp = gray(`[${this.getTimestamp()}]`);
35
+ const levelLabel = bold(this.colors[level](level.toUpperCase().padEnd(5)));
36
+ const content = message instanceof Error
37
+ ? `${red(message.message)}\n${dim(this.sanitizeStack(message.stack || ""))}`
38
+ : message;
39
+ return `${timestamp} ${levelLabel} ${dim("»")} ${content}`;
40
+ }
41
+ sanitizeStack(stack) {
42
+ return stack
43
+ .split("\n")
44
+ .filter((line) => !line.includes("(native") && line.includes(":"))
45
+ .map((line, index) => {
46
+ if (index === 0)
47
+ return false;
48
+ return (line
49
+ .trim()
50
+ // .replace(/\\/g, "/")
51
+ // .replace(
52
+ // /(.*):(\d+):(\d+)/,
53
+ // (_, f, l, c) => `${dim(f)} ${bold(`(L${l} C${c})`)}`,
54
+ // )
55
+ .replace(/at\s+/, " └─ "));
56
+ })
57
+ .filter(Boolean)
58
+ .join("\n");
59
+ }
60
+ log(level, message, forceError) {
61
+ if (forceError)
62
+ return void console.error(message);
63
+ void console[this.logMethods[level]](this.formatMessage(level, message));
64
+ }
65
+ /**
66
+ * Pring a regular (info) message
67
+ *
68
+ * @param m Message to display
69
+ */
70
+ notif(m) {
71
+ this.log("notif", m);
72
+ }
73
+ /**
74
+ * Print an alert (warning)
75
+ *
76
+ * @param m Message to display
77
+ */
78
+ alert(m) {
79
+ this.log("alert", m);
80
+ }
81
+ /**
82
+ * Print an error
83
+ *
84
+ * @param m Message to display
85
+ * @param e Error (optional)
86
+ * @param f Force error - directly calls `console.error()`
87
+ */
88
+ error(m, e, f) {
89
+ this.log("error", e ?? m, f);
90
+ }
91
+ /**
92
+ * Print a debug message
93
+ *
94
+ * @param m Message to display
95
+ */
96
+ debug(m) {
97
+ if ("__DEBUG_MODE" in env && env.__DEBUG_MODE === "1")
98
+ this.log("debug", m);
99
+ }
100
+ divider(text) {
101
+ const line = dim("─".repeat(Math.max(0, (50 - text.length - 2) / 2)));
102
+ console.log(`\n${line} ${bold(text.trim())} ${line}`);
103
+ }
104
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./lib/Logger";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * To enable debuging make the env variable `__DEBUG_MODE` equal to "1"
3
+ */
4
+ export declare class Logger {
5
+ private readonly colors;
6
+ private readonly logMethods;
7
+ private getTimestamp;
8
+ private formatMessage;
9
+ private sanitizeStack;
10
+ private log;
11
+ /**
12
+ * Pring a regular (info) message
13
+ *
14
+ * @param m Message to display
15
+ */
16
+ notif(m: unknown): void;
17
+ /**
18
+ * Print an alert (warning)
19
+ *
20
+ * @param m Message to display
21
+ */
22
+ alert(m: unknown): void;
23
+ /**
24
+ * Print an error
25
+ *
26
+ * @param m Message to display
27
+ * @param e Error (optional)
28
+ * @param f Force error - directly calls `console.error()`
29
+ */
30
+ error(m: unknown, e?: Error, f?: boolean): void;
31
+ /**
32
+ * Print a debug message
33
+ *
34
+ * @param m Message to display
35
+ */
36
+ debug(m: unknown): void;
37
+ divider(text: string): void;
38
+ }
39
+ //# sourceMappingURL=Logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../../lib/Logger.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,qBAAa,MAAM;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAKrB;IAEF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAQzB;IAEF,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,aAAa;IAqBrB,OAAO,CAAC,GAAG;IAOX;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,OAAO;IAIvB;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,OAAO;IAIvB;;;;;;OAMG;IACI,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO;IAI/C;;;;OAIG;IACI,KAAK,CAAC,CAAC,EAAE,OAAO;IAIhB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAIlC"}
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@kyvrixon/utils",
3
+ "module": "index.js",
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "private": false,
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "packageManager": "bun@1.3.6",
11
+ "devDependencies": {
12
+ "@types/bun": "1.3.6"
13
+ },
14
+ "peerDependencies": {
15
+ "typescript": "^5.9.3"
16
+ },
17
+ "dependencies": {
18
+ "chalk": "^5.6.2"
19
+ }
20
+ }