How to use multiple helpers in handlebars - nested

I have written two helpers namely i18n and toLowerCase as following:
/*
* Returns lowercase of a string
*/
Handlebars.registerHelper('toLowerCase', function(value) {
if (value && typeof value === 'string') {
return value.toLowerCase();
} else {
return '';
}
});
I have a string which should be converted to lowercase first and then should be localized using i18n helper. Both these helpers work/run fine.
These lines are working fine. (Tested)
{{toLowerCase status }}
{{i18n status}}
But I want something like this.I have tried this:
{{i18n {{toLowerCase status }} }}
But this throws syntax error as
Uncaught Error: Parse error on line 88:
..div> {{ i18n {{toLowerCase stat
----------------------^
Expecting 'CLOSE', 'CLOSE_UNESCAPED', 'STRING', 'INTEGER', 'BOOLEAN', 'ID', 'DATA', 'SEP', got 'OPEN'
Any suggestions ?

Handlesbars supports Subexpressions now, so you could just do:
{{i18n (toLowerCase status) }}
(notice, those are parens (), not curly braces {}, for the inside helper)

You could try using https://github.com/mateusmaso/handlebars.nested (be aware that it allows only one level of nesting, though). As far as I know, there's no built-in support on Handlebars for this, though you can use some of the workarounds in the question I linked in comments.

Related

json_agg result from NodeJS application code is different than the same query in pgAdmin [duplicate]

I have this object:
const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
But when I try to show it using console.log(myObject), I receive this output:
{ a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }
How can I get the full object, including the content of property f?
You need to use util.inspect():
const util = require('util')
console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true}))
// alternative shortcut
console.log(util.inspect(myObject, false, null, true /* enable colors */))
Outputs
{ a: 'a', b: { c: 'c', d: { e: 'e', f: { g: 'g', h: { i: 'i' } } } } }
You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.
console.log(JSON.stringify(myObject, null, 4));
{
"a": "a",
"b": {
"c": "c",
"d": {
"e": "e",
"f": {
"g": "g",
"h": {
"i": "i"
}
}
}
}
}
The third argument sets the indentation level, so you can adjust that as desired.
More detail here in JSON stringify MDN docs if needed.
A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer). Tip of the hat to Rory O'Kane for his help.
tl;dr
To get the desired output for the example in the question, use console.dir():
console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion
Why not util.inspect()? Because it’s already at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly. It’s generally not necessary to require('util') and call util.inspect() directly.
Details below.
console.log() (and its alias, console.info()):
If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:
o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'
Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:
Structural depth of the output is limited to 2 levels (the default).
Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.
You can’t turn syntax coloring on.
If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:
o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'
Note:
There is NO placeholder for representing objects util.inspect()-style.
JSON generated with %j is NOT pretty-printed.
console.dir():
Accepts only 1 argument to inspect, and always applies util.inspect() – essentially, a wrapper for util.inspect() without options by default; e.g.:
o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.
Node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() – see below; e.g.:
console.dir({ one: 1, two: 'deux'}, { colors: true }); // Node 0.11+: Prints object representation with syntax coloring.
The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;
i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:
o = { one: 1, two: 'deux', foo: function(){} } // The REPL echoes the object definition with syntax coloring.
util.inspect() automatically pretty-prints object and array representations, but produces multiline output only when needed.
The pretty-printing behavior can be controlled by the compact property in the optional options argument; false uses multi-line output unconditionally, whereas true disables pretty-printing altogether; it can also be set to a number (the default is 3) to control the conditional multi-line behavior – see the docs.
By default, output is wrapped at around 60 characters thanks, Shrey
, regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).
In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.
If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:
Fails with objects that have circular references, such as module in the global context.
Methods (functions) will by design NOT be included.
You can't opt into showing hidden (non-enumerable) properties.
Example call:
JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces
util.inspect() options object (2nd argument):
An optional options object may be passed that alters certain aspects of the formatted string; some of the properties supported are:
See the latest Node.js docs for the current, full list.
showHidden
if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.
depth
tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.
colors
if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [… – see link].
customInspect
if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.
util.format() format-string placeholders (1st argument)
Some of the supported placeholders are:
See the latest Node.js docs for the current, full list.
%s – String.
%d – Number (both integer and float).
%j – JSON.
%% – single percent sign (‘%’). This does not consume an argument.
Another simple method is to convert it to json
console.log('connection : %j', myObject);
Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:
require("util").inspect.defaultOptions.depth = null;
console.log(myObject);
Try this:
console.dir(myObject,{depth:null})
Both of these usages can be applied:
// more compact, and colour can be applied (better for process managers logging)
console.dir(queryArgs, { depth: null, colors: true });
// get a clear list of actual values
console.log(JSON.stringify(queryArgs, undefined, 2));
perhaps console.dir is all you need.
http://nodejs.org/api/console.html#console_console_dir_obj
Uses util.inspect on obj and prints resulting string to stdout.
use util option if you need more control.
A good way to inspect objects is to use node --inspect option with Chrome DevTools for Node.
node.exe --inspect www.js
Open chrome://inspect/#devices in chrome and click Open dedicated DevTools for Node
Now every logged object is available in inspector like regular JS running in chrome.
There is no need to reopen inspector, it connects to node automatically as soon as node starts or restarts. Both --inspect and Chrome DevTools for Node may not be available in older versions of Node and Chrome.
You can also do
console.log(JSON.stringify(myObject, null, 3));
I think this could be useful for you.
const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
console.log(JSON.stringify(myObject, null, '\t'));
As mentioned in this answer:
JSON.stringify's third parameter defines white-space insertion for
pretty-printing. It can be a string or a number (number of spaces).
JSON.stringify()
let myVar = {a: {b: {c: 1}}};
console.log(JSON.stringify( myVar, null, 4 ))
Great for deep inspection of data objects. This approach works on nested arrays and nested objects with arrays.
You can simply add an inspect() method to your object which will override the representation of object in console.log messages
eg:
var myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }
then, your object will be represented as required in both console.log and node shell
Update:
object.inspect has been deprecated ( https://github.com/nodejs/node/issues/15549). Use myObject[util.inspect.custom] instead:
const util = require('util')
var myObject = {
/* nested properties not shown */
}
myObject[util.inspect.custom] = function(){ return JSON.stringify( this, null, 4 ); }
console.log(util.inspect(myObject))
Use a logger
Don't try to reinvent the wheel
util.inspect(), JSON.stringify() and console.dir() are useful tools for logging an object while playing in the browser console.
If you are serious about Node.js development, you should definitely use a logger. Using it you can add all the logs you want for debugging and monitoring your application. Then just change the logging level of your logger to keep only the production logs visible.
Additionaly they have already solved all the annoying issues related to logging, like: circular objects, formatting, log levels, multiple outputs and performance.
Use a modern logger
pino is a fast and modern logger for Node.js that has sane defaults to handle circular object/references like depthLimit and edgeLimit. It supports child loggers, transports and a pretty printed output.
Moreover, it has 8 default logging levels that you can customize using the customLevels option:
fatal
error
warn
info
debug
trace
silent
Install it
npm install pino
Use it
const logger = require('pino')()
logger.info('hello world')
Configure it
const logger = pino({
depthLimit: 10,
edgeLimit: 200,
customLevels: {
foo: 35
}
});
logger.foo('hi')
A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script
Ex.
DEBUG=* DEBUG_DEPTH=null node index.js
In you code
const debug = require('debug');
debug("%O", myObject);
If you're looking for a way to show the hidden items in you array, you got to pass maxArrayLength: Infinity
console.log(util.inspect(value, { maxArrayLength: Infinity }));
The node REPL has a built-in solution for overriding how objects are displayed, see here.
The REPL module internally uses util.inspect(), when printing values.
However, util.inspect delegates the call to the object's inspect()
function, if it has one.
Easiest option:
console.log('%O', myObject);
const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
console.log(JSON.stringify(myObject));
Output:
{"a":"a","b":{"c":"c","d":{"e":"e","f":{"g":"g","h":{"i":"i"}}}}}

Unable to add event listener to webNavigation.onCompleted

Using the mock function below along with the dev console:
This call will work:
chrome.webNavigation.onCompleted.addListener(processWebNavChange, filtera);
but when I actually pass in my real var filter it throws this error:
Uncaught TypeError: Could not add listener
My actual data looks like this:
{
url: [ {hostContains: ".im88rmbOwZ"} ]
}
function registerWebNavListener() {
var matchers = getUrlMatchers();
var filter = {
url: matchers
};
// test with mock data filtera that actually works
const filtera = {
url:
[
{hostContains: "example.com"},
]
}
if (matchers.length > 0) {
chrome.webNavigation.onCompleted.addListener(processWebNavChange, filtera);
}
}
async function processWebNavChange(data) {
}
Is there something wrong with my data structure that I'm actually using? I don't believe that the filter object I returned is incorrect
}
EDIT:
I added a new
const filterb = {
url: [ {hostContains: ".im88rmbOwZ"} ]
};
and it still fails with that. The single entry {hostContains: ".im88rmbOwZ"}, was the first item returned from getURLMatchers() which I used as an example of real data being returned.
The above comment on the upper-case letters was the cause of the issue. Converting everything to lowercase resolved the problem.
Although, I am not clear as to why that was a problem to begin with. (If there are any hints in the chromium source code event filter handlers, I'd appreciate it if it could be pointed out).

Typescript Array.filter empty return

Problem statement
I've got problem with an object array I would like to get a sub object array from based on a object property. But via the Array.filter(lambda{}) all I get is an empty list.
The object is like:
export interface objectType1 {
someName: number;
someOtherName: string;
}
export interface ObjectType2 {
name: string;
other: string;
ObjectType1: [];
}
The method to get the subArray is:
private getSubArray(toDivied: ObjectType2[], propertyValue: string){
let list: ObjectType2[] = toDivied.filter((row:ObjectType2) => {
row.name === propertyValue
});
return list;
}
Analys
Namely two things been done ensure filter comparing works and that the data is "as expected".
Brekepoints in visual studio code
Via break points in the return and filter compareison I've inspected that the property value exists (by conditions on the break point) and that the "list" which is returned is empty.
I would like to point out that I use a Typescript linter which usally gives warning for the wrong types and undefined variable calls and such so I am quite sure it shouldn't be an syntax problem.
Tested via javascript if it works in chrome console
remove braces inside callback function
private getSubArray(toDivied: ObjectType2[], propertyValue: string){
let list: ObjectType2[] = toDivied.filter((row:ObjectType2) =>
row.name === propertyValue
);
return list;
}

Proper way to parse environment variables

I am using node-config in basically all my projects and most of the time I come across the problem of parsing booleans and numbers which are set as environment variables.
E.g.
default.js
module.exports = {
myNumber = 10,
myBool = true
}
custom-environment-variables.js
module.exports = {
myNumber = "MY_NUMBER",
myBool = "MY_BOOL"
}
Now, the obvious problem is that if I override the default values with custom values set as environment variables they will be a string value instead of a number or boolean value. So now, to make sure in my code that the types are correct. I always have to do type conversion and for booleans use a proper library e.g. yn. The problem is I have to do this conversion every time I use config.get() for example +config.get("myNumber") or yn(config.get("myBool")).
Is there a better and more elegant way to do this?
One solution I see would be to add a type property to an environment variable as it is done here with format. This would allow to do something like this...
custom-environment-variables.js
module.exports = {
myNumber = {
name: "MY_NUMBER",
type: "number"
},
myBool = {
name: "MY_BOOL",
type: "boolean"
}
}
node-config would handle the type conversions and there would be no need to do it all the time in the code when getting it. Of course there would be the requirement to implement a proper parser for booleans but those already exist and could be used here.
By default, environment variables will be parsed as string.
In node-config, we could override this behaviour with __format as shown below.
We don't need any additional libraries. Normal json datatypes like boolean, number, nested json etc., should work well.
Taking an easy to relate example.
config/default.json
{
"service": {
"autostart": false
}
}
custom-environment-variables.json
{
"service": {
"autostart": {
"__name": "AUTOSTART",
"__format": "json"
}
}
}
Now we can pass environment variables when we like to override and no type conversation should be needed for basic types.
This feature is now supported in node-config v3.3.2, see changelog
I use this method:
const toBoolean = (dataStr) => {
return !!(dataStr?.toLowerCase?.() === 'true' || dataStr === true);
};
You can add cases if you want 0 to resolve to true as well:
const toBoolean = (dataStr) => {
return !!(dataStr?.toLowerCase?.() === 'true' || dataStr === true || Number.parseInt(dataStr, 10) === 0);
};

Query nested objects mongoose [duplicate]

I have this object:
const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
But when I try to show it using console.log(myObject), I receive this output:
{ a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }
How can I get the full object, including the content of property f?
You need to use util.inspect():
const util = require('util')
console.log(util.inspect(myObject, {showHidden: false, depth: null, colors: true}))
// alternative shortcut
console.log(util.inspect(myObject, false, null, true /* enable colors */))
Outputs
{ a: 'a', b: { c: 'c', d: { e: 'e', f: { g: 'g', h: { i: 'i' } } } } }
You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.
console.log(JSON.stringify(myObject, null, 4));
{
"a": "a",
"b": {
"c": "c",
"d": {
"e": "e",
"f": {
"g": "g",
"h": {
"i": "i"
}
}
}
}
}
The third argument sets the indentation level, so you can adjust that as desired.
More detail here in JSON stringify MDN docs if needed.
A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer). Tip of the hat to Rory O'Kane for his help.
tl;dr
To get the desired output for the example in the question, use console.dir():
console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion
Why not util.inspect()? Because it’s already at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly. It’s generally not necessary to require('util') and call util.inspect() directly.
Details below.
console.log() (and its alias, console.info()):
If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:
o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'
Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:
Structural depth of the output is limited to 2 levels (the default).
Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.
You can’t turn syntax coloring on.
If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:
o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'
Note:
There is NO placeholder for representing objects util.inspect()-style.
JSON generated with %j is NOT pretty-printed.
console.dir():
Accepts only 1 argument to inspect, and always applies util.inspect() – essentially, a wrapper for util.inspect() without options by default; e.g.:
o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.
Node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() – see below; e.g.:
console.dir({ one: 1, two: 'deux'}, { colors: true }); // Node 0.11+: Prints object representation with syntax coloring.
The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;
i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:
o = { one: 1, two: 'deux', foo: function(){} } // The REPL echoes the object definition with syntax coloring.
util.inspect() automatically pretty-prints object and array representations, but produces multiline output only when needed.
The pretty-printing behavior can be controlled by the compact property in the optional options argument; false uses multi-line output unconditionally, whereas true disables pretty-printing altogether; it can also be set to a number (the default is 3) to control the conditional multi-line behavior – see the docs.
By default, output is wrapped at around 60 characters thanks, Shrey
, regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).
In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.
If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:
Fails with objects that have circular references, such as module in the global context.
Methods (functions) will by design NOT be included.
You can't opt into showing hidden (non-enumerable) properties.
Example call:
JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces
util.inspect() options object (2nd argument):
An optional options object may be passed that alters certain aspects of the formatted string; some of the properties supported are:
See the latest Node.js docs for the current, full list.
showHidden
if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.
depth
tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.
colors
if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [… – see link].
customInspect
if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.
util.format() format-string placeholders (1st argument)
Some of the supported placeholders are:
See the latest Node.js docs for the current, full list.
%s – String.
%d – Number (both integer and float).
%j – JSON.
%% – single percent sign (‘%’). This does not consume an argument.
Another simple method is to convert it to json
console.log('connection : %j', myObject);
Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:
require("util").inspect.defaultOptions.depth = null;
console.log(myObject);
Try this:
console.dir(myObject,{depth:null})
Both of these usages can be applied:
// more compact, and colour can be applied (better for process managers logging)
console.dir(queryArgs, { depth: null, colors: true });
// get a clear list of actual values
console.log(JSON.stringify(queryArgs, undefined, 2));
perhaps console.dir is all you need.
http://nodejs.org/api/console.html#console_console_dir_obj
Uses util.inspect on obj and prints resulting string to stdout.
use util option if you need more control.
A good way to inspect objects is to use node --inspect option with Chrome DevTools for Node.
node.exe --inspect www.js
Open chrome://inspect/#devices in chrome and click Open dedicated DevTools for Node
Now every logged object is available in inspector like regular JS running in chrome.
There is no need to reopen inspector, it connects to node automatically as soon as node starts or restarts. Both --inspect and Chrome DevTools for Node may not be available in older versions of Node and Chrome.
You can also do
console.log(JSON.stringify(myObject, null, 3));
I think this could be useful for you.
const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
console.log(JSON.stringify(myObject, null, '\t'));
As mentioned in this answer:
JSON.stringify's third parameter defines white-space insertion for
pretty-printing. It can be a string or a number (number of spaces).
JSON.stringify()
let myVar = {a: {b: {c: 1}}};
console.log(JSON.stringify( myVar, null, 4 ))
Great for deep inspection of data objects. This approach works on nested arrays and nested objects with arrays.
You can simply add an inspect() method to your object which will override the representation of object in console.log messages
eg:
var myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }
then, your object will be represented as required in both console.log and node shell
Update:
object.inspect has been deprecated ( https://github.com/nodejs/node/issues/15549). Use myObject[util.inspect.custom] instead:
const util = require('util')
var myObject = {
/* nested properties not shown */
}
myObject[util.inspect.custom] = function(){ return JSON.stringify( this, null, 4 ); }
console.log(util.inspect(myObject))
Use a logger
Don't try to reinvent the wheel
util.inspect(), JSON.stringify() and console.dir() are useful tools for logging an object while playing in the browser console.
If you are serious about Node.js development, you should definitely use a logger. Using it you can add all the logs you want for debugging and monitoring your application. Then just change the logging level of your logger to keep only the production logs visible.
Additionaly they have already solved all the annoying issues related to logging, like: circular objects, formatting, log levels, multiple outputs and performance.
Use a modern logger
pino is a fast and modern logger for Node.js that has sane defaults to handle circular object/references like depthLimit and edgeLimit. It supports child loggers, transports and a pretty printed output.
Moreover, it has 8 default logging levels that you can customize using the customLevels option:
fatal
error
warn
info
debug
trace
silent
Install it
npm install pino
Use it
const logger = require('pino')()
logger.info('hello world')
Configure it
const logger = pino({
depthLimit: 10,
edgeLimit: 200,
customLevels: {
foo: 35
}
});
logger.foo('hi')
A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script
Ex.
DEBUG=* DEBUG_DEPTH=null node index.js
In you code
const debug = require('debug');
debug("%O", myObject);
If you're looking for a way to show the hidden items in you array, you got to pass maxArrayLength: Infinity
console.log(util.inspect(value, { maxArrayLength: Infinity }));
The node REPL has a built-in solution for overriding how objects are displayed, see here.
The REPL module internally uses util.inspect(), when printing values.
However, util.inspect delegates the call to the object's inspect()
function, if it has one.
Easiest option:
console.log('%O', myObject);
const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
console.log(JSON.stringify(myObject));
Output:
{"a":"a","b":{"c":"c","d":{"e":"e","f":{"g":"g","h":{"i":"i"}}}}}

Resources