zario 0.3.5 → 0.3.6

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.
@@ -1,47 +1,49 @@
1
1
  import { LogData } from '../types/index.js';
2
+ import { LogLevel } from '../core/LogLevel.js';
2
3
  export interface Filter {
3
- /**
4
- * Determines if a log record should be emitted
5
- * @param logData The structured log record
6
- * @returns true if the log should be emitted, false if it should be filtered out
7
- */
8
4
  shouldEmit(logData: LogData): boolean;
9
5
  }
10
6
  export type FilterPredicate = (logData: LogData) => boolean;
11
- /**
12
- * A filter that combines multiple filters with AND logic
13
- * Note: With an empty array of filters, this returns true (allows all logs).
14
- * This follows the mathematical concept of vacuous truth - "all" conditions
15
- * are satisfied when there are no conditions to check.
16
- */
17
7
  export declare class CompositeFilter implements Filter {
18
8
  private filters;
19
9
  constructor(filters: Filter[]);
20
10
  shouldEmit(logData: LogData): boolean;
21
11
  }
22
- /**
23
- * A filter that combines multiple filters with OR logic
24
- * Note: With an empty array of filters, this returns false (blocks all logs).
25
- * This is because there are no matching conditions when the filter array is empty.
26
- */
27
12
  export declare class OrFilter implements Filter {
28
13
  private filters;
29
14
  constructor(filters: Filter[]);
30
15
  shouldEmit(logData: LogData): boolean;
31
16
  }
32
- /**
33
- * A filter that negates another filter
34
- */
35
17
  export declare class NotFilter implements Filter {
36
18
  private filter;
37
19
  constructor(filter: Filter);
38
20
  shouldEmit(logData: LogData): boolean;
39
21
  }
40
- /**
41
- * A filter based on a predicate function
42
- */
43
22
  export declare class PredicateFilter implements Filter {
44
23
  private predicate;
45
24
  constructor(predicate: FilterPredicate);
46
25
  shouldEmit(logData: LogData): boolean;
47
26
  }
27
+ export declare class LevelFilter implements Filter {
28
+ private allowedLevels;
29
+ constructor(allowedLevels: LogLevel[]);
30
+ shouldEmit(logData: LogData): boolean;
31
+ }
32
+ export declare class PrefixFilter implements Filter {
33
+ private allowedPrefixes;
34
+ constructor(allowedPrefixes: string[]);
35
+ shouldEmit(logData: LogData): boolean;
36
+ }
37
+ export declare class MetadataFilter implements Filter {
38
+ private requiredMetadata;
39
+ constructor(requiredMetadata: {
40
+ [key: string]: any;
41
+ });
42
+ shouldEmit(logData: LogData): boolean;
43
+ }
44
+ export declare class FieldFilter implements Filter {
45
+ private fieldName;
46
+ private expectedValue;
47
+ constructor(fieldName: string, expectedValue: any);
48
+ shouldEmit(logData: LogData): boolean;
49
+ }
@@ -1,9 +1,3 @@
1
- /**
2
- * A filter that combines multiple filters with AND logic
3
- * Note: With an empty array of filters, this returns true (allows all logs).
4
- * This follows the mathematical concept of vacuous truth - "all" conditions
5
- * are satisfied when there are no conditions to check.
6
- */
7
1
  export class CompositeFilter {
8
2
  constructor(filters) {
9
3
  this.filters = filters;
@@ -12,11 +6,6 @@ export class CompositeFilter {
12
6
  return this.filters.every(filter => filter.shouldEmit(logData));
13
7
  }
14
8
  }
15
- /**
16
- * A filter that combines multiple filters with OR logic
17
- * Note: With an empty array of filters, this returns false (blocks all logs).
18
- * This is because there are no matching conditions when the filter array is empty.
19
- */
20
9
  export class OrFilter {
21
10
  constructor(filters) {
22
11
  this.filters = filters;
@@ -25,9 +14,6 @@ export class OrFilter {
25
14
  return this.filters.some(filter => filter.shouldEmit(logData));
26
15
  }
27
16
  }
28
- /**
29
- * A filter that negates another filter
30
- */
31
17
  export class NotFilter {
32
18
  constructor(filter) {
33
19
  this.filter = filter;
@@ -36,9 +22,6 @@ export class NotFilter {
36
22
  return !this.filter.shouldEmit(logData);
37
23
  }
38
24
  }
39
- /**
40
- * A filter based on a predicate function
41
- */
42
25
  export class PredicateFilter {
43
26
  constructor(predicate) {
44
27
  this.predicate = predicate;
@@ -47,3 +30,50 @@ export class PredicateFilter {
47
30
  return this.predicate(logData);
48
31
  }
49
32
  }
33
+ export class LevelFilter {
34
+ constructor(allowedLevels) {
35
+ this.allowedLevels = new Set(allowedLevels);
36
+ }
37
+ shouldEmit(logData) {
38
+ return this.allowedLevels.has(logData.level);
39
+ }
40
+ }
41
+ export class PrefixFilter {
42
+ constructor(allowedPrefixes) {
43
+ this.allowedPrefixes = new Set(allowedPrefixes);
44
+ }
45
+ shouldEmit(logData) {
46
+ if (!logData.prefix) {
47
+ return this.allowedPrefixes.has('');
48
+ }
49
+ return this.allowedPrefixes.has(logData.prefix);
50
+ }
51
+ }
52
+ export class MetadataFilter {
53
+ constructor(requiredMetadata) {
54
+ this.requiredMetadata = requiredMetadata;
55
+ }
56
+ shouldEmit(logData) {
57
+ if (!logData.metadata) {
58
+ return Object.keys(this.requiredMetadata).length === 0;
59
+ }
60
+ for (const [key, value] of Object.entries(this.requiredMetadata)) {
61
+ if (logData.metadata[key] !== value) {
62
+ return false;
63
+ }
64
+ }
65
+ return true;
66
+ }
67
+ }
68
+ export class FieldFilter {
69
+ constructor(fieldName, expectedValue) {
70
+ this.fieldName = fieldName;
71
+ this.expectedValue = expectedValue;
72
+ }
73
+ shouldEmit(logData) {
74
+ if (!logData.metadata) {
75
+ return false;
76
+ }
77
+ return logData.metadata[this.fieldName] === this.expectedValue;
78
+ }
79
+ }
@@ -1,2 +1 @@
1
1
  export * from './Filter.js';
2
- export * from './SpecificFilters.js';
@@ -1,2 +1 @@
1
1
  export * from './Filter.js';
2
- export * from './SpecificFilters.js';
@@ -6,6 +6,7 @@ import { CustomLogLevelConfig } from './core/CustomLogLevel.js';
6
6
  import { Filter, CompositeFilter, OrFilter, NotFilter, PredicateFilter, LevelFilter, PrefixFilter, MetadataFilter, FieldFilter } from './filters/index.js';
7
7
  import { LogAggregator, BatchAggregator, TimeBasedAggregator, CompositeAggregator } from './aggregation/index.js';
8
8
  import { LogEnricher, MetadataEnricher, LogEnrichmentPipeline } from './structured/index.js';
9
- export { Logger, ConsoleTransport, FileTransport, HttpTransport, FilterableTransport, CompositeFilter, OrFilter, NotFilter, PredicateFilter, LevelFilter, PrefixFilter, MetadataFilter, FieldFilter, BatchAggregator, TimeBasedAggregator, CompositeAggregator, MetadataEnricher, LogEnrichmentPipeline };
9
+ import { Timer } from './utils/index.js';
10
+ export { Logger, ConsoleTransport, FileTransport, HttpTransport, FilterableTransport, CompositeFilter, OrFilter, NotFilter, PredicateFilter, LevelFilter, PrefixFilter, MetadataFilter, FieldFilter, BatchAggregator, TimeBasedAggregator, CompositeAggregator, MetadataEnricher, LogEnrichmentPipeline, Timer };
10
11
  export type { LogLevel, Transport, TransportConfig, LoggerConfig, CustomLogLevelConfig, Filter, LogAggregator, LogEnricher };
11
12
  export default Logger;
package/dist/esm/index.js CHANGED
@@ -3,6 +3,7 @@ import { ConsoleTransport, FileTransport, HttpTransport, FilterableTransport } f
3
3
  import { CompositeFilter, OrFilter, NotFilter, PredicateFilter, LevelFilter, PrefixFilter, MetadataFilter, FieldFilter } from './filters/index.js';
4
4
  import { BatchAggregator, TimeBasedAggregator, CompositeAggregator } from './aggregation/index.js';
5
5
  import { MetadataEnricher, LogEnrichmentPipeline } from './structured/index.js';
6
+ import { Timer } from './utils/index.js';
6
7
  // Configure default transports to maintain backward compatibility
7
8
  Logger.defaultTransportsFactory = (isProd) => {
8
9
  if (isProd) {
@@ -18,5 +19,7 @@ CompositeFilter, OrFilter, NotFilter, PredicateFilter, LevelFilter, PrefixFilter
18
19
  // Aggregators
19
20
  BatchAggregator, TimeBasedAggregator, CompositeAggregator,
20
21
  // Structured logging extensions
21
- MetadataEnricher, LogEnrichmentPipeline };
22
+ MetadataEnricher, LogEnrichmentPipeline,
23
+ // Utils
24
+ Timer };
22
25
  export default Logger;
@@ -0,0 +1,15 @@
1
+ export declare class ColorUtil {
2
+ private static readonly ANSI_COLORS;
3
+ static colorize(text: string, color: string): string;
4
+ }
5
+ export declare class TimeUtil {
6
+ static format(date: Date, format: string): string;
7
+ }
8
+ export declare class Timer {
9
+ private startTime;
10
+ private name;
11
+ private logFn;
12
+ private hasEnded;
13
+ constructor(name: string, logFn: (message: string) => void);
14
+ end(): void;
15
+ }
@@ -0,0 +1,72 @@
1
+ export class ColorUtil {
2
+ static colorize(text, color) {
3
+ const supportsColor = process.env.FORCE_COLOR !== "0" &&
4
+ (process.stdout.isTTY || process.env.FORCE_COLOR === "1");
5
+ if (!supportsColor) {
6
+ return text;
7
+ }
8
+ const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
9
+ return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
10
+ }
11
+ }
12
+ ColorUtil.ANSI_COLORS = {
13
+ black: "\x1b[30m",
14
+ red: "\x1b[31m",
15
+ green: "\x1b[32m",
16
+ yellow: "\x1b[33m",
17
+ blue: "\x1b[34m",
18
+ magenta: "\x1b[35m",
19
+ cyan: "\x1b[36m",
20
+ white: "\x1b[37m",
21
+ brightRed: "\x1b[91m",
22
+ brightGreen: "\x1b[92m",
23
+ brightYellow: "\x1b[93m",
24
+ brightBlue: "\x1b[94m",
25
+ brightMagenta: "\x1b[95m",
26
+ brightCyan: "\x1b[96m",
27
+ brightWhite: "\x1b[97m",
28
+ info: "\x1b[32m",
29
+ warn: "\x1b[33m",
30
+ error: "\x1b[31m",
31
+ debug: "\x1b[36m",
32
+ boring: "\x1b[37m",
33
+ reset: "\x1b[0m",
34
+ };
35
+ export class TimeUtil {
36
+ static format(date, format) {
37
+ if (format === "ISO")
38
+ return date.toISOString();
39
+ if (format === "UTC")
40
+ return date.toUTCString();
41
+ if (format === "LOCAL")
42
+ return date.toLocaleString();
43
+ const pad = (n, width = 2) => n.toString().padStart(width, "0");
44
+ const tokens = {
45
+ YYYY: pad(date.getFullYear(), 4),
46
+ MM: pad(date.getMonth() + 1),
47
+ DD: pad(date.getDate()),
48
+ HH: pad(date.getHours()),
49
+ mm: pad(date.getMinutes()),
50
+ ss: pad(date.getSeconds()),
51
+ SSS: pad(date.getMilliseconds(), 3),
52
+ };
53
+ return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
54
+ }
55
+ }
56
+ export class Timer {
57
+ constructor(name, logFn) {
58
+ this.hasEnded = false;
59
+ this.name = name;
60
+ this.logFn = logFn;
61
+ this.startTime = Date.now();
62
+ }
63
+ end() {
64
+ if (this.hasEnded) {
65
+ return;
66
+ }
67
+ const endTime = Date.now();
68
+ const duration = endTime - this.startTime;
69
+ this.logFn(`${this.name} took ${duration}ms`);
70
+ this.hasEnded = true;
71
+ }
72
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zario",
3
- "version": "0.3.5",
4
- "description": "A minimal, fast logging library for Node.js.",
3
+ "version": "0.3.6",
4
+ "description": "just a minimal, fast, and feature-rich logging library for Node.js.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
7
7
  "types": "./dist/esm/index.d.ts",
@@ -39,7 +39,8 @@
39
39
  "logger",
40
40
  "console",
41
41
  "terminal",
42
- "typescript"
42
+ "typescript",
43
+ "nodejs"
43
44
  ],
44
45
  "author": "Dev-dami",
45
46
  "license": "MIT",
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FieldFilter = exports.MetadataFilter = exports.PrefixFilter = exports.LevelFilter = void 0;
4
- /**
5
- * A filter that allows logs based on their log level
6
- */
7
- class LevelFilter {
8
- constructor(allowedLevels) {
9
- this.allowedLevels = new Set(allowedLevels);
10
- }
11
- shouldEmit(logData) {
12
- return this.allowedLevels.has(logData.level);
13
- }
14
- }
15
- exports.LevelFilter = LevelFilter;
16
- /**
17
- * A filter that allows logs based on their prefix/namespace
18
- */
19
- class PrefixFilter {
20
- constructor(allowedPrefixes) {
21
- this.allowedPrefixes = new Set(allowedPrefixes);
22
- }
23
- shouldEmit(logData) {
24
- if (!logData.prefix) {
25
- // If no prefix exists, only allow if empty string is in allowed prefixes
26
- return this.allowedPrefixes.has('');
27
- }
28
- return this.allowedPrefixes.has(logData.prefix);
29
- }
30
- }
31
- exports.PrefixFilter = PrefixFilter;
32
- /**
33
- * A filter that allows logs based on specific metadata fields
34
- * Note: Uses strict equality (===) for comparison, which means objects and arrays
35
- * will only match if they are the same reference. For deep comparison of complex
36
- * values, consider implementing a custom filter.
37
- */
38
- class MetadataFilter {
39
- constructor(requiredMetadata) {
40
- this.requiredMetadata = requiredMetadata;
41
- }
42
- shouldEmit(logData) {
43
- if (!logData.metadata) {
44
- // If no metadata exists but we require some, return false
45
- return Object.keys(this.requiredMetadata).length === 0;
46
- }
47
- for (const [key, value] of Object.entries(this.requiredMetadata)) {
48
- if (logData.metadata[key] !== value) {
49
- return false;
50
- }
51
- }
52
- return true;
53
- }
54
- }
55
- exports.MetadataFilter = MetadataFilter;
56
- /**
57
- * A filter that allows logs based on a custom field in metadata
58
- */
59
- class FieldFilter {
60
- constructor(fieldName, expectedValue) {
61
- this.fieldName = fieldName;
62
- this.expectedValue = expectedValue;
63
- }
64
- shouldEmit(logData) {
65
- if (!logData.metadata) {
66
- return false;
67
- }
68
- return logData.metadata[this.fieldName] === this.expectedValue;
69
- }
70
- }
71
- exports.FieldFilter = FieldFilter;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ColorUtil = void 0;
4
- class ColorUtil {
5
- static colorize(text, color) {
6
- const supportsColor = process.env.FORCE_COLOR !== "0" &&
7
- (process.stdout.isTTY || process.env.FORCE_COLOR === "1");
8
- if (!supportsColor) {
9
- return text;
10
- }
11
- const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
12
- return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
13
- }
14
- }
15
- exports.ColorUtil = ColorUtil;
16
- // ANSI color codes
17
- ColorUtil.ANSI_COLORS = {
18
- // Standard colors
19
- black: "\x1b[30m",
20
- red: "\x1b[31m",
21
- green: "\x1b[32m",
22
- yellow: "\x1b[33m",
23
- blue: "\x1b[34m",
24
- magenta: "\x1b[35m",
25
- cyan: "\x1b[36m",
26
- white: "\x1b[37m",
27
- // Bright colors
28
- brightRed: "\x1b[91m",
29
- brightGreen: "\x1b[92m",
30
- brightYellow: "\x1b[93m",
31
- brightBlue: "\x1b[94m",
32
- brightMagenta: "\x1b[95m",
33
- brightCyan: "\x1b[96m",
34
- brightWhite: "\x1b[97m",
35
- // Default log level colors
36
- info: "\x1b[32m",
37
- warn: "\x1b[33m",
38
- error: "\x1b[31m",
39
- debug: "\x1b[36m",
40
- boring: "\x1b[37m",
41
- reset: "\x1b[0m",
42
- };
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeUtil = void 0;
4
- class TimeUtil {
5
- // util class for date formating
6
- static format(date, format) {
7
- if (format === "ISO")
8
- return date.toISOString();
9
- if (format === "UTC")
10
- return date.toUTCString();
11
- if (format === "LOCAL")
12
- return date.toLocaleString();
13
- const pad = (n, width = 2) => n.toString().padStart(width, "0");
14
- const tokens = {
15
- YYYY: pad(date.getFullYear(), 4),
16
- MM: pad(date.getMonth() + 1),
17
- DD: pad(date.getDate()),
18
- HH: pad(date.getHours()),
19
- mm: pad(date.getMinutes()),
20
- ss: pad(date.getSeconds()),
21
- SSS: pad(date.getMilliseconds(), 3),
22
- };
23
- return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
24
- }
25
- }
26
- exports.TimeUtil = TimeUtil;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Timer = void 0;
4
- class Timer {
5
- constructor(name, logFn) {
6
- this.hasEnded = false;
7
- this.name = name;
8
- this.logFn = logFn;
9
- this.startTime = Date.now();
10
- }
11
- end() {
12
- // If already ended, do nothing (idempotent)
13
- if (this.hasEnded) {
14
- return;
15
- }
16
- const endTime = Date.now();
17
- const duration = endTime - this.startTime;
18
- this.logFn(`${this.name} took ${duration}ms`);
19
- this.hasEnded = true;
20
- }
21
- }
22
- exports.Timer = Timer;
@@ -1,41 +0,0 @@
1
- import { LogData } from '../types/index.js';
2
- import { LogLevel } from '../core/LogLevel.js';
3
- import { Filter } from './Filter.js';
4
- /**
5
- * A filter that allows logs based on their log level
6
- */
7
- export declare class LevelFilter implements Filter {
8
- private allowedLevels;
9
- constructor(allowedLevels: LogLevel[]);
10
- shouldEmit(logData: LogData): boolean;
11
- }
12
- /**
13
- * A filter that allows logs based on their prefix/namespace
14
- */
15
- export declare class PrefixFilter implements Filter {
16
- private allowedPrefixes;
17
- constructor(allowedPrefixes: string[]);
18
- shouldEmit(logData: LogData): boolean;
19
- }
20
- /**
21
- * A filter that allows logs based on specific metadata fields
22
- * Note: Uses strict equality (===) for comparison, which means objects and arrays
23
- * will only match if they are the same reference. For deep comparison of complex
24
- * values, consider implementing a custom filter.
25
- */
26
- export declare class MetadataFilter implements Filter {
27
- private requiredMetadata;
28
- constructor(requiredMetadata: {
29
- [key: string]: any;
30
- });
31
- shouldEmit(logData: LogData): boolean;
32
- }
33
- /**
34
- * A filter that allows logs based on a custom field in metadata
35
- */
36
- export declare class FieldFilter implements Filter {
37
- private fieldName;
38
- private expectedValue;
39
- constructor(fieldName: string, expectedValue: any);
40
- shouldEmit(logData: LogData): boolean;
41
- }
@@ -1,64 +0,0 @@
1
- /**
2
- * A filter that allows logs based on their log level
3
- */
4
- export class LevelFilter {
5
- constructor(allowedLevels) {
6
- this.allowedLevels = new Set(allowedLevels);
7
- }
8
- shouldEmit(logData) {
9
- return this.allowedLevels.has(logData.level);
10
- }
11
- }
12
- /**
13
- * A filter that allows logs based on their prefix/namespace
14
- */
15
- export class PrefixFilter {
16
- constructor(allowedPrefixes) {
17
- this.allowedPrefixes = new Set(allowedPrefixes);
18
- }
19
- shouldEmit(logData) {
20
- if (!logData.prefix) {
21
- // If no prefix exists, only allow if empty string is in allowed prefixes
22
- return this.allowedPrefixes.has('');
23
- }
24
- return this.allowedPrefixes.has(logData.prefix);
25
- }
26
- }
27
- /**
28
- * A filter that allows logs based on specific metadata fields
29
- * Note: Uses strict equality (===) for comparison, which means objects and arrays
30
- * will only match if they are the same reference. For deep comparison of complex
31
- * values, consider implementing a custom filter.
32
- */
33
- export class MetadataFilter {
34
- constructor(requiredMetadata) {
35
- this.requiredMetadata = requiredMetadata;
36
- }
37
- shouldEmit(logData) {
38
- if (!logData.metadata) {
39
- // If no metadata exists but we require some, return false
40
- return Object.keys(this.requiredMetadata).length === 0;
41
- }
42
- for (const [key, value] of Object.entries(this.requiredMetadata)) {
43
- if (logData.metadata[key] !== value) {
44
- return false;
45
- }
46
- }
47
- return true;
48
- }
49
- }
50
- /**
51
- * A filter that allows logs based on a custom field in metadata
52
- */
53
- export class FieldFilter {
54
- constructor(fieldName, expectedValue) {
55
- this.fieldName = fieldName;
56
- this.expectedValue = expectedValue;
57
- }
58
- shouldEmit(logData) {
59
- if (!logData.metadata) {
60
- return false;
61
- }
62
- return logData.metadata[this.fieldName] === this.expectedValue;
63
- }
64
- }
@@ -1,4 +0,0 @@
1
- export declare class ColorUtil {
2
- private static readonly ANSI_COLORS;
3
- static colorize(text: string, color: string): string;
4
- }
@@ -1,38 +0,0 @@
1
- export class ColorUtil {
2
- static colorize(text, color) {
3
- const supportsColor = process.env.FORCE_COLOR !== "0" &&
4
- (process.stdout.isTTY || process.env.FORCE_COLOR === "1");
5
- if (!supportsColor) {
6
- return text;
7
- }
8
- const colorCode = ColorUtil.ANSI_COLORS[color] || ColorUtil.ANSI_COLORS.reset;
9
- return `${colorCode}${text}${ColorUtil.ANSI_COLORS.reset}`;
10
- }
11
- }
12
- // ANSI color codes
13
- ColorUtil.ANSI_COLORS = {
14
- // Standard colors
15
- black: "\x1b[30m",
16
- red: "\x1b[31m",
17
- green: "\x1b[32m",
18
- yellow: "\x1b[33m",
19
- blue: "\x1b[34m",
20
- magenta: "\x1b[35m",
21
- cyan: "\x1b[36m",
22
- white: "\x1b[37m",
23
- // Bright colors
24
- brightRed: "\x1b[91m",
25
- brightGreen: "\x1b[92m",
26
- brightYellow: "\x1b[93m",
27
- brightBlue: "\x1b[94m",
28
- brightMagenta: "\x1b[95m",
29
- brightCyan: "\x1b[96m",
30
- brightWhite: "\x1b[97m",
31
- // Default log level colors
32
- info: "\x1b[32m",
33
- warn: "\x1b[33m",
34
- error: "\x1b[31m",
35
- debug: "\x1b[36m",
36
- boring: "\x1b[37m",
37
- reset: "\x1b[0m",
38
- };
@@ -1,3 +0,0 @@
1
- export declare class TimeUtil {
2
- static format(date: Date, format: string): string;
3
- }
@@ -1,22 +0,0 @@
1
- export class TimeUtil {
2
- // util class for date formating
3
- static format(date, format) {
4
- if (format === "ISO")
5
- return date.toISOString();
6
- if (format === "UTC")
7
- return date.toUTCString();
8
- if (format === "LOCAL")
9
- return date.toLocaleString();
10
- const pad = (n, width = 2) => n.toString().padStart(width, "0");
11
- const tokens = {
12
- YYYY: pad(date.getFullYear(), 4),
13
- MM: pad(date.getMonth() + 1),
14
- DD: pad(date.getDate()),
15
- HH: pad(date.getHours()),
16
- mm: pad(date.getMinutes()),
17
- ss: pad(date.getSeconds()),
18
- SSS: pad(date.getMilliseconds(), 3),
19
- };
20
- return format.replace(/YYYY|MM|DD|HH|mm|ss|SSS/g, (match) => tokens[match] || match);
21
- }
22
- }
@@ -1,8 +0,0 @@
1
- export declare class Timer {
2
- private startTime;
3
- private name;
4
- private logFn;
5
- private hasEnded;
6
- constructor(name: string, logFn: (message: string) => void);
7
- end(): void;
8
- }
@@ -1,18 +0,0 @@
1
- export class Timer {
2
- constructor(name, logFn) {
3
- this.hasEnded = false;
4
- this.name = name;
5
- this.logFn = logFn;
6
- this.startTime = Date.now();
7
- }
8
- end() {
9
- // If already ended, do nothing (idempotent)
10
- if (this.hasEnded) {
11
- return;
12
- }
13
- const endTime = Date.now();
14
- const duration = endTime - this.startTime;
15
- this.logFn(`${this.name} took ${duration}ms`);
16
- this.hasEnded = true;
17
- }
18
- }