https://github.com/tenphi/jsync
Module for sync local object variable with *.js or *.coffee file
https://github.com/tenphi/jsync
Last synced: about 2 months ago
JSON representation
Module for sync local object variable with *.js or *.coffee file
- Host: GitHub
- URL: https://github.com/tenphi/jsync
- Owner: tenphi
- License: mit
- Created: 2012-08-27T11:02:45.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-11-16T08:30:35.000Z (over 13 years ago)
- Last Synced: 2024-04-30T00:46:26.584Z (about 2 years ago)
- Language: CoffeeScript
- Homepage:
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## jSync - Module for sync local object variable with *.js or *.coffee file
======
### Installation
```bash
$ npm install jsync
```
### Simple usage
```javascript
var jsync = require('jsync');
var obj = jsync('data.json'); // also you can load *.js, *.cson and *.coffee files
// now object will keep in sync with json-file
```
### Set interval
```javascript
var obj = jsync('data.js', 100); // file check every 100ms
```
### Set context for eval
```javascript
// data.js
{
someVariable: this.prop
}
```
Context can only be the Object
```javascript
context = { prop: 'value' };
var obj = jsync('data.js', context);
console.log(obj); // { someVariable: 'value' }
```
### Set handler
```javascript
// data.js
[1,2,3,4]
```
```javascript
function handler (err, arr) {
arr.splice(2);
}
var obj = jsync('data.js', handler);
console.log(obj); // [1,2]
```
### All-in-one call
```javascript
var obj = jsync(file, interval, context, handler); // all arguments are optional except `file`
```
### Cancel sync and remove watcher
```javascript
jsync.cancel(obj);
```
### Simple read without sync
```javascript
var obj = jsync.read('data.js', context);
```
### Manual sync with or without new context
```javascript
jsync.trigger(obj, newContext);
```
### Save synced object to file
```javascript
var obj = jsync('data.js');
jsync.save(obj/*, fileName, callback */); // if fileName not set it will use 'data.js'
```
function will execute asynchronously if callback is set
### Run some tests
```bash
$ cd /path/to/jsync/
$ npm test
```