read-packages
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

read-packages build license

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.sync());
//=> {dependencies: {foo: '^1.0.0',..}, devDependencies: {bar: '^2.0.0',...}}

API

readPackages(options?)

Returns a Promise<object> with the parsed dependencies/devDependencies.

readPackages.sync(options?)

Returns the parsed dependencies/devDependencies.

options

dir

Type: string
Default: process.cwd()

Current working directory.

removePrefix

Type: boolean
Default: false

Removes the dependency version prefixes (^,~,*).

flattenPackages

Type: boolean
Default: false

Flattens all types dependencies into a single object.

Related

  • package-outdated - Returns the outdated packages of a package.json file
  • flatify-obj - Flatten javascript objects into a single-depth object

Support

Package Sidebar

Install

npm i read-packages

Weekly Downloads

3

Version

1.3.0

License

MIT

Unpacked Size

7.39 kB

Total Files

5

Last publish

Collaborators

  • rocktimsaikia