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

captainjs

v1.0.4

Published

A toolkit for NodeJS which contains Debugger and Console Utilities.

Downloads

6

Readme

Captain.js

A toolkit for NodeJS which contains Debugger and Console Utilities.

What is Captain.js?

Captain.js is a toolkit that provides console utilities such as debugging, logging, and commands.

Console

Format console
add formats to the console that apply automatic colors, prefixes and other utilities.

const Captain = require('captainjs');
console = new Captain.Console();

console.log("Hello");
console.error("This is an error");
console.warn("Warning! you are awesome.");

Output:
[23:57:44] [Log] Hello
[23:57:44] [Error] This is an error
[23:57:44] [Warn] Warning! you are awesome.

Custom Console configuration
All parameters are optional.

console = new Captain.Console({
    "use_colors": true,
    "debug": false,
    "format": "§8[§d%time%§8] [%prefix%§8] §7%message%",
    "log_prefix": "§aLog",
    "warn_prefix": "§eWarn",
    "error_prefix": "§cError",
    "info_prefix": "§bInfo",
    "debug_prefix": "§bDebug"
});

Colors

Colors in console
Just do a console.log (); containing a string with color scapes.

const Captain = require('captainjs');
console = new Captain.Console();

console.log("§dHello in Purple §aAnd goodbye in green");

Colors:
§0 = Black
§1 = Dark Blue
§2 = Dark Green
§3 = Dark Cyan
§4 = Dark Red
§5 = Dark Purple
§6 = Gold
§7 = Gray
§8 = Dark Gray
§9 = Blue
§a = Green
§b = Aqua
§c = Red
§d = Purple
§e = Yellow
§f = White
§r = Reset

Colors in console using the Enumerator
You can concatenate a string to a color using the following enumerator.

const Color = require("captainjs").Colors;

console.log(Color.Red + "Hello");

Debugger

Normal debugger
It shows in the console when the function is called, which in turn contains where it is called from and in which line of code.

const Captain = require('captainjs');
const Debug = new Captain.Debugger();

Debug.call();

Output:
Debug called from Object.(); || test.js:4:7

Debugger with message
It shows a message in the console when the function is called, which in turn contains where it is called from and in which line of code.

const Captain = require('captainjs');
const Debug = new Captain.Debugger();

Debug.call("This works?");

Output:
This works? || test.js:4:7

Debugger with console object

const Captain = require('captainjs');
console = new Captain.Console();

console.debug();

Output:
[23:57:44] [Debug] Debug called from Object.(); || test.js:5:9

Commands

Register a command
Registers a function that will be executed when the specified command is written to the terminal.

const Captain = require('captainjs');
const Commander = new Captain.Commander();

Commander.registerCommand("hello", (args) => {
    console.log("Hello world");
});

Commander.fetch();

Change the command input prefix
change the text to be displayed when a command needs to be sent.

Commander.setPrefix("Type a command here: ");

Handle unknown commands
executes an action when trying to execute a non-existent command.

Commander.onUnknownCommand((cmd) => {
    console.error("Invalid Command: " + cmd);
})