I wrote a simple module that returns the dependencies
of a package.json
file.
It has some additional options that you can pass in. Check the project readme
for more info.
Installation
npm install read-packages
Usage
const readPackages = require('read-packages');
(async()=>{
console.log(await readPackages());
//=> {dependencies: {foo: '^1.0.0',..}, devDependencies: {bar: '^2.0.0',...}}
console.log(await readPackages({dir: './some/other/directory'}));
//=> {dependencies: {...}, devDependencies: {...}}
console.log(await readPackages({removePrefix: true}));
//=> {dependencies: {foo: '1.0.0',..}, devDependencies: {bar: '2.0.0',...}}
console.log(await readPackages({removePrefix: true, flattenPackages: true}));
//=> {foo: '1.0.0',bar: '2.0.0',...}
})();
rocktimsaikia / read-packages
Read dependencies of a package.json file.
Read dependencies of a package.json file.
Install
npm install read-packages
Usage
const readPackages = require('read-packages');
(async()=>{
console.log(await readPackages());
//=> {dependencies: {foo: '^1.0.0',..}, devDependencies: {bar: '^2.0.0',...}}
console.log(await readPackages({dir: './some/other/directory'}));
//=> {dependencies: {...}, devDependencies: {...}}
console.log(await readPackages({removePrefix: true}));
//=> {dependencies: {foo: '1.0.0',..}, devDependencies: {bar: '2.0.0',...}}
console.log(await readPackages({removePrefix: true, flattenPackages: true}));
//=> {foo: '1.0.0',bar: '2.0.0',...}
})();
Usage without async
The module has a sync
property to use the lib without async. All the other options works just the same.
const readPackages = require('read-packages');
console.log(readPackages.
…[PS: Thought someone might find it a handy tool so I made a quick post. Thanks for reading 🦄 👋]
Top comments (2)
Cool😍
Thank you 🙏