DEV Community

Rocktim Saikia
Rocktim Saikia

Posted on

✨ read-packages : a simple package that returns the dependencies of a package.json file.

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
Enter fullscreen mode Exit fullscreen mode

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',...}
})();
Enter fullscreen mode Exit fullscreen mode

GitHub logo rocktimsaikia / read-packages

Read dependencies of a package.json file.

read-packages build license

Read dependencies of a package.json file.

Install

npm install read-packages
Enter fullscreen mode Exit fullscreen mode

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',...}
})();
Enter fullscreen mode Exit fullscreen mode

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.
Enter fullscreen mode Exit fullscreen mode

[PS: Thought someone might find it a handy tool so I made a quick post. Thanks for reading 🦄 👋]

Top comments (2)

Collapse
 
rajasekharguptha profile image
Rajasekhar Guptha

Cool😍

Collapse
 
rocktimsaikia profile image
Rocktim Saikia

Thank you 🙏