https://github.com/artdecocode/bosom
Read and write a JSON file in Node.js
https://github.com/artdecocode/bosom
Last synced: 3 months ago
JSON representation
Read and write a JSON file in Node.js
- Host: GitHub
- URL: https://github.com/artdecocode/bosom
- Owner: artdecocode
- License: mit
- Created: 2018-06-11T05:51:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-08-01T15:30:25.000Z (over 6 years ago)
- Last Synced: 2025-09-17T02:32:59.144Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bosom
[](https://npmjs.org/package/bosom)
`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.
```sh
yarn add bosom
```
- [API](#api)
- [`async bosom(path: string, data=: Object, options=: Options): string|void`](#async-bosompath-stringdata-objectoptions-options-stringvoid)
* [`_bosom.Options`](#type-_bosomoptions)
- [Copyright](#copyright)
## API
The package is available by importing its default function:
```js
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.
```js
/* 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)
}
})()
```
```js
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).
```js
/* 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)
}
})()
```
```js
t
{ 'my-data': true, bar: 'foo' }
```
## Copyright