0.2.1 • Published 7 years ago

durian v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

durian

Make your json support comment

only support single line comment '//'

Usage

parse
const fs = require('fs');
const durian = require('durian');

const input = fs.readFileSync(path.join(__dirname, './input.json'), 'utf8');
const result = durian.parse(input);   // same as JSON.parse, just remove comments before parse;

input.json

// head comment
{
    "code": 200,
    "message": "success",
    "result": {
        "list": [
            {
                "goodsId": 1,
                "goodsName": "Nike Kobe 8",
                "url": "https://www.kaola.com"
            },
            // {
            //     "goodsId": 2,
            //     "goodsName": "Nike Kobe 9",
            //     "url": "https://www.kaola.com"
            // },
            {
                "goodsId": 3,
                "goodsName": "Nike Kobe 10",
                "url": "https://www.kaola.com"
            }
        ],
        "total": 100
    }
}
// tail comment

And the result is(a javascript variable, not string):

{
    "code": 200,
    "message": "success",
    "result": {
        "list": [
            {
                "goodsId": 1,
                "goodsName": "Nike Kobe 8",
                "url": "https://www.kaola.com"
            },
            {
                "goodsId": 3,
                "goodsName": "Nike Kobe 10",
                "url": "https://www.kaola.com"
            }
        ],
        "total": 100
    }
}
minify
const fs = require('fs');
const durian = require('durian');

const input = fs.readFileSync(path.join(__dirname, './input.json'), 'utf8');
const result = durian.minify(input);

And the result is(a string, remove the whitespaces within input):

{"code": 200,"message": "success","result": {"list": [{"goodsId": 1,"goodsName": "Nike Kobe 8","url": "https://www.kaola.com"},{"goodsId": 3,"goodsName": "Nike Kobe 10","url": "https://www.kaola.com"}],"total": 100}}

Build

$ npm run build

Publish

$ npm run publish
0.2.1

7 years ago

0.2.0

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

9 years ago