halua 0.0.5 → 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/package.json CHANGED
@@ -1,24 +1,25 @@
1
1
  {
2
2
  "name": "halua",
3
- "version": "0.0.5",
4
- "description": "logger for JS",
3
+ "version": "1.0.0",
4
+ "description": "Package that takes control of logging, metrics and other stuff",
5
+ "type": "module",
5
6
  "main": "lib/index.js",
6
7
  "module": "lib/index.mjs",
7
8
  "types": "lib/index.d.ts",
8
- "files": ["lib"],
9
- "scripts": {
10
- "test": "jest --config --passWithNoTests jest.config.ts",
11
- "build": "tsup",
12
- "prepare": "yarn build",
13
- "postversion": "git push && git push --tags"
14
- },
9
+ "files": [
10
+ "lib"
11
+ ],
15
12
  "repository": {
16
13
  "type": "git",
17
14
  "url": "git+https://github.com/inshinrei/halua.git"
18
15
  },
19
16
  "keywords": [
20
17
  "logger",
21
- "logging"
18
+ "logging",
19
+ "node",
20
+ "console",
21
+ "web",
22
+ "json logs"
22
23
  ],
23
24
  "author": "inshinrei",
24
25
  "license": "MIT",
@@ -27,13 +28,20 @@
27
28
  },
28
29
  "homepage": "https://github.com/inshinrei/halua#readme",
29
30
  "devDependencies": {
30
- "jest": "^30.0.2",
31
- "ts-jest": "^29.4.0",
31
+ "prettier": "^3.6.1",
32
+ "tinybench": "^5.0.0",
32
33
  "ts-node": "^10.9.2",
33
34
  "tsup": "^8.5.0",
34
- "typescript": "^5.8.3"
35
+ "typescript": "^5.8.3",
36
+ "vitest": "^3.2.4"
35
37
  },
36
38
  "publishConfig": {
37
39
  "access": "public"
40
+ },
41
+ "scripts": {
42
+ "test": "vitest",
43
+ "bench": "node benchmarks/main_bench.js",
44
+ "build": "tsup",
45
+ "postversion": "git push && git push --tags"
38
46
  }
39
- }
47
+ }
package/lib/index.d.mts DELETED
@@ -1,56 +0,0 @@
1
- interface Handler {
2
- debug: (msg: string) => void;
3
- info: (msg: string) => void;
4
- warn: (msg: string) => void;
5
- error: (msg: string) => void;
6
- }
7
- type LoggerFn = (msg: string, ...args: any[]) => void;
8
- interface Logger {
9
- debug: LoggerFn;
10
- info: LoggerFn;
11
- warn: LoggerFn;
12
- err: LoggerFn;
13
- assert: (value: boolean, msg: string, ...args: any[]) => void;
14
- setHandler: (handler: Handler) => void;
15
- setDateGetter: (getter: (() => string | number)) => void;
16
- }
17
- interface LoggerOptions {
18
- minLevel?: Level;
19
- postfix?: string;
20
- dateGetter?: (() => string | number) | null | undefined;
21
- }
22
- declare enum Level {
23
- Debug = "DEBUG",
24
- Info = "INFO",
25
- Warn = "WARN",
26
- Error = "ERR"
27
- }
28
-
29
- declare class LoggerCore implements Logger {
30
- private handler;
31
- private dateGetter;
32
- private readonly options;
33
- private readonly levelMapping;
34
- constructor(handler?: Handler | null | undefined, options?: LoggerOptions);
35
- New(handler?: Handler, options?: LoggerOptions): Logger;
36
- With(msg: string, ...args: any[]): Logger;
37
- debug(msg: string, ...args: any[]): void;
38
- info(msg: string, ...args: any[]): void;
39
- warn(msg: string, ...args: any[]): void;
40
- err(msg: string, ...args: any[]): void;
41
- assert(value: boolean, msg: string, ...args: any[]): void;
42
- setHandler(handler: Handler): void;
43
- setDateGetter(getter: () => string | number): void;
44
- private log;
45
- private composeMsgWithArgs;
46
- private formatWithLevel;
47
- private formatWithDate;
48
- private shiftValue;
49
- private appendValue;
50
- private getDateInLocaleString;
51
- private canLogByMinLevelRestriction;
52
- }
53
-
54
- declare const halua: LoggerCore;
55
-
56
- export { type Handler, Level, halua };
package/lib/index.mjs DELETED
@@ -1,149 +0,0 @@
1
- // types.ts
2
- var Level = /* @__PURE__ */ ((Level2) => {
3
- Level2["Debug"] = "DEBUG";
4
- Level2["Info"] = "INFO";
5
- Level2["Warn"] = "WARN";
6
- Level2["Error"] = "ERR";
7
- return Level2;
8
- })(Level || {});
9
-
10
- // loggerCore.ts
11
- var LoggerCore = class _LoggerCore {
12
- handler = self?.console || window?.console;
13
- dateGetter = null;
14
- options = {};
15
- levelMapping = /* @__PURE__ */ new Map([
16
- ["debug", "DEBUG" /* Debug */],
17
- ["info", "INFO" /* Info */],
18
- ["warn", "WARN" /* Warn */],
19
- ["error", "ERR" /* Error */]
20
- ]);
21
- constructor(handler, options = {}) {
22
- if (handler) {
23
- this.handler = handler;
24
- }
25
- if (options.dateGetter) {
26
- this.dateGetter = options.dateGetter;
27
- delete options.dateGetter;
28
- }
29
- this.options = {
30
- ...this.options,
31
- ...options
32
- };
33
- }
34
- New(handler = this.handler, options = this.options) {
35
- return new _LoggerCore(handler, options);
36
- }
37
- With(msg, ...args) {
38
- let postfix = this.options.postfix ? `${this.options.postfix} ${this.composeMsgWithArgs(msg, ...args)}` : this.composeMsgWithArgs(msg, ...args);
39
- return new _LoggerCore(this.handler, {
40
- postfix,
41
- dateGetter: this.dateGetter,
42
- minLevel: this.options.minLevel
43
- });
44
- }
45
- debug(msg, ...args) {
46
- if (this.canLogByMinLevelRestriction("DEBUG" /* Debug */)) {
47
- this.log("debug", msg, ...args);
48
- }
49
- }
50
- info(msg, ...args) {
51
- if (this.canLogByMinLevelRestriction("INFO" /* Info */)) {
52
- this.log("info", msg, ...args);
53
- }
54
- }
55
- warn(msg, ...args) {
56
- if (this.canLogByMinLevelRestriction("WARN" /* Warn */)) {
57
- this.log("warn", msg, ...args);
58
- }
59
- }
60
- err(msg, ...args) {
61
- this.log("error", msg, ...args);
62
- }
63
- assert(value, msg, ...args) {
64
- if (!value) {
65
- this.log("error", `assertion failed: ${msg}`, ...args);
66
- }
67
- }
68
- setHandler(handler) {
69
- this.handler = handler;
70
- }
71
- setDateGetter(getter) {
72
- this.dateGetter = getter;
73
- }
74
- log(to, msg, ...args) {
75
- let value = msg;
76
- value = this.composeMsgWithArgs(value, ...args);
77
- if (this.options.postfix) {
78
- value = this.appendValue(this.options.postfix, value);
79
- }
80
- let level = this.levelMapping.get(to);
81
- value = this.formatWithDate(this.formatWithLevel(level, value));
82
- this.handler[to](value);
83
- }
84
- composeMsgWithArgs(msg, ...args) {
85
- if (args.length === 1) {
86
- return this.appendValue(args[0], msg);
87
- }
88
- let totalMsg = msg;
89
- let key = "";
90
- for (let arg of args) {
91
- if (!key) {
92
- key = arg;
93
- continue;
94
- }
95
- totalMsg = this.appendValue(`${key}="${arg}"`, totalMsg);
96
- key = "";
97
- }
98
- if (key) {
99
- totalMsg = this.appendValue(`${key}=${void 0}`, totalMsg);
100
- }
101
- return totalMsg;
102
- }
103
- formatWithLevel(level, msg) {
104
- return this.shiftValue(level, msg);
105
- }
106
- formatWithDate(msg) {
107
- if (this.dateGetter) {
108
- try {
109
- return this.shiftValue(this.dateGetter().toString(), msg);
110
- } catch (_) {
111
- this.err("date getter catches an error, check your date getter func");
112
- }
113
- }
114
- return this.shiftValue(this.getDateInLocaleString(), msg);
115
- }
116
- shiftValue(value, to) {
117
- return `${value} ${to}`;
118
- }
119
- appendValue(value, to) {
120
- return `${to} ${value}`;
121
- }
122
- getDateInLocaleString() {
123
- let d = /* @__PURE__ */ new Date();
124
- return `${d.toLocaleDateString()} ${d.toLocaleTimeString()}`;
125
- }
126
- canLogByMinLevelRestriction(level) {
127
- const { minLevel } = this.options;
128
- if (!minLevel || level === "ERR" /* Error */) {
129
- return true;
130
- }
131
- if (level === "WARN" /* Warn */) {
132
- return minLevel !== "ERR" /* Error */;
133
- }
134
- if (level === "INFO" /* Info */) {
135
- return minLevel !== "WARN" /* Warn */ && minLevel !== "ERR" /* Error */;
136
- }
137
- if (level === "DEBUG" /* Debug */) {
138
- return minLevel === "DEBUG" /* Debug */;
139
- }
140
- return true;
141
- }
142
- };
143
-
144
- // index.ts
145
- var halua = new LoggerCore();
146
- export {
147
- Level,
148
- halua
149
- };