@mks2508/better-logger 0.0.2-alpha.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/.claude/settings.local.json +18 -2
- package/.github/workflows/ci-quality.yml +357 -0
- package/.github/workflows/docs-demo.yml +119 -0
- package/.github/workflows/releases-core.yml +512 -0
- package/.github/workflows/releases-full.yml +582 -0
- package/.github/{workflows → workflows-backup}/ci.yml +12 -110
- package/.github/workflows-backup/nightly.yml +196 -0
- package/.github/workflows-backup/release-optimized.yml +373 -0
- package/.release-notes-0.2.0.md +129 -0
- package/.yamllint +28 -0
- package/CHANGELOG.json +783 -0
- package/CLAUDE.md +92 -1
- package/README.md +198 -490
- package/bun.lock +323 -0
- package/demo.html +9 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/Logger.d.ts +272 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/Logger.js +680 -0
- package/dist/ScopedLogger.d.ts +126 -0
- package/dist/ScopedLogger.d.ts.map +1 -0
- package/dist/ScopedLogger.js +234 -0
- package/dist/chunks/Logger-BpeuYIxR.js +2 -0
- package/dist/chunks/Logger-BpeuYIxR.js.map +1 -0
- package/dist/chunks/Logger-Didxtr23.js +3275 -0
- package/dist/chunks/Logger-Didxtr23.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
- package/dist/chunks/environment-Bxbnw4pd.js +544 -0
- package/dist/chunks/environment-Bxbnw4pd.js.map +1 -0
- package/dist/chunks/environment-Dm66zOML.js +4 -0
- package/dist/chunks/environment-Dm66zOML.js.map +1 -0
- package/dist/chunks/formatting-C0riPC5_.js +95 -0
- package/dist/chunks/formatting-C0riPC5_.js.map +1 -0
- package/dist/chunks/formatting-DNCAV66-.js +2 -0
- package/dist/chunks/formatting-DNCAV66-.js.map +1 -0
- package/dist/cli/CommandProcessor.d.ts +103 -0
- package/dist/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/cli/CommandProcessor.js +184 -0
- package/dist/cli/commands/ConfigCommand.d.ts +17 -0
- package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/cli/commands/ConfigCommand.js +88 -0
- package/dist/cli/commands/ExportCommand.d.ts +51 -0
- package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/cli/commands/ExportCommand.js +243 -0
- package/dist/cli/commands/HistoryCommand.d.ts +50 -0
- package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
- package/dist/cli/commands/HistoryCommand.js +96 -0
- package/dist/cli/commands/StatusCommand.d.ts +33 -0
- package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/cli/commands/StatusCommand.js +93 -0
- package/dist/cli/commands/ThemeCommand.d.ts +33 -0
- package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/cli/commands/ThemeCommand.js +79 -0
- package/dist/cli/help.d.ts +15 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +118 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +46 -0
- package/dist/constants.d.ts +122 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +159 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +134 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +315 -242
- package/dist/core.js.map +1 -1
- package/dist/example.d.ts +18 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +154 -0
- package/dist/exports-module.d.ts +203 -0
- package/dist/exports-module.d.ts.map +1 -0
- package/dist/exports-module.js +260 -0
- package/dist/exports.cjs +1 -1
- package/dist/exports.cjs.map +1 -1
- package/dist/exports.js +5 -4
- package/dist/exports.js.map +1 -1
- package/dist/handlers/AnalyticsLogHandler.d.ts +11 -0
- package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/handlers/AnalyticsLogHandler.js +19 -0
- package/dist/handlers/ExportLogHandler.d.ts +103 -0
- package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/handlers/ExportLogHandler.js +516 -0
- package/dist/handlers/FileLogHandler.d.ts +36 -0
- package/dist/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/handlers/FileLogHandler.js +156 -0
- package/dist/handlers/RemoteLogHandler.d.ts +14 -0
- package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/dist/handlers/RemoteLogHandler.js +37 -0
- package/dist/handlers/index.d.ts +8 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -103
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +139 -0
- package/dist/styling/LogStyleBuilder.d.ts +149 -0
- package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
- package/dist/styling/LogStyleBuilder.js +289 -0
- package/dist/styling/SemanticStyles.d.ts +181 -0
- package/dist/styling/SemanticStyles.d.ts.map +1 -0
- package/dist/styling/SemanticStyles.js +339 -0
- package/dist/styling/SmartPresets.d.ts +25 -0
- package/dist/styling/SmartPresets.d.ts.map +1 -0
- package/dist/styling/SmartPresets.js +276 -0
- package/dist/styling/StyleBuilder.d.ts +140 -0
- package/dist/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/styling/StyleBuilder.js +280 -0
- package/dist/styling/banners.d.ts +45 -0
- package/dist/styling/banners.d.ts.map +1 -0
- package/dist/styling/banners.js +155 -0
- package/dist/styling/index.d.ts +10 -0
- package/dist/styling/index.d.ts.map +1 -0
- package/dist/styling/index.js +9 -0
- package/dist/styling/themes.d.ts +10 -0
- package/dist/styling/themes.d.ts.map +1 -0
- package/dist/styling/themes.js +231 -0
- package/dist/styling-module.d.ts +185 -0
- package/dist/styling-module.d.ts.map +1 -0
- package/dist/styling-module.js +199 -0
- package/dist/styling.cjs +1 -1
- package/dist/styling.cjs.map +1 -1
- package/dist/styling.js +6 -6
- package/dist/styling.js.map +1 -1
- package/dist/types/Logger.d.ts +268 -0
- package/dist/types/Logger.d.ts.map +1 -0
- package/dist/types/ScopedLogger.d.ts +123 -0
- package/dist/types/ScopedLogger.d.ts.map +1 -0
- package/dist/types/cli/CommandProcessor.d.ts +100 -0
- package/dist/types/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/types/cli/commands/ConfigCommand.d.ts +14 -0
- package/dist/types/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/ExportCommand.d.ts +48 -0
- package/dist/types/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/HistoryCommand.d.ts +47 -0
- package/dist/types/cli/commands/HistoryCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/StatusCommand.d.ts +30 -0
- package/dist/types/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/ThemeCommand.d.ts +30 -0
- package/dist/types/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/types/cli/help.d.ts +12 -0
- package/dist/types/cli/help.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +15 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/constants.d.ts +119 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/core.d.ts +125 -211
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +13 -0
- package/dist/types/example.d.ts +18 -0
- package/dist/types/example.d.ts.map +1 -0
- package/dist/types/exports-module.d.ts +196 -0
- package/dist/types/exports-module.d.ts.map +1 -0
- package/dist/types/handlers/AnalyticsLogHandler.d.ts +8 -0
- package/dist/types/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/ExportLogHandler.d.ts +100 -0
- package/dist/types/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/FileLogHandler.d.ts +33 -0
- package/dist/types/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/RemoteLogHandler.d.ts +11 -0
- package/dist/types/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/index.d.ts +8 -0
- package/dist/types/handlers/index.d.ts.map +1 -0
- package/dist/types/handlers.d.ts +88 -0
- package/dist/types/handlers.d.ts.map +1 -0
- package/dist/types/handlers.js +4 -0
- package/dist/types/index.d.ts +7 -675
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/main.d.ts.map +1 -0
- package/dist/types/styling/LogStyleBuilder.d.ts +146 -0
- package/dist/types/styling/LogStyleBuilder.d.ts.map +1 -0
- package/dist/types/styling/SemanticStyles.d.ts +178 -0
- package/dist/types/styling/SemanticStyles.d.ts.map +1 -0
- package/dist/types/styling/SmartPresets.d.ts +22 -0
- package/dist/types/styling/SmartPresets.d.ts.map +1 -0
- package/dist/types/styling/StyleBuilder.d.ts +140 -0
- package/dist/types/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/types/styling/banners.d.ts +42 -0
- package/dist/types/styling/banners.d.ts.map +1 -0
- package/dist/types/styling/index.d.ts +10 -0
- package/dist/types/styling/index.d.ts.map +1 -0
- package/dist/types/styling/themes.d.ts +7 -0
- package/dist/types/styling/themes.d.ts.map +1 -0
- package/dist/types/styling-module.d.ts +178 -0
- package/dist/types/styling-module.d.ts.map +1 -0
- package/dist/types/types/core.d.ts +125 -0
- package/dist/types/types/core.d.ts.map +1 -0
- package/dist/types/types/handlers.d.ts +85 -0
- package/dist/types/types/handlers.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +7 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/environment.d.ts +47 -0
- package/dist/types/utils/environment.d.ts.map +1 -0
- package/dist/types/utils/formatting.d.ts +37 -0
- package/dist/types/utils/formatting.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/opentui-detection.d.ts +34 -0
- package/dist/types/utils/opentui-detection.d.ts.map +1 -0
- package/dist/types/utils/output.d.ts +41 -0
- package/dist/types/utils/output.d.ts.map +1 -0
- package/dist/types/utils/stackTrace.d.ts +6 -0
- package/dist/types/utils/stackTrace.d.ts.map +1 -0
- package/dist/types/utils/timestamps.d.ts +20 -0
- package/dist/types/utils/timestamps.d.ts.map +1 -0
- package/dist/utils/environment.d.ts +47 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/environment.js +85 -0
- package/dist/utils/formatting.d.ts +40 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/formatting.js +117 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/opentui-detection.d.ts +34 -0
- package/dist/utils/opentui-detection.d.ts.map +1 -0
- package/dist/utils/opentui-detection.js +116 -0
- package/dist/utils/output.d.ts +44 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +150 -0
- package/dist/utils/stackTrace.d.ts +9 -0
- package/dist/utils/stackTrace.d.ts.map +1 -0
- package/dist/utils/stackTrace.js +81 -0
- package/dist/utils/timestamps.d.ts +20 -0
- package/dist/utils/timestamps.d.ts.map +1 -0
- package/dist/utils/timestamps.js +71 -0
- package/docs/API.md +691 -0
- package/docs/CORE.md +10 -10
- package/docs/DEVELOPMENT.md +731 -0
- package/docs/PACKAGES.md +244 -0
- package/docs/_config.yml +36 -0
- package/docs/index.md +179 -0
- package/examples/README.md +208 -0
- package/examples/basic-logging.js +75 -0
- package/examples/data-export.js +234 -0
- package/examples/package.json +16 -0
- package/examples/performance-timing.js +170 -0
- package/examples/simplified-api.js +124 -0
- package/examples/styling-themes.js +207 -0
- package/package.json +37 -21
- package/packages/core/package.json +57 -0
- package/packages/exports/package.json +41 -0
- package/packages/nodejs-opentui/README.md +232 -0
- package/packages/nodejs-opentui/package.json +72 -0
- package/packages/nodejs-opentui/src/LogRenderer.ts +171 -0
- package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +178 -0
- package/packages/nodejs-opentui/src/components/LogBadge.tsx +131 -0
- package/packages/nodejs-opentui/src/index.ts +133 -0
- package/packages/nodejs-opentui/src/types.ts +158 -0
- package/packages/nodejs-opentui/tsconfig.json +20 -0
- package/packages/styling/package.json +41 -0
- package/project-utils/README.md +172 -0
- package/project-utils/auto-release-gemini.ts +1193 -0
- package/project-utils/auto-release-ui.ts +1329 -0
- package/project-utils/commit-generator.ts +1385 -0
- package/project-utils/commit-ui.ts +264 -0
- package/project-utils/git-utils.ts +199 -0
- package/project-utils/github-release-manager.ts +466 -0
- package/project-utils/project-config.ts +260 -0
- package/project-utils/prompt-templates.js +345 -0
- package/project-utils/prompt-templates.ts +422 -0
- package/project-utils/version-manager.ts +1078 -0
- package/src/Logger.ts +251 -16
- package/src/ScopedLogger.ts +262 -0
- package/src/cli/CommandProcessor.ts +173 -2
- package/src/cli/commands/HistoryCommand.ts +117 -0
- package/src/cli/index.ts +12 -0
- package/src/constants.ts +84 -2
- package/src/core.ts +119 -46
- package/src/example.ts +4 -4
- package/src/exports-module.ts +1 -1
- package/src/handlers/ExportLogHandler.ts +141 -0
- package/src/handlers/FileLogHandler.ts +144 -5
- package/src/index.ts +1 -1
- package/src/main.ts +3 -3
- package/src/styling/LogStyleBuilder.ts +355 -0
- package/src/styling/SemanticStyles.ts +380 -0
- package/src/styling/SmartPresets.ts +288 -0
- package/src/styling/StyleBuilder.ts +14 -0
- package/src/styling/index.ts +16 -1
- package/src/styling-module.ts +1 -1
- package/src/types/core.ts +60 -0
- package/src/types/index.ts +6 -0
- package/src/utils/environment.ts +94 -0
- package/src/utils/formatting.ts +142 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/opentui-detection.ts +138 -0
- package/src/utils/output.ts +66 -8
- package/test-core-browser.html +237 -0
- package/test-core-node.js +63 -0
- package/tests/test-conflict-resolution.ts +391 -0
- package/tests/validate-workflows.sh +131 -0
- package/tests/yaml-autofix.sh +146 -0
- package/vite.config.ts +189 -50
- package/.npmrc.bak +0 -1
- package/dist/chunks/Logger-BQhMKy_T.js +0 -2
- package/dist/chunks/Logger-BQhMKy_T.js.map +0 -1
- package/dist/chunks/Logger-BrFKFZcD.js +0 -978
- package/dist/chunks/Logger-BrFKFZcD.js.map +0 -1
- package/dist/chunks/core-2opW4Pi3.js +0 -194
- package/dist/chunks/core-2opW4Pi3.js.map +0 -1
- package/dist/chunks/core-DyugwSYZ.js +0 -4
- package/dist/chunks/core-DyugwSYZ.js.map +0 -1
- package/dist/chunks/exports-BNP3R7dp.js +0 -421
- package/dist/chunks/exports-BNP3R7dp.js.map +0 -1
- package/dist/chunks/exports-U1xLBXrY.js +0 -2
- package/dist/chunks/exports-U1xLBXrY.js.map +0 -1
- package/dist/chunks/styling-DhUDzwlE.js +0 -654
- package/dist/chunks/styling-DhUDzwlE.js.map +0 -1
- package/dist/chunks/styling-tmRDI28D.js +0 -2
- package/dist/chunks/styling-tmRDI28D.js.map +0 -1
- package/dist/types/exports.d.ts +0 -600
- package/dist/types/styling.d.ts +0 -751
- package/src/Logger.ts.backup +0 -1684
- /package/.github/{workflows → workflows-backup}/release.yml +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stackTrace.d.ts","sourceRoot":"","sources":["../../src/utils/stackTrace.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,eAAe,IAAI,SAAS,GAAG,IAAI,CAqFlD"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Stack trace parsing utilities for Advanced Logger
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parses the current stack trace to extract caller information
|
|
6
|
+
*/
|
|
7
|
+
export function parseStackTrace() {
|
|
8
|
+
try {
|
|
9
|
+
const stack = new Error().stack;
|
|
10
|
+
if (!stack) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const lines = stack.split('\n').filter(line => line.trim());
|
|
14
|
+
// Find the first caller that's not from Logger methods
|
|
15
|
+
for (let i = 1; i < lines.length; i++) {
|
|
16
|
+
const line = lines[i];
|
|
17
|
+
if (!line) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
// Skip if line contains Logger methods or parseStackTrace
|
|
21
|
+
if (line.includes('parseStackTrace') ||
|
|
22
|
+
line.includes('Logger.') ||
|
|
23
|
+
line.includes('.log(') ||
|
|
24
|
+
line.includes('createStyledOutput')) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
// Parse different stack trace formats
|
|
28
|
+
let match;
|
|
29
|
+
// Chrome format: "at functionName (file:line:column)" or "at file:line:column"
|
|
30
|
+
const chromeMatch = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);
|
|
31
|
+
if (chromeMatch) {
|
|
32
|
+
match = chromeMatch;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Firefox format: "functionName@file:line:column"
|
|
36
|
+
const firefoxMatch = line.match(/(.+?)@(.+?):(\d+):(\d+)$/);
|
|
37
|
+
if (firefoxMatch) {
|
|
38
|
+
match = firefoxMatch;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Safari/other formats
|
|
42
|
+
const safariMatch = line.match(/(\S+)?@(.+?):(\d+):(\d+)$/);
|
|
43
|
+
if (safariMatch) {
|
|
44
|
+
match = safariMatch;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!match) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const [, functionName, file, lineStr, columnStr] = match;
|
|
52
|
+
if (!file) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// Process file path - remove query params and get filename
|
|
56
|
+
const fileParts = file.split('/');
|
|
57
|
+
const fileName = fileParts[fileParts.length - 1];
|
|
58
|
+
if (!fileName) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const cleanFileName = fileName.split('?')[0];
|
|
62
|
+
// Parse line and column numbers
|
|
63
|
+
const lineNum = lineStr ? parseInt(lineStr, 10) : 0;
|
|
64
|
+
const columnNum = columnStr ? parseInt(columnStr, 10) : 0;
|
|
65
|
+
// Clean function name
|
|
66
|
+
const cleanFunction = functionName && functionName.trim()
|
|
67
|
+
? functionName.trim()
|
|
68
|
+
: undefined;
|
|
69
|
+
return {
|
|
70
|
+
file: cleanFileName ? cleanFileName : 'unknown',
|
|
71
|
+
line: lineNum,
|
|
72
|
+
column: columnNum,
|
|
73
|
+
function: cleanFunction
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Timestamp utilities for Advanced Logger
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Formats the timestamp using modern Date API
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatTimestamp(): string;
|
|
8
|
+
/**
|
|
9
|
+
* Parse relative time strings like "2h", "30m", "1d" into milliseconds
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseRelativeTime(timeStr: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Parse time input which can be Date, ISO string, or relative time
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseTimeInput(input: Date | string | number): Date;
|
|
16
|
+
/**
|
|
17
|
+
* Format timestamp for display in different contexts
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatDisplayTime(date: Date, format?: 'short' | 'full' | 'time-only'): string;
|
|
20
|
+
//# sourceMappingURL=timestamps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timestamps.d.ts","sourceRoot":"","sources":["../../src/utils/timestamps.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAQxC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CA2BlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,OAAO,GAAG,MAAM,GAAG,WAAqB,GAAG,MAAM,CAUtG"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Timestamp utilities for Advanced Logger
|
|
3
|
+
*/
|
|
4
|
+
import { TIME_UNITS } from '../constants.js';
|
|
5
|
+
/**
|
|
6
|
+
* Formats the timestamp using modern Date API
|
|
7
|
+
*/
|
|
8
|
+
export function formatTimestamp() {
|
|
9
|
+
try {
|
|
10
|
+
// Use modern Temporal API if available, fallback to Date
|
|
11
|
+
const now = new Date();
|
|
12
|
+
return now.toISOString();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return new Date().toISOString();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse relative time strings like "2h", "30m", "1d" into milliseconds
|
|
20
|
+
*/
|
|
21
|
+
export function parseRelativeTime(timeStr) {
|
|
22
|
+
const match = timeStr.match(/^(\d+)(ms|s|m|h|d)$/);
|
|
23
|
+
if (!match) {
|
|
24
|
+
throw new Error(`Invalid time format: ${timeStr}. Use format like "2h", "30m", "1d"`);
|
|
25
|
+
}
|
|
26
|
+
const [, amount, unit] = match;
|
|
27
|
+
const multiplier = TIME_UNITS[unit];
|
|
28
|
+
return parseInt(amount || '0', 10) * multiplier;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Parse time input which can be Date, ISO string, or relative time
|
|
32
|
+
*/
|
|
33
|
+
export function parseTimeInput(input) {
|
|
34
|
+
if (input instanceof Date) {
|
|
35
|
+
return input;
|
|
36
|
+
}
|
|
37
|
+
if (typeof input === 'number') {
|
|
38
|
+
// Assume hours ago
|
|
39
|
+
return new Date(Date.now() - input * TIME_UNITS.h);
|
|
40
|
+
}
|
|
41
|
+
if (typeof input === 'string') {
|
|
42
|
+
// Try parsing as ISO date first
|
|
43
|
+
const isoDate = new Date(input);
|
|
44
|
+
if (!isNaN(isoDate.getTime())) {
|
|
45
|
+
return isoDate;
|
|
46
|
+
}
|
|
47
|
+
// Try parsing as relative time
|
|
48
|
+
try {
|
|
49
|
+
const ms = parseRelativeTime(input);
|
|
50
|
+
return new Date(Date.now() - ms);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new Error(`Invalid time format: ${input}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`Unsupported time input type: ${typeof input}`);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Format timestamp for display in different contexts
|
|
60
|
+
*/
|
|
61
|
+
export function formatDisplayTime(date, format = 'short') {
|
|
62
|
+
switch (format) {
|
|
63
|
+
case 'time-only':
|
|
64
|
+
return date.toTimeString().slice(0, 8); // HH:MM:SS
|
|
65
|
+
case 'full':
|
|
66
|
+
return date.toISOString();
|
|
67
|
+
case 'short':
|
|
68
|
+
default:
|
|
69
|
+
return date.toISOString().slice(11, 23); // HH:MM:SS.mmm
|
|
70
|
+
}
|
|
71
|
+
}
|