Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pietrodev07/kittylog
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrodev07 committed May 23, 2024
2 parents 4ba015b + 741f420 commit 198db73
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/src/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ It is by default, so you don't need to add it!
}
}
```
:::
:::
10 changes: 10 additions & 0 deletions docs/src/guide/log-types/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ interface BoxParameters {
```

:::

::: tip Support for rest parameters

`box` support [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)

```js
kittylog.box("Hello", ...)
```

:::
10 changes: 10 additions & 0 deletions docs/src/guide/log-types/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@ type Color =
```

:::

::: tip Support for rest parameters

`custom` support [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)

```js
kittylog.custom("magenta", "CUSTOM", "Hello", ...)
```

:::
10 changes: 10 additions & 0 deletions docs/src/guide/log-types/error.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ interface ErrorParameters {
```

:::

::: tip Support for rest parameters

`error` support [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)

```js
kittylog.error("Error", ...)
```

:::
10 changes: 10 additions & 0 deletions docs/src/guide/log-types/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ interface InfoParameters {
```

:::

::: tip Support for rest parameters

`info` support [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)

```js
kittylog.info("Info", ...)
```

:::
10 changes: 10 additions & 0 deletions docs/src/guide/log-types/success.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ interface SuccessParameters {
```

:::

::: tip Support for rest parameters

`success` support [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)

```js
kittylog.success("Success", ...)
```

:::
10 changes: 10 additions & 0 deletions docs/src/guide/log-types/warning.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ interface WarningParameters {
```

:::

::: tip Support for rest parameters

`warning` support [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)

```js
kittylog.warning("Warning", ...)
```

:::
2 changes: 1 addition & 1 deletion docs/src/guide/what-is-kittylog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ One of the core features of KittyLog is its ability to augment logs visually. By

## Preview

<img src="/screenshot.png" alt="preview image of library" style="border-radius: 8px;" />
<img src="/screenshot.png" alt="preview image of library" style="border-radius: 8px;" />
2 changes: 1 addition & 1 deletion src/functions/blank/blank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const blank = (lineType?: LineType, color?: Color) => {
const selectedLine = lineType in LINE_TYPES ? LINE_TYPES[lineType] : LINE_TYPES.default;
const selectedColor = color in COLORS ? COLORS[color] : COLORS.default;

console.log(...buildCompleteMessage([colorizeText(selectedLine.repeat(40), selectedColor)]));
console.log(...buildCompleteMessage([colorizeText(selectedLine, selectedColor)]));
};
6 changes: 3 additions & 3 deletions src/functions/box/box.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const box = (message: string): void => {
export const box = (...message: string[]): void => {
let border = "──"; // We put 2 characters to have some distance from the edge

for (let i = 0; i < message.length; i++) {
for (let i = 0; i < message.join(" ").length; i++) {
border += "─";
}

console.log(`╭${border}╮\n│ ${message} │\n╰${border}╯`);
console.log(`╭${border}╮\n│ ${message.join(" ")} │\n╰${border}╯`);
};
4 changes: 2 additions & 2 deletions src/functions/custom/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { COLORS } from "../../constants";
import { colorsProvider } from "../../global";
import { Color } from "../../types";

export const custom = (color: Color, label: string, message: string) => {
export const custom = (color: Color, label: string, ...message: string[]) => {
const { colorizeText, buildCompleteMessage } = colorsProvider;

const labelMessage = colorizeText(`[${label}]`, COLORS[color]);
const messageColorized = colorizeText(message, COLORS[color]);
const messageColorized = colorizeText(message.join(" "), COLORS[color]);

console.log(...buildCompleteMessage([labelMessage, messageColorized]));
};
18 changes: 11 additions & 7 deletions src/functions/error/error.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { COLORS } from "../../constants";
import { colorsProvider } from "../../global";

export const error = (message: string | Error) => {
export const error = (...message: string[] | Error[]) => {
const { colorizeText, buildCompleteMessage } = colorsProvider;
const label = colorizeText("[ERROR]", COLORS.red);

if (typeof message === "string") {
const messageColorized = colorizeText(message, COLORS.red);
if (message[0] instanceof Error) {
if (message.length > 1) throw new Error("Too many arguments for error function");

console.error(...buildCompleteMessage([label, messageColorized]));
} else {
const stack = `\n${message.stack?.split("\n").slice(1).join("\n")}`;
const error = message[0];

const stack = `\n${error.stack?.split("\n").slice(1).join("\n")}`;

const messageColorized = colorizeText(message.message, COLORS.red);
const messageColorized = colorizeText(error.message, COLORS.red);
const stackColorized = colorizeText(stack, COLORS.dim);

console.error(...buildCompleteMessage([label, messageColorized, stackColorized]));
} else {
const messageColorized = colorizeText(message.join(" "), COLORS.red);

console.error(...buildCompleteMessage([label, messageColorized]));
}
};
4 changes: 2 additions & 2 deletions src/functions/info/info.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { COLORS } from "../../constants";
import { colorsProvider } from "../../global";

export const info = (message: string) => {
export const info = (...message: string[]) => {
const { colorizeText, buildCompleteMessage } = colorsProvider;

const label = colorizeText("[INFO]", COLORS.cyan);
const messageColorized = colorizeText(message, COLORS.cyan);
const messageColorized = colorizeText(message.join(" "), COLORS.cyan);

console.info(...buildCompleteMessage([label, messageColorized]));
};
4 changes: 2 additions & 2 deletions src/functions/success/success.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { COLORS } from "../../constants";
import { colorsProvider } from "../../global";

export const success = (message: string) => {
export const success = (...message: string[]) => {
const { colorizeText, buildCompleteMessage } = colorsProvider;

const label = colorizeText("[SUCCESS]", COLORS.green);
const messageColorized = colorizeText(message, COLORS.green);
const messageColorized = colorizeText(message.join(" "), COLORS.green);

console.log(...buildCompleteMessage([label, messageColorized]));
};
4 changes: 2 additions & 2 deletions src/functions/warning/warning.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { COLORS } from "../../constants";
import { colorsProvider } from "../../global";

export const warning = (message: string): void => {
export const warning = (...message: string[]): void => {
const { colorizeText, buildCompleteMessage } = colorsProvider;

const label = colorizeText("[WARNING]", COLORS.yellow);
const messageColorized = colorizeText(message, COLORS.yellow);
const messageColorized = colorizeText(message.join(" "), COLORS.yellow);

console.warn(...buildCompleteMessage([label, messageColorized]));
};
8 changes: 7 additions & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kittylog.debug("User data", { id: 1, username: "pietrodev07" });

kittylog.blank("dashed", "yellow");

kittylog.box("Hello, World! From a box!");
kittylog.box("Hello, World!", "This is a test...");

const whileLoopTest = kittylog.performance("external performance test #1");

Expand All @@ -40,3 +40,9 @@ for (let i = 0; i < 100; i++) {}
internalTest.end();

forLoopTest.end();

kittylog.info("Info...", "This is a test...");
kittylog.success("Success...", "This is a test...");
kittylog.warning("Warn...", "This is a test...");
kittylog.error("Error...", "This is a test...");
kittylog.custom("magenta", "CUSTOM", "Custom...", "This is a test...");

0 comments on commit 198db73

Please sign in to comment.