Socket
Book a DemoInstallSign in
Socket

reactive-json-file

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactive-json-file

Reactively sync JSON mutations to disk

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
10
100%
Maintainers
1
Weekly downloads
 
Created
Source

reactive-json-file

Sync JSON mutations to disk using reactive magic!

Great for removing saving-to-disk concerns when updating a JSON object.

import { openJson } from 'reactive-json-file'

// Open a JSON file
const object = openJson('./data.json')

// No need to save changes to disk, just update the object
object.name = 'John Doe'

:rocket: Install

npm i reactive-json-file

⚙️ API

openJson(filePath, options)

Open a file (eg. JSON file) and return the object

Options

  • throttle <Number> - Milliseconds to throttle saves by. Saves are already batched at the end of every event-loop, but this adds time-based throttling.

  • fs <FileSystemInterface> (fs) - Pass in a custom file-system. Defaults to native Node.js fs

  • serialize/deserialize <Function> - Functions to serialize/deserialize the object with. eg. to save output to YAML

    import { openJson as openYaml } from 'reactive-json-file'
    import yaml from 'js-yaml'
    
    const object = openYaml('./file.yaml', {
        serialize: data => yaml.dump(data),
        deserialize: string => yaml.load(string)
    })
    
    object.message = 'YAML!'
    

closeJson(object)

Close a file to disable syncing

🙋‍♀️ FAQ

How does it work?

Arbitrary new changes are detected by using ES6 Proxy behind the scenes.

Keywords

reactive

FAQs

Package last updated on 28 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.