npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cornsol

v1.1.5

Published

pretty console formatter

Downloads

5

Readme

🌽 cornsol 🌞

Pretty, Formatted, Numbered, Customizable

JavaScript console library.

Demo

npm npm dev dependency version npm GitHub code size in bytes NPM GitHub Repo stars

Table of contents

Installation

npm i cornsol
# or
yarn add cornsol

Cautions

cornsol use the default naming for asynchronous.

If you want to use synchronous functions then use functions below.

function openPrintGroupSync<T>(fn?: () => T): T;
function closePrintGroupSync<T>(fn?: () => T): T;
function printStepSync<T = void>(stepName: string, stepFunction: () => T): T;
function printGroupSync<T = void>(stepFunction: () => T, open?: () => void, close?: () => void): T;
function printArraySync(fn: (msg: any, ...params: any[]) => void, messages: any[]): void;
function printBufferSync(fn: (msg: any, ...params: any[]) => void, chunk: any): void;

Usage

Register globally

const corn = require("cornsol");

corn.register();

// Unregister
corn.unregister();

Function supports

Overloads

  • log
  • debug
  • dir
  • info
  • warn
  • error
  • group
  • table
  • trace
  • groupCollapsed
  • groupEnd

Extra features

  • div
  • array
  • chunk

Group

Example

const corn = require("cornsol");

corn.register();

// Open and close the group manually
console.group("group start");
console.log("content");
console.groupEnd("close group");
// or
corn.openPrintGroup(console.log, "group start");
console.log("content");
corn.closePrintGroup(console.log, "close group");

Result

➤ 0000: ─ This is an example for print group
➤ 0001: ┌ group start
        │ content
        └ group end
➤ 0002: ┌ group start
        │ content
        └ close group

Array

Example

const corn = require("cornsol");

corn.register();

// Synchronous
console.array(["Item 1", "Item 2"]);
// or
corn.printArraySync(console.log, ["Item 1", "Item 2"]);

// Asynchronous
console.array.async(["Item 1", (async () => "Item 2")()]);
// or
corn.printArray(console.log, ["Item 1", (async () => "Item 2")()]);

Result

➤ 0000: ┌ Item 1
        └ Item 2

Step

Example

const corn = require("cornsol");

corn.register();

// Synchronous
const result = console.step("Step title", () => {
  console.log("Process 1");
  console.log("Process 2");

  return 1;
});
// or
const result = corn.printStepSync("Step title", () => {
  // ...
});

// Asynchronous
const result = console.step.async("Step title", () => {
  // ...
});
const result = corn.printStep("Step title", () => {
  // ...
});

console.log(result);

Result

➤ 0000: ┌ Step title step
        │ Process 1
        │ Process 2
        └ Completed in 0s
➤ 0001: ─ 1

Chunk

Example

const corn = require("cornsol");
const { exec } = require("child_process");

const proc = exec("ls");

corn.register();

// Synchronous
proc.stdout.on("data", console.chunk);
// or
proc.stdout.on("data", (chunk) => corn.printChunkSync(console.log, chunk));

// Asynchronous
proc.stdout.on("data", console.chunk.async);
// or
proc.stdout.on("data", (chunk) => corn.printChunk(console.log, chunk));

// It works internally like
corn.printArray(console.log, Buffer.from(chunk).toString().trim().split("\n"));

Result

➤ 0000: ┌ dist
        │ LICENSE
        │ node_modules
        │ package.json
        │ README.md
        │ src
        │ test
        │ tsconfig.json
        └ yarn.lock

Divider

Example

console.log("message 1");
console.div("This is a divider");
console.log("message 2");

// or

const { printDivider } = require("cornsol");

console.log("message 1");
printDivider("This is a divider");
console.log("message 2");

Result

➤ 0000: ─ message 1
───────── This is a divider
➤ 0001: ─ message 2

Customizations

cornsol supports customizing.

Spinners

cornsol use ASCII spinners on group print.

There are some presets for spinner.

// Built-in presets
export const spinners = [
  /* 0  */ "⣾⣽⣻⢿⡿⣟⣯⣷",
  /* 1  */ "←↖↑↗→↘↓↙",
  /* 2  */ "⠁⠂⠄⡀⢀⠠⠐⠈",
  /* 3  */ "▉▊▋▌▍▎▏▎▍▌▋▊▉",
  /* 4  */ "▁▂▃▄▅▆▇█▇▆▅▄▃▂▁",
  /* 5  */ "▖▘▝▗",
  /* 6  */ "┤┘┴└├┌┬┐",
  /* 7  */ "◢◣◤◥",
  /* 8  */ "◰◳◲◱",
  /* 9  */ "◴◷◶◵",
  /* 10 */ "◐◓◑◒",
  /* 11 */ "◡⊙◠",
  /* 12 */ "bᓂqᓄ",
  /* 13 */ "dᓇpᓀ",
  /* 14 */ "d|b|",
  /* 15 */ "q|p|",
  /* 16 */ "ᓂ—ᓄ—",
  /* 17 */ "ᓇ—ᓀ—",
  /* 18 */ "|/—\\",
];

// Update config
const corn = require("cornsol");

corn.configure({
  spinner: {
    symbols: corn.spinners[4], // "▁▂▃▄▅▆▇█▇▆▅▄▃▂▁"
  },
});

Line numbers

Example

const corn = require("cornsol");

corn.register();

corn.configure({
  formatters: {
    lineNumber: (context) => `${String(context.lineNo).padStart(2, "0")} [${new Date().toISOString()}]:`,
  },
});

console.log(0);
console.log(1);
console.log(2);

Result

➤ 01 [2022-12-20T02:48:47.909Z]: ─ 0
➤ 02 [2022-12-20T02:48:47.909Z]: ─ 1
➤ 03 [2022-12-20T02:48:47.909Z]: ─ 2

Step messages

Example

const corn = require("cornsol");

corn.register();

corn.configure({
  formatters: {
    stepStart: (context, name) => `The cool step ${name}`,
    stepEnd: (context, name, duration) => `The cool step ${name} has been completed in ${context.duration(duration)}`,
  },
});

console.log(0);
console.log(1);
console.log(2);

Result

➤ 0000: ┌ The cool step Test
        │ 0
        │ 1
        │ 2
        └ The cool step Test has been completed in 0s 1ms

Symbols

Example

const corn = require("cornsol");

corn.register();

corn.configure({
  symbols: {
    prefix: "$",
    singleLine: "*",
    newLine: "&",
    groupStart: "┳",
    groupLine: "┣",
    groupEnd: "┗",
  },
});

console.log(0);
console.log(1);
console.log(2);

console.group(0);
console.log(1);
console.log(2);
console.log(3);
console.groupEnd(4);

Result (small size terminal)

$ 0000: * 0
$ 0001: * 1
$ 0002: * 2
$ 0003: ┳ The cool step Test
        ┣ 0
        ┣ 1
        ┣ 2
        ┗ The cool step Test has been
          &  completed in 0s 1ms

License

MIT