1.0.1 • Published 6 years ago

package-json-editor v1.0.1

Weekly downloads
135
License
MIT
Repository
-
Last release
6 years ago

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