
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
reactivefile
Advanced tools
A lightweight library for creating a reactive ⚡️ binding between a JS object and a file.
ReactiveFile is a library which handles parsing a data file and then auto-saving it reactively whenever you change the object.
Most popular filetypes (JSON, TOML, YAML, XML) are handled automatically. The API provides a set of tools that let you easily implement parsers and serializers for other languages.
The reactivity of a ReactiveFile object is deep by default.
Currently only supports Node.js (browser implementation is on the way)
A simple example of a JSON file with a counter:
// data.json
{"counter": 0}
You can create a reactive binding with a few lines of code:
import * as ReactiveFile from 'reactivefile'
const data = await ReactiveFile.load('data.json')
data.$.counter++
The counter in data.json now has a value of 1.
Just run:
yarn add reactivefile
or:
npm install reactivefile
import * as ReactiveFile from 'reactivefile'
// or
const ReactiveFile = require('reactivefile')
const data = await ReactiveFile.load('data.json', options)
// use .loadSync(...) for synchronous loading instead
You can also create a ReactiveFile from an existing object and set a destination file
const data = ReactiveFile.from(response, {saveTo: 'destination.toml'})
data.$.lastAccess = new Date()
// data.$ is an alias for data.val
Adding new keys to your objects requires you to refresh your object's reactivity
data.$.newKey = 100
data.react()
data.$.newKey = 200
The implementation of the built-in toml type:
ReactiveFile.registerType('toml', str => toml.parse(str), obj => toml.stringify(obj))
You can also copy these functions from one type to another
ReactiveFile.assignType('yaml', 'yml')
// creates a yaml type with the same parser and serializer as yml
These types are also the file extensions — files with the json extension will be automatically handled by the json parser. You can override this behaviour by specifying the data type.
const data = await ReactiveFile.load('data.json', {type: 'toml'})
// reads toml from the data.json file (and saves in toml as well)
The encoding of the file. One of: 'ascii', 'base64', 'binary', 'hex', 'latin1', 'ucs-2', 'ucs2', 'utf-8', 'utf16le', 'utf8'.
The type/language of the file. Defaults to the file's extension.
The destination file path. If set, saves your data to another file instead. Otherwise overwrites the original file.
Turns on/off the reactive binding. The object can be then saved with .save() or .saveSync() instead. Defaults to true.
Turns on/off deep reactivity. Defaults to true.
Turns on/off asynchronous saving (instead of synchronous). Defaults to true.
MIT
FAQs
A lightweight library for creating a reactive ⚡️ binding between a JS object and a file.
We found that reactivefile demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.