require-json5
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -5,7 +5,7 @@ /** | ||
* @license MIT | ||
* @version 1.0.1 | ||
* @version 1.0.2 | ||
* @author Dumitru Uzun (DUzun.Me) | ||
*/ | ||
var VERSION = '1.0.1'; | ||
var VERSION = '1.0.2'; | ||
@@ -12,0 +12,0 @@ var fs = require('fs'); |
{ | ||
"name": "require-json5", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Require JSON5 files in node - a better JSON for ES5 era", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,3 +5,3 @@ # require-json5 [![Build Status](https://travis-ci.org/duzun/require-json5.svg?branch=master)](https://travis-ci.org/duzun/require-json5) | ||
JSON5 is more human friendly, can contain comments, trailing commas amd more! | ||
JSON5 is more human friendly, can contain comments, trailing commas, unquoted keys amd more! | ||
@@ -16,21 +16,31 @@ ## Install | ||
Include the lib: | ||
```js | ||
var requireJSON5 = require('require-json5'); | ||
``` | ||
1) Require a JSON5 file | ||
```js | ||
require('require-json5'); | ||
var config = require("./config.json5"); | ||
``` | ||
2) Load a .json file in JSON5 format | ||
2) Load a `.json` file in JSON5 format | ||
```js | ||
var requireJSON5 = require('require-json5'); | ||
var config = requireJSON5("./config.json"); | ||
``` | ||
3) Load a .js file as JSON5 format. | ||
This is useful if you don't like the `.json5` file extension | ||
and prefer to keep JSON5 in `.js` files. | ||
```js | ||
var config = requireJSON5("./config.js"); | ||
``` | ||
3) Parse a JSON5 string | ||
```js | ||
var requireJSON5 = require('require-json5'); | ||
var config = requireJSON5.parse('{ name: /*a very important option*/ "value" }'); | ||
@@ -45,1 +55,33 @@ ``` | ||
``` | ||
## Example of JSON5 | ||
The following is a contrived example, but it illustrates most of the features: | ||
```js | ||
{ | ||
foo: 'bar', | ||
while: true, | ||
this: 'is a \ | ||
multi-line string', | ||
// this is an inline comment | ||
here: 'is another', // inline comment | ||
/* this is a block comment | ||
that continues on another line */ | ||
hex: 0xDEADbeef, | ||
half: .5, | ||
delta: +10, | ||
to: Infinity, // and beyond! | ||
finally: 'a trailing comma', | ||
oh: [ | ||
"we shouldn't forget", | ||
'arrays can have', | ||
'trailing commas too', | ||
], | ||
} | ||
``` |
7910
85