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

rocktimsaikia

Rocktim Saikia

Posted on October 4, 2020

✨ 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 🦄 👋]

💖 💪 🙅 🚩
rocktimsaikia
Rocktim Saikia

Posted on October 4, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

tsParticles 3.0.1 Released
typescript tsParticles 3.0.1 Released

December 6, 2023

tsParticles 2.12.0 Released
typescript tsParticles 2.12.0 Released

August 4, 2023

tsParticles 2.11.0 Released
typescript tsParticles 2.11.0 Released

July 12, 2023