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

sgcconsole

v1.0.27

Published

sgcConsole logs commands to the console in a structured way such that it is easy to debug code. Sections (or functions) are used to create a console log that looks like an executed piece of 'sudo code'.

Downloads

95

Readme

sgcConsole logs commands to the console in a structured way such that it is easy to debug code. Sections (or functions) are used to create a console log that looks like an executed piece of 'sudo code'.

From version 1.0.10, sgcConsole is now implemented as a class, requiring initialisation using the new keyword.

Note that in order for the colours to work, you must have a console/terminal that supports colours. By default both bash and zsh do. Developed and tested on a Mac, but should work fine on Windows and Unix.

Build Status NPM Version NPM Downloads Install Size

Installation

This is a Node.js package that can be installed from the CLI using the npm install command:

npm install sgcconsole

Using sgcCode

Once installed, sgcConsole needs to be included within your project as follows. Note that logging is disabled on creation and so the .loggingEnabled option needs to be set immediately following the first reference.

const Log = require('sgcconsole')
Log.loggingEnabled = true

sgcConsole is implemented using a singleton model, meaning that the object is shared across a project - requiring sgcConsole in subject files will not therefore need the .loggingEnabled option setting.

Typically, you will want to start with opening a 'function' and then issue one or more messages before closing it:

// Start a new function and log a message
Log.openFunction(`testFunction()`, `index`)
Log.messageToConsole(`This is a test message.`)
Log.closeFunction()

This produces the following output:

Example 1

Turning logging on/off

sgcConsole takes advantage of the environment variable LOGGING_ENABLED to determine if output should be made to the console. In order for any logging to occur, this environment variable must be present and set to true.

Sub-functions

Functions can be cascaded by simply opening a new function before closing the previous function.

const testValue = 123

// Start a new function
Log.lineBreakToConsole()
Log.openFunction(`testFunction()`, `index`)

Log.messageToConsole(`We might log a value, like '${testValue}'.`)
Log.messageToConsole(`:)This is a good message.`)
Log.messageToConsole(`:(This is a bad message.`)

// Start a sub-function and close with a message
Log.newlineToConsole()
Log.openFunction(`subFunction()`, `index`)
Log.messageToConsoleAndClose(`Nothing to see here.`)

// Close the function
Log.closeFunction()
Log.lineBreakToConsole()

This produces the following output:

Example 2

Smiley's

If you wish to show messages in green or red so that they stand-out, simply place a :) (smiley face) for green text or :( (sad face) for red text:

Log.openFunction(`testFunction()`, `index`)
Log.messageToConsole(`:)This is a good message.`)
Log.messageToConsole(`:(This is a bad message.`)
Log.closeFunction()

Line breaks

To help separate sections of code, you can include a line break, which will insert a fixed number of characters in a yellow line to the screen:

Log.lineBreakToConsole()
Log.openFunction(`testFunction()`, `index`)
Log.messageToConsole(`This is a test message.`)
Log.closeFunction()
Log.lineBreakToConsole()

New line

You can additionally add one or more blank lines by using the newlineToConsole call, which takes the number of lines you wish to insert as a parameter. If no parameter is specified then it defaults to 1.

Log.newlineToConsole()
Log.lineBreakToConsole()
Log.openFunction(`testFunction()`, `index`)
Log.messageToConsole(`This is a test message.`)
Log.closeFunction()
Log.lineBreakToConsole()
Log.newlineToConsole(10)

Support

This package is under active development as we use it in our own products. If you experience any difficulties, please email [email protected] and we'll get back to you as soon as possible.