https://github.com/tobua/pakag
Format package.json file or contents.
https://github.com/tobua/pakag
Last synced: 3 months ago
JSON representation
Format package.json file or contents.
- Host: GitHub
- URL: https://github.com/tobua/pakag
- Owner: tobua
- Created: 2020-08-24T07:44:30.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-02-22T17:31:41.000Z (over 1 year ago)
- Last Synced: 2024-05-01T21:22:21.019Z (about 1 year ago)
- Language: TypeScript
- Homepage: https://npmjs.com/pakag
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pakag
Format package.json contents when working with it in node.
## Features
- Compatible with npm formatting
- Sorts properties## Usage
```js
import { readFileSync, writeFileSync } from 'fs'
import { join } from 'path'
import { formatPackageJson } from 'pakag'const packageJsonPath = join(process.cwd(), 'package.json')
const packageContents = readFileSync(packageJsonPath, 'utf8')
const formattedContents = await formatPackageJson(packageContents)
writeFileSync(packageJsonPath, formattedContents)
```To format the `package.json` in the current folder from the CLI run the following:
```sh
npx pakag
bunx pakag
```## Options
Options can be provided as the second parameter.
```js
await formatPackageJson(packageContents, {
// Sort properties using sort-package-json, default true.
sort: false,
// Customize sort order for package.json keys, default order see index.js.
sortOrder: ['version'],
})
```