read-packages

Reads dependencies of a package.json file

Usage no npm install needed!

<script type="module">
  import readPackages from 'https://cdn.skypack.dev/read-packages';
</script>

README

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