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

consono

v1.4.17

Published

The most correct, informative, appealing, and configurable variable inspector for JavaScript.

Downloads

126

Readme

Consono

🕵️ Consono 🕵️‍♀️

The most correct, informative, appealing, and configurable variable inspector for JavaScript.

📝 Consono Documentation

npm downloads stars types build lgtm


🔋 Motivation

Motivation and differences from other libraries.

🧬 Examples

consono(undefined);
consono(null);

Nil

consono(true);
consono(false);

Boolean

consono(Infinity);
consono(Number.NEGATIVE_INFINITY);
consono(NaN);
consono(1);
consono(1.5);
consono(BigInt(9007199254740991));

Number

consono(new Date());

Date

consono("Hello, world 😀😁😂🤣😃😄😅😆😉😊", { stringMaxLength: 17 });
consono(Symbol("🌈"));

String

consono(/[0-9]+/);
consono(/\w+/giu);

RegExp

consono(function() {});
consono(function helloWorld() {});
consono(() => {});

Function

consono(new Promise(() => {}));
consono(async function helloWorld() {});
consono(async () => {});
consono(function* gen() { yield 1; });

Async

consono([1, 2, 3]);
consono(Int8Array.from([1, 2, 3]));

Array

consono(new ArrayBuffer(8));
consono(new SharedArrayBuffer(16));

Array Buffer

consono(new Set(["a", true, { prop: 1 }]));
consono(new Map([["first", "a"], [true, "b"]]));
consono(new WeakMap());
consono(new WeakSet());

Collection

consono({});

class MyClass {} const myClass = new MyClass(); myClass.deeper = new
MyClass(); consono(myClass);

Object

consono(new Error("Standard error"));
consono(new EvalError("Unable to run this code"));
consono(new RangeError("Must be less than 10 and greater than 0"));
consono(new ReferenceError("This is error from try/catch"));
consono(new SyntaxError("Not a source code"));
consono(new TypeError("Value is not of the expected type"));

Error

(function(a, b) { consono(arguments); })(true, false);

Arguments

consono(global || globalThis, { objectMaxProps: 3 });

Global

📦 Installation

npm -s install consono

⌨️ Include

The default is a function for printing variable.

import { consono } from "consono";

Import multiple items: function, constructor, options object, theme objects.

import {
  Consono,
  consono,
  options,
  THEME_DARK,
  THEME_LIGHT,
} from "consono";

UNPKG CDN.

Note that the web browser version has no theme support, limited color palette, and only support chromium based browsers.

<script src="https://unpkg.com/consono/dist/consono.js"></script>

⚙️ Options

import { Consono } from "consono";
const options = {
  clear: true,
  quotesEnd: `”`,
  quotesStart: `“`,
  stringMaxLength: 54,
};
const theme = "light"; // default is "dark"
const consono = new Consono(options, theme);
consono.log("Cleared before output. Different quotes. And cut to 54!");
// string • "Cleared before output. Different quotes. And cut to 54"
// (length=55, shown=54)
import { Consono } from "consono";
const theme = {
  argument: [253, 151, 31],
  boolean: [174, 129, 255],
  comment: [117, 113, 94],
  keyword: [249, 38, 114],
  name: [230, 219, 116],
  number: [174, 129, 255],
  plain: [255, 255, 255],
  property: [102, 217, 239],
  string: [166, 226, 46],
};
const consono = new Consono(null, theme);
consono.log("Themed");
import { Consono, options } from "consono";
options.colorize = false;
const consono = new Consono(options);
consono.log("Text without colorization");
import { consono } from "consono";
console.debug(
  consono("Outputs a message only at the debug log level.", false)
);

🏷️ Instance

const consono = Consono.factory(options, theme);
consono("This is log function with your own options");

🔖 Log function

import { consono } from "consono";
const map = new Map();
map.add("key", true);
consono(map);

Return string with variable description.

const variableAsString = consono({}, false);

or

const variableAsString = consono({},  { console: false });
const defaultOptions = {
  // Maximum number of elements in array to show
  arrayMaxElements: 99,
  // Assign symbol
  assignSymbol: "→",
  // Clear console before output
  clear: false,
  // Colorize the output
  colorize: true,
  // Output to console
  console: true,
  // Default depth of object
  depth: 20,
  // 'false' - do nothing. 'true' - exit status ok.
  // Number greater than zero - exit status with passed error code.
  exit: false,
  // Call console.log immediately
  immediate: false,
  // Print indentation
  indent: "ˑˑ",
  // Maximum number of entries in map to show
  mapMaxEntries: 99,
  // Maximum number of properties in object to show
  objectMaxProps: 99,
  // Quote start
  quotesEnd: `"`,
  // Quote end
  quotesStart: `"`,
  // Return inspected variable as string
  returns: true,
  // Maximum number of values in set to show
  setMaxValues: 99,
  // Call `process.stdout.write` instead of `console.log`.
  stdout: false,
  // Maximum length of string to show
  stringMaxLength: 360,
};
consono("Some variable", defaultOptions);

🔮 Shortcuts

// Exit code - 15
consonoExit("Some value", null, null, 15);
// No colorization, no description, only printing with `console.dir`
consonoJSON("Some value");
// No colorization, no description, only printing with `process.stdout.write`
consonoOut("Some value");
// No colorization
consonoPlain("Some value");
// Return only, no `console.log`
consonoReturn("Some value");

👀 Discover more

My other projects