feat(@websnacksjs/conventional): initial implementation

`@websnacksjs/conventional` is a cli program which can be used with
`husky` & git hooks to enforce that commit messages adhere to the
conventional commits standard.
This commit is contained in:
M. George Hansen 2025-08-19 18:31:34 +12:00
parent 3165625fb7
commit 5f519f54f2
Signed by: mgeorgehansen
SSH key fingerprint: SHA256:JlIGiQLPyQ2RHTH3a2oVlb20Xkh9Glr8DUF4YTXHJxM
19 changed files with 1446 additions and 1 deletions

View file

@ -0,0 +1,28 @@
export const normalizeError = (error: unknown): Error => {
if (!(error instanceof Error)) {
error = new Error(`non-Error type thrown: ${JSON.stringify(error)}`);
}
return error as Error;
};
const errorCauseChain = (error: Error): Error[] => {
const causeChain: Error[] = [];
let cause = error.cause;
while (cause !== undefined) {
causeChain.push(normalizeError(cause));
if (cause instanceof Error) {
cause = cause.cause;
}
}
return causeChain;
};
export const formatError = (error: Error): string => {
let message = error.message;
const causeChain = errorCauseChain(error);
for (const cause of causeChain) {
message += `: ${cause.message}`;
}
return message;
};