Consono
Product Information
Public chat
Support Plans
There are currently no OSS plans available
If you are a provider or contributor to the repository, you can start adding your OSS plan.
Add an OSS planContact us if you are looking for a plan for this open source.
We will help you get in touch with professional providers.
Product Details
๐ต๏ธ Consono ๐ต๏ธโโ๏ธ
The most correct, informative, appealing, and configurable variable inspector for JavaScript.
๐ Motivation
Motivation and differences from other libraries.
- โ๏ธ Light and ๐ dark themes for terminal output.
- ๐๏ธ Configurable coloring of variables.
- Can print to terminal or ๐ return formatted and colored string for later use.
- ๐ Turn on/off output colorization.
- It even works on Windows - use Windows Terminal.
- Configurable indent - tabs ๐ spaces holy war ๐ผ๐ป โ๏ธ ๐ป๐ฆ.
- Availability to set the ๐ณ๏ธ depth for object inspection.
- Configurable #๏ธโฃ max items for array, map, object, set.
- โ๏ธLimit string length when printing for better readability.
- Inspect both string ๐ character count and ๐ string length.
- Inspect โ0๏ธ positive zeroes and โ0๏ธ negative zeroes.
- Inspect ๐ items count for collection-like variables array, map, object, set.
- Actually ๐ฌ can inspect arguments, set and map.
- Can print ๐ function names or mark them as anonymous.
- Handles ๐ circular references.
- Has ๐ TypeScript declaration file.
- Avoids ๐ฑ๐๐ฅ dependency hell.
- Can ๐งน clear terminal before output.
- Can ๐ฅ exit Node.js process after output.
- Import as ๐ ECMAScript module.
- And so on and so forth โพ๏ธ.
๐งฌ Examples
consono(undefined);
consono(null);
consono(true);
consono(false);
consono(Infinity);
consono(Number.NEGATIVE_INFINITY);
consono(NaN);
consono(1);
consono(1.5);
consono(BigInt(9007199254740991));
consono(new Date());
consono("Hello, world ๐๐๐๐คฃ๐๐๐
๐๐๐", { stringMaxLength: 17 });
consono(Symbol("๐"));
consono(/[0-9]+/);
consono(/\w+/giu);
consono(function() {});
consono(function helloWorld() {});
consono(() => {});
consono(new Promise(() => {}));
consono(async function helloWorld() {});
consono(async () => {});
consono(function* gen() { yield 1; });
consono([1, 2, 3]);
consono(Int8Array.from([1, 2, 3]));
consono(new ArrayBuffer(8));
consono(new SharedArrayBuffer(16));
consono(new Set(["a", true, { prop: 1 }]));
consono(new Map([["first", "a"], [true, "b"]]));
consono(new WeakMap());
consono(new WeakSet());
consono({});
class MyClass {} const myClass = new MyClass(); myClass.deeper = new
MyClass(); consono(myClass);
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"));
(function(a, b) { consono(arguments); })(true, false);
consono(global || globalThis, { objectMaxProps: 3 });
๐ฆ 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");