json-chain

0.0.3 • Public • Published

🎀⛓ json-chain

fluent chaining for json with dot-prop access

NPM version MIT License fliphub flipfam

📦 usage

yarn add json-chain
npm i json-chain --save
const JSONChain = require('json-chain')

📘 examples

const data = {
  eh: ['og'],
  canada: true,
}
 
const chain = JSONChain.init(data).update('eh', ['some values'])

👓 reading json file

const {readFileSync} = require('fs')
 
const pkg = readFileSync('./package.json', 'utf8')
const chain = new JSONChain(pkg)
  .parse() // will be done automatically, is optional
  .set('eh', ['some values']) // also as .update
  .del('eh') // also as .delete, .remove
 
// also as .val
const test = chain.get('scripts.test')
const has = chain.has('version')

✍ writing to file

  • has .toString and .toJSON methods for auto-stringifying when cast to string or JSON.stringify

👾 keep it simple

const chain = new JSONChain(pkg)
  .updateIfNotEmpty('scripts.test', 'ava --verbose')
  .updateIfNotEmpty('scripts.devDependencies', {'ava': '*'})
  .write()

Package Sidebar

Install

npm i json-chain

Weekly Downloads

2

Version

0.0.3

License

MIT

Last publish

Collaborators

  • aretecode