package-json-editor

1.0.1 • Public • Published

package-json-editor

npm package editor that preserve newline and indentation

npm Travis npm

This is a mere wrapper around automerge so that we can use to edit npm package tree and preserve all the indentation, newline settings.

We can use this package to edit the tree directly using .set() method or we can edit the tree object directly and merge the new tree onto the old tree later with .merge().

Usage

var packageJsonEditor = require('package-json-editor')
 
var originTree = fs.readFileSync('./package.json', 'utf-8')
var mutated = JSON.parse(originTree)
mutated.dependencies.debug = '^1.0.0'
mutated.description = 'new description'
delete mutated.license
 
var newTree = packageJsonEditor(originTree)
    .merge(mutated)
    .toString()
 
// or
var anotherTree = packageJsonEditor(originTree)
    .set('dependencies.detect-indent', '^5.0.1')
    .toJSON()

API

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i package-json-editor

Weekly Downloads

128

Version

1.0.1

License

MIT

Unpacked Size

15.7 kB

Total Files

9

Last publish

Collaborators

  • tuananh