Skip to content

NaN-NaN-sempai/ConsoFy

Repository files navigation

Table of Content

Features

  • ✅ Simple and clean console formatting
  • ✅ Full JS Doc implementation
  • ✅ Colored tags for each log type (log, info, warn, error, success, debug...)
  • ✅ Custom title/prefix for each instance
  • ✅ Native console methods supported (log, error, warn, info, trace, time, count, etc.)
  • ✅ Extra methods:
    • success() — green success logs
    • blank() — prints an empty line
    • typeCustom() — apply custom colors to any log type
  • ✅ Smart handling for:
    • table() — with object hide option ("ignore object")
    • assert(), trace(), time(), timeLog(), timeEnd(), count(), countReset()
  • ✅ Option to disable colors for any single log ("disable color")
  • ✅ Consistent and styled console output for better readability
  • ✅ Lightweight, no dependencies besides kleur

Support

ES6 Module Comonn JS
Node.js

About

ConsoFy is a simple tool to organize your logs. It's easy to use and works just like the default JavaScript console object, behaving in the same way.

The name ConsoFy was created to keep the same word structure as the word console, making it easy to write when coding. The suffix -Fy was added to suggest the idea of transforming or enhancing the console.

Example:

// standard vs consofy
console.log("Hello World!");
consofy.log("Hello World!");

About it's usage, the module imports a generateConsofy function that recieve a param title, the text that will be shown in the console for this consofy instance.

Live example:

Installing

Install the package using npm:

npm install consofy

(optional) Run the test to learn all the supported methods:

consofyTest

(optional) Run the test with the javascript console:

consofyTest -- console

Once the package is installed, you can import ConsoFy to your project:

import generateConsofy from "consofy";

const consofy = generateConsofy("MY CONSOLE");

// Or

import { consofy } from "consofy";
// by doing this way, all files that import consofy will share the same instance
// this is usefull in the case of a fast test or a sigle file implementation
// if you want to organize your modules make sure to use generateConsofy("...")

consofy.title = "MY CONSOLE"; // if not set the title will be "<anonymous>"

If you are using CommomJS:

const generateConsofy = require("consofy");

const consofy = generateConsofy("MY CONSOLE");

// Or

const { consofy } = require("consofy");
// the same is true to Common JS, all files that require consofy will share the same instance
// if you want to organize your modules make sure to use generateConsofy("...")

consofy.title = "MY CONSOLE"; // if not set the title will be "<anonymous>"

CDN

Using jsDelivr CDN (browser module):

<script src="https://cdn.jsdelivr.net/npm/consofy@latest/index.js"></script>

Using unpkg CDN:

<script src="https://unpkg.com/consofy@latest/index.js"></script>

Example

There is a simple example of usage:

consofy.log("Hello World!")

Result:

Errors and Warnings:

consofy.error("This is a error")

consofy.warn("This is a warn")

// in any method if the first argument is "disable color" the text color will be ignored
consofy.error("disable color","This is a error");

Result:

Methods

Almost all the methods of the console were recreated in ConsoFy and the ones that weren't can be executed thru Consofy the same way as the javascript console. They may or may not work and if they don't you can simply use the javascript console as usual.

Some methods:

Trace - ConsoFy traces has some usefull options:

consofy.trace('This is a trace');

// Trace With options
consofy.trace({
    shortenPath: true, // hides most part of the paths shown in the console
    filterLines: ["ModuleJob"], // hides the lines that contain any value of the array
    replace: { // replace the text in the stack trace that is equal to the key of the object by the value
        "traceFunction": "<my replaced string>"
    },
    colorByRegex: [ // colorize the text in the stack trace that matches the regex
        {
            check: /(["'])(.*?)(\1)/g, // paints text inside quotes yellow
            callback: (colors, _, quote, content) => `${quote}${colors.yellow(content)}${quote}`
        },
        {
            check: /<my replaced string>/g, // paints "<my replaced string>" cyan
            callback: (colors, content) => colors.cyan(content)
        }
    ] // The supported colors are: [cyan, yellow, red, green, blue, magenta, gray]
},'This is a trace with options');

Result:

Table:

consofy.table([{name: "John", age: 25}, {name: "Bob", age: 30}, {name: "Alice", age: 30}]);

consofy.table({name: "John", surname: "Doe"});

// in the table, if the first argument is "ignore object" the object will be hidden
consofy.table("ignore object", {name: "John", surname: "Doe"});

Result:

Time:

consofy.time();
setTimeout(() => {
    consofy.timeLog();
},500);
setTimeout(() => {
    consofy.timeEnd();
},1000);

Named Time:

consofy.time("time");
setTimeout(() => {
    consofy.timeLog("time", "my time log");
},500);
setTimeout(() => {
    consofy.timeEnd("time");
},1000);

You can check more methods runnig test command consofyTest and compare with the javascript console consofyTest -- console.

Custom Methods

ConsoFy also has some custom methods:

consofy.log("Blank line ↓");
consofy.blank();
consofy.log("Blank line ↑");


consofy.success("Success message!");

Use typeCustom to execute one method with a different style:

consofy.typeCustom('log', 'error', 'This message is not an error');

consofy.typeCustom('warn', 'info', 'Remender: This message is a warning');

These are the supported styles:

["success", "log", "error", "warn", "info", "debug", "time"]

Credits

I created this tool while organizing a project that i was working on.

To make this README i used as reference Axio's README.

Go back to top ↑

Releases

No releases published

Packages

No packages published