JSPM

json-chain

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q32595F
  • License MIT

fluent chaining for json with dot-prop access

Package Exports

  • json-chain

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-chain) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

🎀⛓ 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()