open-index/open-npm huggingface dataset:
npm package: @map-colonies/read-pkg
Description: This is a helper for reading and parsing package json files
Latest version: 2.0.0

# read-pkg

A lightweight utility to read and parse package.json files synchronously.

## Installation

```bash
npm install @mapcolonies/read-pkg
```

## Usage

```typescript
import { readPackageJsonSync } from '@map-colonies/read-pkg';

// Read package.json from current directory
const packageJson = readPackageJsonSync();
console.log(packageJson.name);

// Read package.json from specific path
const otherPackageJson = readPackageJsonSync('./path/to/package.json');
console.log(otherPackageJson.version);
```

## API
Check the autogenerated documentation [here](https://mapcolonies.github.io/infra-packages/modules/_map-colonies_read-pkg.html).

### readPackageJsonSync(path?: string, encoding?: BufferEncoding): PackageJson

Synchronously reads and parses a package.json file.

#### Parameters

- `path` (optional): Path to the package.json file. Defaults to `'./package.json'`
- `encoding` (optional): File encoding to use. Defaults to `'utf-8'`

#### Returns

Returns a `PackageJson` object from the [type-fest](https://github.com/sindresorhus/type-fest) package.

#### Throws

- `SyntaxError`: If the JSON content is invalid
- `Error`: If the file cannot be read or does not exist