-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from privatenumber/develop
Release
- Loading branch information
Showing
5 changed files
with
102 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
# reactive-json <a href="https://npm.im/reactive-json"><img src="https://badgen.net/npm/v/reactive-json"></a> <a href="https://npm.im/reactive-json"><img src="https://badgen.net/npm/dm/reactive-json"></a> <a href="https://packagephobia.now.sh/result?p=reactive-json"><img src="https://packagephobia.now.sh/badge?p=reactive-json"></a> <a href="https://bundlephobia.com/result?p=reactive-json"><img src="https://badgen.net/bundlephobia/minzip/reactive-json"></a> | ||
# reactive-json-file <a href="https://npm.im/reactive-json-file"><img src="https://badgen.net/npm/v/reactive-json-file"></a> <a href="https://npm.im/reactive-json-file"><img src="https://badgen.net/npm/dm/reactive-json-file"></a> <a href="https://packagephobia.now.sh/result?p=reactive-json-file"><img src="https://packagephobia.now.sh/badge?p=reactive-json-file"></a> <a href="https://bundlephobia.com/result?p=reactive-json-file"><img src="https://badgen.net/bundlephobia/minzip/reactive-json-file"></a> | ||
|
||
Immediate save your JS objects to a JSON file as you mutate them | ||
Save your JS objects to a JSON file as you mutate them | ||
|
||
## :raising_hand: Why? | ||
- 🐥 Tiny! | ||
```js | ||
import reactiveJsonFile from 'reactive-json-file' | ||
|
||
// Create a new JSON | ||
const object = reactiveJsonFile('./data.json') | ||
|
||
// Mutating the object automatically saves to file | ||
object.name = 'John Doe' | ||
|
||
``` | ||
|
||
## :rocket: Install | ||
```sh | ||
npm i reactive-json | ||
npm i reactive-json-file | ||
``` | ||
|
||
|
||
## ⚙️ 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](https://nodejs.org/api/fs.html)) - 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 | ||
|
||
```js | ||
import reactiveJsonFile from 'reactive-json-file' | ||
import yaml from 'js-yaml' | ||
|
||
const object = reactiveJsonFile('./file.yaml', { | ||
serialize: string => yaml.dump(string), | ||
deserialize: object_ => yaml.load(object_) | ||
}) | ||
|
||
object.message = 'YAML!' | ||
``` | ||
|
||
## 🙋♀️ FAQ | ||
|
||
### How does it work? | ||
Arbitrary new changes are detected by using Vue 3's reactive API, which uses [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) behind the scenes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
{ | ||
"name": "reactive-json", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "lib/reactive-json.js", | ||
"name": "reactive-json-file", | ||
"version": "0.0.0-semantic-release", | ||
"description": "Reactively save objects to file", | ||
"keywords": [ | ||
"reactive", | ||
"vue", | ||
"json", | ||
"save", | ||
"file" | ||
], | ||
"repository": "privatenumber/reactive-json-file", | ||
"author": "Hiroki Osame <[email protected]>", | ||
"license": "MIT", | ||
"files": [ | ||
"lib" | ||
], | ||
"main": "lib/reactive-json-file.js", | ||
"scripts": { | ||
"test": "jest", | ||
"lint": "xo" | ||
|
@@ -15,17 +28,8 @@ | |
"lint-staged": { | ||
"*.js": "xo" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/privatenumber/reactive-json.git" | ||
}, | ||
"author": "Hiroki Osame <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/privatenumber/reactive-json/issues" | ||
}, | ||
"homepage": "https://github.com/privatenumber/reactive-json#readme", | ||
"dependencies": { | ||
"lodash.throttle": "^4.1.1", | ||
"vue": "^3.0.0-rc.9" | ||
}, | ||
"devDependencies": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters