Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ const ErrorType = type({
"stack?": "string",
});

const formatItem = (item: unknown): string => {
const itemToString = (item: unknown): string => {
if (typeof item === "undefined") return "undefined";

// Remove colors from strings
if (typeof item === "string")
// biome-ignore lint/suspicious/noControlCharactersInRegex: stripping ANSI escape codes
return config.redact(item.replace(/\x1b\[[0-9;]*m/g, ""));
return item.replace(/\x1b\[[0-9;]*m/g, "");

// Check if this is an Error
const error = ErrorType(item);
if (!(error instanceof type.errors))
return config.redact(error.stack || error.message);
if (!(error instanceof type.errors)) return error.stack || error.message;

Comment thread
SynthLuvr marked this conversation as resolved.
const stringified = (() => {
try {
Expand All @@ -36,12 +35,10 @@ const formatItem = (item: unknown): string => {
}
})();

return config.redact(stringified.replace(/^'|'$/g, ""));
return stringified.replace(/^'|'$/g, "");
};

const format = (items: unknown[]): string =>
Array.from(items)
.map((item) => formatItem(item))
.join(" ");
config.redact(Array.from(items).map(itemToString).join(" "));

export { format, updateConfig };
12 changes: 11 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { format } from "../src/format.js";
import { setupLogging } from "../src/index.js";

beforeAll(() => {
setupLogging();
setupLogging({ hex: { allow: [{ re: /\b(transfer)\b/i }] } });
});

describe("logging", () => {
Expand Down Expand Up @@ -34,4 +34,14 @@ describe("logging", () => {
expect(result).not.toContain(secret);
expect(result).toContain("[REDACTED]");
});

it("allows hex when context word is in a separate argument", () => {
const result = format([
"transfer",
"538845bf2f418e0c7f3798d6bcb632273d46633545a5e261feceb7d378ed0761",
]);
expect(result).toBe(
"transfer 538845bf2f418e0c7f3798d6bcb632273d46633545a5e261feceb7d378ed0761",
);
});
});