bosom

2.0.0 • Public • Published

bosom

npm version

bosom is a Node.JS package which can read and write JSON files easily. It can be used to record and update configurations as serialised JSON data.

yarn add bosom

API

The package is available by importing its default function:

import bosom from '@rqt/namecheap-web'

async bosom(
  path: string,
  data=: Object,
  options=: Options,
): string|void

The function which can be used for both reading and writing of data. When only a single argument is passed, the read mode is assumed. To write data, it should be passed as the second argument, with an optional config.

bosom will read the file when only a path is passed.

/* eslint-disable no-console */
import bosom from 'bosom'
import { resolve } from 'path'
 
(async () => {
  try {
    const p = resolve(__dirname, 'example.json')
    const res = await bosom(p)
    console.log(res)
  } catch (err) {
    console.error(err)
  }
})()
t
{ hello: 'world', foo: true, bar: -1 }

When data is passed, bosom will write into that file the serialised version of the object. An optional configuration can be passed along to the JSON.stringify method.

_bosom.Options: Options for writing.

Name Type & Description
space number
How many spaces to use for indentation.
replacer !Function
The replacer function used when serializing data (see JSON.stringify documentation).
/* eslint-disable no-console */
import bosom from 'bosom'
import { resolve } from 'path'
 
(async () => {
  try {
    const p = resolve(__dirname, 'temp.json')
    await bosom(p, {
      'my-data': true,
      bar: 'foo',
    }, {
      space: 2,
    })
 
    // test the written value
    const actual = require(p)
    console.log(actual)
  } catch (err) {
    console.error(err)
  }
})()
t
{ 'my-data': true, bar: 'foo' }

Copyright

Readme

Keywords

Package Sidebar

Install

npm i bosom

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

36.5 kB

Total Files

14

Last publish

Collaborators

  • zvr