Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
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.
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()));
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.
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.
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 turns the object you give it into a string. It's similar to Node.js' util.inspect()
function, but it works cross platform, in most modern browsers as well as Node.
loupe
is available on npm. To install it, type:
$ npm install loupe
You can also use it within the browser; install via npm and use the loupe.js
file found within the download. For example:
<script src="./node_modules/loupe/loupe.js"></script>
const { inspect } = require('loupe');
inspect({ foo: 'bar' }); // => "{ foo: 'bar' }"
inspect(1); // => '1'
inspect('foo'); // => "'foo'"
inspect([ 1, 2, 3 ]); // => '[ 1, 2, 3 ]'
inspect(/Test/g); // => '/Test/g'
// ...
$ npm test
Coverage:
$ npm run upload-coverage
(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.
FAQs
Inspect utility for Node.js and browsers
The npm package loupe receives a total of 9,993,198 weekly downloads. As such, loupe popularity was classified as popular.
We found that loupe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.