https://github.com/spoonx/json-statham
Kick your JSON's ass, with json-statham's help.
https://github.com/spoonx/json-statham
Last synced: 12 months ago
JSON representation
Kick your JSON's ass, with json-statham's help.
- Host: GitHub
- URL: https://github.com/spoonx/json-statham
- Owner: SpoonX
- License: mit
- Created: 2016-04-13T19:47:37.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-15T13:50:14.000Z (almost 10 years ago)
- Last Synced: 2024-11-09T01:17:39.172Z (over 1 year ago)
- Language: JavaScript
- Size: 153 KB
- Stars: 23
- Watchers: 7
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# json-statham
[](https://travis-ci.org/SpoonX/json-statham)
Kick your JSON's ass, with json-statham's help. Extends [Homefront](https://github.com/SpoonX/homefront).

Makes working with javascript objects and json easy.
## Installation
`npm i --save json-statham`
## Tests
`npm test`
## Usage
This module extends [Homefront](https://github.com/SpoonX/homefront). It's essentially the same, except for some additional methods, and an extended constructor.
### Using Statham
All arguments are optional.
```js
let Statham = require('json-statham').Statham;
let statham = new Statham({data: 'here'}, Statham.MODE_NESTED, 'path/to/file');
```
### Using .setFileLocation()
```js
let Statham = require('json-statham').Statham;
let statham = new Statham();
statham.setFileLocation('./foo/ray-liotta.json'); // Used by .save()
```
### Using .save()
```js
let Statham = require('json-statham').Statham;
let statham = new Statham();
statham.save().then(() => {/* Really does return a promise, I promise. */});
statham.save('./json-flemyng.json'); // Specific file
statham.save(true); // Create path for file, too
statham.save('./matt-schulze.json', true); // Both options
```
### Using .fromFile(fileName[, ensureFileExists=false])
This method allows you to tell Statham to fetch the contents of a file itself. When `ensure` has been set to true, statham will create the provided file if it doesn't exist yet. This method returns a promise, and resolves with a statham instance (as described above).
```js
let Statham = require('json-statham').Statham;
Statham.fromFile(__dirname + '/my-data.json').then(statham => {
// Yeeeaaah, we have a statham instance now.
});
```