isotropic-console
v0.4.0
Published
A preconfigured Console with deep, sorted, unabridged inspection output
Downloads
28
Maintainers
Readme
isotropic-console
A pre-configured Node.js console object with enhanced inspection settings and natural sorting of object properties.
Why Use This?
- Consistent Output: Standardized console output formatting across your applications
- Natural Sorting: Object properties are sorted naturally (e.g., "item2" before "item10")
- Unlimited Depth: Full inspection of nested objects with unlimited depth
- Improved Readability: Non-compact format with unlimited line length for better log readability
- Drop-in Replacement: Works as a direct replacement for the standard Node.js console
Installation
npm install isotropic-consoleUsage
import _console from 'isotropic-console';
// Use just like the standard console
_console.log('Hello world');
// Complex objects are displayed with enhanced formatting
_console.log({
deeply: {
nested: {
object: {
with: [
'many',
'properties',
{
that: 'would normally be truncated'
}
]
}
}
}
});
// Object properties are sorted naturally
_console.log({
item10: 'value',
item2: 'value',
item1: 'value'
});
// Output order: item1, item2, item10Features
Enhanced Object Inspection
The console is configured with the following inspection options:
breakLength: Infinity- No arbitrary line breaks in outputcolors: false- No ANSI color codes are added when inspecting objectscompact: false- Full, readable formatting rather than compressedcustomInspect: true- Respects custom [util.inspect.custom] implementationsdepth: Infinity- No depth limitation for nested objectsgetters: false- Getters are not invoked during inspectionmaxArrayLength: Infinity- Arrays are not truncatedshowHidden: false- Non-enumerable properties are not shownshowProxy: false- Proxy internals are not revealedsorted- Object properties are sorted using a natural sort comparator
Natural Sorting
Object properties are sorted using the isotropic-natural-sort module, which ensures that:
- Properties are sorted alphabetically but in a human-friendly way
- Numeric parts of property names are sorted numerically (e.g., "prop2" before "prop10")
- Sorting is case-insensitive by default
Standard Console API
All standard console methods are available:
console.log(),console.info(),console.debug()- Output to stdoutconsole.error(),console.warn()- Output to stderrconsole.dir()- Object inspectionconsole.table()- Display objects in tabular formatconsole.time(),console.timeEnd()- Timing operations- And all other methods from Node.js Console
Examples
Logging Objects with Natural Property Order
import _console from 'isotropic-console';
_console.log({
z: 1,
a: 2,
item10: 3,
item2: 4,
item1: 5
});
// Output:
// {
// a: 2,
// item1: 5,
// item2: 4,
// item10: 3,
// z: 1
// }Inspecting Deeply Nested Objects
import _console from 'isotropic-console';
const _deepObject = {
level1: {
level2: {
level3: {
level4: {
data: [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
]
}
}
}
}
};
_console.log(_deepObject);
// Output will show the complete object with all nesting levels
// and the full array, unlike standard console which would truncateUsing as the Global Console
Because it is a real Console instance, isotropic-console can replace the global console so that every console.* call in your application uses the enhanced settings:
import _console from 'isotropic-console';
globalThis.console = _console;
console.log({
item10: 'value',
item2: 'value',
item1: 'value'
});It can also be handed to any library or function that accepts a Console-compatible object.
Contributing
Please refer to CONTRIBUTING.md for contribution guidelines.
Issues
If you encounter any issues, please file them at https://github.com/ibi-group/isotropic-console/issues
