UNPKG

3.38 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[![Dependency status](http://img.shields.io/david/Kikobeats/json-future.svg?style=flat-square)](https://david-dm.org/Kikobeats/json-future)
6[![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)
7[![NPM Status](http://img.shields.io/npm/dm/json-future.svg?style=flat-square)](https://www.npmjs.org/package/json-future)
8[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/Kikobeats)
9
10> Unbelievable and Modern JSON interface. Prollyfills propositions for ECMAScript 7.
11
12> Prollyfill: A polyfill for a not yet standardized API.
13
14## Why
15
16* High level methods for manipulate JSON files (stringify, parse, load and save).
17* Backward compatibility with JSON Object in Node or Browser.
18* Async support (Node Callback style and Promise).
19
20JSON 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.
21
22## Install
23
24```bash
25npm install json-future --save
26```
27
28If you want to use in the browser (powered by [Browserify](http://browserify.org/)):
29
30```bash
31bower install json-future --save
32```
33
34and later link in your HTML:
35
36```html
37<script src="bower_components/json-future/dist/json-future.js"></script>
38```
39
40## Usage
41
42```js
43var jsonFuture = require('json-future');
44```
45
46Don't be afraid to replace for the default `JSON` object. The library is specially designed for be compatible and don't break your code:
47
48```js
49JSON = require('json-future');
50```
51
52Also you can do this action using the `register` helper:
53
54```js
55require('json-future/register')
56``
57
58## API
59
60In `async` methods, if you don't provide a callback for node style, then the method return a `Promise`.
61
62### .stringify(input, [replacer], [space])
63### .stringifyAsync(input, [replacer], [space], [cb])
64
65Creates the `string` version of the input.
66
67### .parse(input, [reviver], [filename])
68### .parseAsync(input, [reviver], [filename], [cb])
69
70Creates the `object` version of the input.
71
72### .load(filepath)
73### .loadAsync(filepath, [cb])
74
75Returns the parsed JSON.
76
77### .save(filepath, data, [options])
78### .saveAsync(filepath, data, [options], [cb])
79
80Stringify and write JSON to a file atomically.
81
82#### options
83
84##### indent
85
86Type: `string`, `number`
87Default: `\t`
88
89Indentation as a string or number of spaces.
90Pass in `null` for no formatting.
91
92##### sortKeys
93
94Type: `boolean`, `function`
95Default: `false`
96
97Sort the keys recursively.
98Optionally pass in a [`compare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function.
99
100##### replacer
101
102Type: `function`
103
104Passed into [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter).
105
106##### mode
107
108Type: `number`
109Default `438` *(0666 in octal)*
110
111[Mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file.
112
113## License
114
115MIT © [Kiko Beats](http://kikobeats.com)
116
\No newline at end of file