Skip to content

sindresorhus/read-pkg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Nov 16, 2023
a3732e2 · Nov 16, 2023

History

49 Commits
Nov 16, 2023
Apr 7, 2023
Nov 4, 2017
Jun 25, 2018
Nov 4, 2017
Nov 4, 2017
Aug 22, 2023
Nov 16, 2023
Apr 7, 2023
Mar 28, 2021
Nov 16, 2023
Nov 16, 2023

Repository files navigation

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.

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