Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve JSDocs & Update Input Typing #38

Merged
merged 1 commit into from
Dec 14, 2021
Merged
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
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const ansi = new RegExp(

export const stripAnsi = (input: string) => input.replace(ansi, "");

export type LogMethodInput = string | object;

export type LogMethod = (
...input: (string | object | object[] | unknown)[]
...input: LogMethodInput[]
) => void;

export type Logger<K extends string> = {
Expand Down Expand Up @@ -99,6 +101,14 @@ const pad = (
if (paddingStrategy === "PREPEND") return calculatedPadding + text;
};

/**
* @name createLogger
* Creates a logger with the specified methods and config
* Able to output to a logging function
* @param methods Config of logging methods
* @param [config] Logger-wide configuration
* @param [func=console.log] Custom logging function
*/
export const createLogger = <A extends string>(
methods: { [k in A]: string | MethodConfig },
config: Partial<LogConfig> = {},
Expand Down Expand Up @@ -186,7 +196,7 @@ export const createLogger = <A extends string>(
];

return {
[methodHandle]: (...s: unknown[]) => {
[methodHandle]: (...s: LogMethodInput[]) => {
func(
s
.map((value) => {
Expand All @@ -207,9 +217,9 @@ export const createLogger = <A extends string>(
(index == 0
? paddedText + method.divider
: (array.length - 1 == index
? newLineEndPadding
: newLinePadding) +
method.divider) + value
? newLineEndPadding
: newLinePadding) +
method.divider) + value
)
.join("\n")
);
Expand Down