Show content of objects and arrays in the console. Its similar to print_r and var_dump from PHP.
npm install vdumper* Description
* Installation
* Usage
* Examples
* Params
* Show types (default:false)
* Show functions (default:false)
* Show small log (default:false)
* Circular objects
* Config
* Colors
* License
print the 'content' of an object / array in the console.
var_dump / print_r . Returns also result as a string.
bash
$ npm i vdumper
`
$3
require
`js
const vdumper = require("vdumper");
const dump = vdumper.dump;
`
$3
Printing basic variables
`js
num = 123;
str = "My name is Mykola Brozhyna";
test = null;
booleano = true;
NAN = NaN;
dump(num);
dump(str);
dump(test);
dump(booleano);
dump(NAN);
`
Console
`js
number: 123
string(26): "My name is Mykola Brozhyna"
object: null
boolean: true
number: NaN
`
Printing object
`js
test = function (){
return {
num: 123,
str: "My name is Mykola Brozhyna"
};
}
a = new test;
a.b = new test;
a.b.c = new test;
a.b.c.d = new test;
a.b.c.d.e = new test;
dump(a);
`
Console
`js
{
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[b] (3) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[c] (3) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[d] (3) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[e] (2) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
}
}
}
}
}
`
$3
By default it accepts 4 arguments.
`js
1 2 3 4
dump (any var , show types , show functions , show basic log)
dump (object ,(false / true) , (false / true) , (false / true) )
`
$3
You can also include types in the result
`js
dump (a,true);
`
Console ( Previous result bit with showTypes = true )
`shell
{
[num]=> 123 number
[str]=> "My name is Mykola Brozhyna" (26) string
object [b] (3) {
[num]=> 123 number
[str]=> "My name is Mykola Brozhyna" (26) string
object [c] (3) {
[num]=> 123 number
[str]=> "My name is Mykola Brozhyna" (26) string
object [d] (3) {
[num]=> 123 number
[str]=> "My name is Mykola Brozhyna" (26) string
object [e] (2) {
[num]=> 123 number
[str]=> "My name is Mykola Brozhyna" (26) string
}
}
}
}
}
`
$3
( You can also toggle function to show content of a function )
( First as showFunctions = false )
`js
var,showTypes,showFunctions
dump (a,false,false);
`
Console
`js
{
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[func]=> [Function]
[b] (4) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[func]=> [Function]
[c] (3) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[func]=> [Function]
}
}
}
`
( Now as showFunctions = true )
`js
var,showTypes,showFunctions
dump (a,false,true);
`
Console
`js
{
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[func]=> function (){
console.log("Oh yeah. It's all coming together.");
}
[b] (4) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[func]=> function (){
console.log("Oh yeah. It's all coming together.");
}
[c] (3) {
[num]=> 123
[str]=> "My name is Mykola Brozhyna" (26)
[func]=> function (){
console.log("Oh yeah. It's all coming together.");
}
}
}
}
`
$3
( You can also toggle log to see some small details about the result )
`js
dump (a,false,false,true);
`
Console
`js
--------------------------------
LOG: Start =>
[] (6){
[maxNestedLevelAllowed]=> 0
[maxNestedLvlFound]=> 4
[forced_log]=> false
[maxStepsAllowed]=> 0
[stepsFound]=> 4
[msg]=> ""
}
LOG: End
--------------------------------
`
$3
( It deals with most cases of circularity )
`js
test = function () {
return {
num: 123,
str: "My name is Mykola Brozhyna",
func: function () {
console.log("Oh yeah. It's all coming together.");
}
};
};
a = new test;
a.c = a;
a.b = new test;
a.b.a = a;
a.b.c = new test;
a.b.c.d = new test;
a.b.c.d.e = a.b.c.d;
`
Console
`js
[] (5){
[num]=> 123
[str]=> "My name is Mykola Brozhyna"
[func]=> [Function]
[c]=> [Circular]
b{
[num]=> 123
[str]=> "My name is Mykola Brozhyna"
[func]=> [Function]
[a]=> [Circular]
c{
[num]=> 123
[str]=> "My name is Mykola Brozhyna"
[func]=> [Function]
d{
[num]=> 123
[str]=> "My name is Mykola Brozhyna"
[func]=> [Function]
[e]=> [Circular]
}
}
}
}
`
$3
( Some configuration you can toy with)
Use vdumper.showConfig() to get config list.
`js
vdumper.config = {
showTypes: false, // default global setting for showing types
showFunctions: false, // default global setting for showing function
showLog: false, // default global setting for showing small log about last dump result
maxNestedLevel: 0, // max nested child level
print: true, // true means it will show dump result in consle
colorsLog: true, // colors log in case there was some error (occurs when setting custom colors )
bracketInNewLine: true, // brackets in new line (try it on same object to see for yourself :D)
spacer:" " // ( example below) (if not will be provided in the next updates)
};
`
( maxNestedLevel )
Consider the following example:
`js
var id = 0;
test = function () {
return {
id:id++,
str:"Abd Adwa awf awg "
};
};
a = new test;
a.b = new test;
a.b.c = new test;
`
With vdumper.config.maxNestedLevel = 0
(0 = default,means there is no maxNestedLevel)
Console
`js
[] (3){
[id]=> 0
[str]=> "Abd Adwa awf awg "
b{
[id]=> 1
[str]=> "Abd Adwa awf awg "
c{
[id]=> 2
[str]=> "Abd Adwa awf awg "
}
}
}
`
Now, lets say due to allot of information, you only want to get to b,
and ignore rest.
You can use vdumper.config.maxNestedLevel for that:
With vdumper.config.maxNestedLevel = 2 you get:
Console
`js
[] (3){
[id]=> 0
[str]=> "Abd Adwa awf awg "
b{
[id]=> 1
[str]=> "Abd Adwa awf awg "
c{ // Content of c is ignored because it is > (maxNestedLevel = 2)
}
}
}
`
It's quite usefull when you need to filter out some information.
( bracketInNewLine )
This one is self explanatory
false
`js
[b] (4) {
[num]=> 123
[str]=>
`
true
`js
[b] (4)
{
[num]=> 123
[str]=>
`
( spacer )
By default spacer is equal to " ";
so
`js
a = new test;
a.b = new test;
a.b.c = new test;
`
Results in:
`js
[] (3){
[id]=> 0
[str]=> "Abd Adwa awf awg "
b{
[id]=> 1
[str]=> "Abd Adwa awf awg "
c{
[id]=> 2
[str]=> "Abd Adwa awf awg "
}
}
}
`
Lets change spacer to spacer = "...":
`js
vdumper.config.spacer = "...";
`
Result:
`js
[] (3){
...[id]=> 0
...[str]=> "Abd Adwa awf awg "
...b{
......[id]=> 1
......[str]=> "Abd Adwa awf awg "
......c{
.........[id]=> 2
.........[str]=> "Abd Adwa awf awg "
......}
...}
}
`
You can toy with it to get some funny stuff.
( colorsLog: true )
In case you use custom non default color: if (true) it will yield a warning.
Set it to false to turn of.
`js
vdumper.config.colorsLog = false;
`
$3
vdumper supports coloring, both: ( array / object ) and variables.
Use vdumper.colors.showList(); to get list of default colors;
Use vdumper.single.showList(); to get list for single variable;
Use vdumper.object.showList(); to get list for object;
In order to change colors we use:
`js
let myColors = {
key:"red",
string:"green"
};
vdumper[single / object].setColors(myColors);
`
Or separated by space: "color bgcolor".
`js
let myColors = {
key:"red bgred",
string:"bgreen green"
};
vdumper[single / object].setColors(myColors);
``