GithubHelp home page GithubHelp logo

read-pkg's Introduction

read-pkg

Read a package.json file

Why

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.

Related

read-pkg's People

Contributors

bendingbender avatar coreyfarrell avatar fisker avatar richienb avatar roeybiran avatar simenb avatar sindresorhus avatar stevemao avatar tommy-mitchell avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.