What is loupe?
The loupe npm package is a library that allows you to inspect JavaScript objects in a detailed and structured way. It is particularly useful for debugging and understanding complex structures by providing a clear visualization of the object's properties, including those that are not enumerable or are inherited through the prototype chain.
What are loupe's main functionalities?
Inspecting objects
This feature allows you to inspect JavaScript objects and see their structure and contents in a human-readable format. The code sample demonstrates how to use loupe to inspect a simple object.
const loupe = require('loupe');
console.log(loupe({ a: 1, b: { c: 2 } }));
Inspecting arrays
Loupe can also be used to inspect arrays, including nested arrays, to visualize their contents and structure.
const loupe = require('loupe');
console.log(loupe([1, 2, 3, [4, 5]]));
Inspecting functions
This feature is useful for inspecting functions, including their name, length (number of expected arguments), and code. The code sample shows how to inspect a simple function.
const loupe = require('loupe');
function exampleFunction() { return true; }
console.log(loupe(exampleFunction));
Inspecting prototypes
Loupe can inspect objects and their prototypes, revealing inherited properties. The code sample demonstrates inspecting an instance of a custom class.
const loupe = require('loupe');
function MyClass() { this.a = 1; }
MyClass.prototype.b = 2;
console.log(loupe(new MyClass()));
Other packages similar to loupe
util
The 'util' module in Node.js provides a method called 'inspect' which can be used to convert any object into a string representation. It is similar to loupe in that it helps with debugging and inspecting objects, but it is a built-in module and not a separate package.
pretty-format
The 'pretty-format' package is similar to loupe as it allows you to serialize JavaScript objects into a string with a pretty-printed format. It is often used in testing frameworks like Jest to format snapshots.
object-inspect
The 'object-inspect' package is another alternative that provides a way to inspect JavaScript objects and return a string representation. It is similar to loupe but offers different customization options for the output format.
loupe
Inspect utility for Node.js and browsers.
Usage
var inspect = require('loupe');
inspect({ foo: 'bar' });
inspect(1);
inspect('foo');
inspect([ 1, 2, 3 ]);
inspect(/Test/g);
Installation
npm:
npm install loupe
component:
component install chaijs/loupe
Standalone:
<script src="loupe.js></script>
Tests
$ npm test
Coverage:
$ npm run coverage
License
(The MIT License)
Copyright (c) 2011-2013 Jake Luer jake@alogicalparadox.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.