UNPKG

3.28 kBMarkdownView Raw
1# JSON Future
2
3![Last version](https://img.shields.io/github/tag/Kikobeats/json-future.svg?style=flat-square)
4[![Build Status](http://img.shields.io/travis/Kikobeats/json-future/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/json-future)
5[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/json-future.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/json-future)
6[![Dependency status](http://img.shields.io/david/Kikobeats/json-future.svg?style=flat-square)](https://david-dm.org/Kikobeats/json-future)
7[![Dev Dependencies Status](http://img.shields.io/david/dev/Kikobeats/json-future.svg?style=flat-square)](https://david-dm.org/Kikobeats/json-future#info=devDependencies)
8[![NPM Status](http://img.shields.io/npm/dm/json-future.svg?style=flat-square)](https://www.npmjs.org/package/json-future)
9[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/Kikobeats)
10
11> Unbelievable and Modern JSON interface. Prollyfills propositions for ECMAScript 7.
12
13> Prollyfill: A polyfill for a not yet standardized API.
14
15## Why
16
17* High level methods for manipulate JSON files (stringify, parse, load and save).
18* Backward compatibility with JSON Object in Node or Browser.
19* Async support (Node Callback style and Promise).
20
21JSON Future is based into a set of cool libraries to handle JSON, but some of this libraries uses promises or callback style. This library adds an extra layer to call these libraries uniformly.
22
23## Install
24
25```bash
26npm install json-future --save
27```
28
29## Usage
30
31```js
32var jsonFuture = require('json-future')
33```
34
35Don't be afraid to replace for the default `JSON` object. The library is specially designed for be compatible and don't break your code:
36
37```js
38JSON = require('json-future')
39```
40
41Also you can do this action using the `register` helper:
42
43```js
44require('json-future/register')
45```
46
47## API
48
49In `async` methods, if you don't provide a callback for node style, then the method return a `Promise`.
50
51### .stringify(input, [replacer], [space])g
52### .stringifyAsync(input, [replacer], [space], [cb])
53
54Creates the `string` version of the input.
55
56### .parse(input, [reviver], [filename])
57### .parseAsync(input, [reviver], [filename], [cb])
58
59Creates the `object` version of the input.
60
61### .load(filepath)
62### .loadAsync(filepath, [cb])
63
64Returns the parsed JSON.
65
66### .save(filepath, data, [options])
67### .saveAsync(filepath, data, [options], [cb])
68
69Stringify and write JSON to a file atomically.
70
71#### options
72
73##### indent
74
75Type: `string`, `number`
76Default: `\t`
77
78Indentation as a string or number of spaces.
79Pass in `null` for no formatting.
80
81##### sortKeys
82
83Type: `boolean`, `function`
84Default: `false`
85
86Sort the keys recursively.
87Optionally pass in a [`compare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function.
88
89##### replacer
90
91Type: `function`
92
93Passed into [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter).
94
95##### mode
96
97Type: `number`
98Default `438` *(0666 in octal)*
99
100[Mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file.
101
102## License
103
104MIT © [Kiko Beats](http://kikobeats.com)