Socket
Socket
Sign inDemoInstall

write-pkg

Package Overview
Dependencies
12
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    write-pkg

Write a package.json file


Version published
Maintainers
1
Install size
200 kB
Created

Readme

Source

write-pkg Build Status

Write a package.json file

Writes atomically and creates directories for you as needed. Sorts dependencies when writing. Preserves the indentation if the file already exists.

Install

$ npm install write-pkg

Usage

const path = require('path');
const writePackage = require('write-pkg');

(async () => {
	await writePackage({foo: true});
	console.log('done');

	await writePackage(__dirname, {foo: true});
	console.log('done');

	await writePackage(path.join('unicorn', 'package.json'), {foo: true});
	console.log('done');
})();

API

writePackage([path], data, [options])

Returns a Promise.

writePackage.sync([path], data, [options])

path

Type: string
Default: process.cwd()

Path to where the package.json file should be written or its directory.

options

Type: object

normalize

Type: boolean
Default: true

Remove empty dependencies, devDependencies, optionalDependencies and peerDependencies objects.

  • read-pkg - Read a package.json file
  • write-json-file - Stringify and write JSON to a file atomically

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 29 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc