Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis.Learn more
Socket
Socket

read-pkg

Package Overview
Dependencies
4
Maintainers
1
Versions
14
Issues
File Explorer

Advanced tools

read-pkg

Read a package.json file

    8.0.0latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
38,182,902
increased by6.03%

Weekly downloads

Readme

Source

read-pkg

Read a package.json file

Why

  • Throws more helpful JSON errors
  • Normalizes the data

Install

npm install read-pkg

Usage

import {readPackage} from 'read-pkg'; console.log(await readPackage()); //=> {name: 'read-pkg', …} console.log(await readPackage({cwd: 'some-other-directory'})); //=> {name: 'unicorn', …}

API

readPackage(options?)

Returns a Promise<object> with the parsed JSON.

readPackageSync(options?)

Returns the parsed JSON.

options

Type: object

cwd

Type: URL | string
Default: process.cwd()

Current working directory.

normalize

Type: boolean
Default: true

Normalize the package data.

parsePackage(packageFile, options?)

Parses an object or string into JSON.

Note: packageFile is cloned using structuredClone to prevent modification to the input object. This function is available from Node.js 18 on. In environments without structuredClone (such as Node.js 16), a shallow spread is used instead, which can cause deep properties of the object to be modified. Consider cloning the object before using parsePackage if that's the case.

packageFile

Type: object | string\

An object or a stringified object to be parsed as a package.json.

options

Type: object

normalize

Type: boolean
Default: true

Normalize the package data.

Keywords

FAQs

Last updated on 07 Apr 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
Socket SOC 2 Logo

Product

  • Package Issues
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc