Skip to content

Commit

Permalink
fix(performance): fixed performance.ts log type
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrodev07 committed Feb 17, 2024
1 parent c92467e commit c1f0a04
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kittylog",
"version": "1.0.2",
"version": "1.0.4",
"description": "Pretty logs in JavaScript",
"author": "pietrodev07",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { debug } from "./debug/debug";
export { error } from "./error/error";
export { httpResponse } from "./httpResponse/httpResponse";
export { info } from "./info/info";
export { performance, performanceEnd } from "./performance/performance";
export { performance } from "./performance/performance";
export { success } from "./success/success";
export { table } from "./table/table";
export { tableCSV } from "./tableCSV/tableCSV";
Expand Down
32 changes: 15 additions & 17 deletions src/functions/performance/performance.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { COLORS } from "../../constants";
import { colorsProvider } from "../../global";
import { PerformanceSettings } from "../../types";
import { nowPerformance } from "../../utils/nowPerformance";
import { PerformanceStack } from "../../types";

const performanceStack: PerformanceSettings[] = [];

export const performanceEnd = (action: string) => {
const { colorizeText, buidlCompleteMessage } = colorsProvider;
const { start } = performanceStack.pop();

const label = colorizeText("[PERFORMANCE]", COLORS.cyan);

const end = nowPerformance();
const duration = end - start;

console.log(...buidlCompleteMessage([label]), `${action}:`, `${duration.toFixed(3)}ms`);
};
const performanceStack: PerformanceStack[] = [];
const getPerformanceTimestamp = global.performance;

export const performance = (action: string) => {
const start = nowPerformance();
const start = getPerformanceTimestamp.now();
performanceStack.push({ action, start });

return {
end: () => performanceEnd(action),
end: () => {
const { colorizeText, buidlCompleteMessage } = colorsProvider;
const { start } = performanceStack.pop();

const label = colorizeText("[PERFORMANCE]", COLORS.cyan);

const end = getPerformanceTimestamp.now();
const duration = end - start;

console.log(...buidlCompleteMessage([label]), `${action}:`, `${duration.toFixed(3)}ms`);
},
};
};
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { COLORS, LINE_TYPES } from "../constants";
export type Color = keyof typeof COLORS;
export type LineType = keyof typeof LINE_TYPES;

export interface PerformanceSettings {
export interface PerformanceStack {
start: number | null;
action: string | null;
}
Expand Down
3 changes: 0 additions & 3 deletions src/utils/nowPerformance.ts

This file was deleted.

0 comments on commit c1f0a04

Please sign in to comment.