read-pkg

  • Version 9.0.1
  • Published
  • 6.92 kB
  • 5 dependencies
  • MIT license

Install

npm i read-pkg
yarn add read-pkg
pnpm add read-pkg

Overview

Read a package.json file

Index

Functions

function parsePackage

parsePackage: {
(
packageFile: PackageJson | string,
options?: NormalizeParseOptions
): NormalizedPackageJson;
(packageFile: any, options: ParseOptions): typeFestPackageJson;
};

    function readPackage

    readPackage: {
    (options?: NormalizeOptions): Promise<NormalizedPackageJson>;
    (options: Options): Promise<typeFestPackageJson>;
    };
    • Returns

      The parsed JSON.

      Example 1

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

    function readPackageSync

    readPackageSync: {
    (options?: NormalizeOptions): NormalizedPackageJson;
    (options: Options): typeFestPackageJson;
    };
    • Returns

      The parsed JSON.

      Example 1

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

    Type Aliases

    type NormalizedPackageJson

    type NormalizedPackageJson = PackageJson & normalizePackage;

      type NormalizeOptions

      type NormalizeOptions = _NormalizeOptions & Options;

        type NormalizeParseOptions

        type NormalizeParseOptions = _NormalizeOptions & ParseOptions;

          type Options

          type Options = {
          /**
          Current working directory.
          @default process.cwd()
          */
          readonly cwd?: URL | string;
          /**
          [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
          @default true
          */
          readonly normalize?: boolean;
          };

            type PackageJson

            type PackageJson = typeFestPackageJson;

              type ParseOptions

              type ParseOptions = Omit<Options, 'cwd'>;

                Package Files (1)

                Dependencies (5)

                Dev Dependencies (3)

                Peer Dependencies (0)

                No peer dependencies.

                Badge

                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/read-pkg.

                • Markdown
                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/read-pkg)
                • HTML
                  <a href="https://www.jsdocs.io/package/read-pkg"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>