1.3.0 • Published 4 years ago

read-packages v1.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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