comment-json
Advanced tools
Comparing version 4.0.0 to 4.0.1
{ | ||
"name": "comment-json", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Parse and stringify JSON with comments. It will retain comments even after saved!", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
[![Build Status](https://travis-ci.org/kaelzhang/node-comment-json.svg?branch=master)](https://travis-ci.org/kaelzhang/node-comment-json) | ||
[![Coverage](https://codecov.io/gh/kaelzhang/node-comment-json/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/node-comment-json) | ||
[![npm module downloads per month](http://img.shields.io/npm/dm/comment-json.svg)](https://www.npmjs.org/package/comment-json) | ||
<!-- optional appveyor tst | ||
@@ -9,5 +10,2 @@ [![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-comment-json?branch=master&svg=true)](https://ci.appveyor.com/project/kaelzhang/node-comment-json) | ||
--> | ||
<!-- optional npm downloads | ||
[![npm module downloads per month](http://img.shields.io/npm/dm/comment-json.svg)](https://www.npmjs.org/package/comment-json) | ||
--> | ||
<!-- optional dependency status | ||
@@ -28,2 +26,13 @@ [![Dependency Status](https://david-dm.org/kaelzhang/node-comment-json.svg)](https://david-dm.org/kaelzhang/node-comment-json) | ||
## Table of Contents | ||
- [Why](#why) and [How](#how) | ||
- [Usage and examples](#usage) | ||
- API reference | ||
- [parse](#parse) | ||
- [stringify](#stringify) | ||
- [assign](#assigntarget-object-source-object-keys-array) | ||
- [CommentArray](#commentarray) | ||
- [Change Logs](https://github.com/kaelzhang/node-comment-json/releases) | ||
## Why? | ||
@@ -79,2 +88,32 @@ | ||
#### Sort keys | ||
It is a common use case to sort the keys of a JSON file | ||
```js | ||
const parsed = parse(`{ | ||
// b | ||
"b": 2 | ||
// a | ||
"a": 1 | ||
}`) | ||
// Assign the properties including comments from `parsed` to the new object `{}` | ||
// according to the sequance of the given keys | ||
const sorted = assign( | ||
{}, | ||
parsed, | ||
// You could also use your custom sorting function | ||
Object.keys().sort() | ||
) | ||
console.log(stringify(sorted, null, 2)) | ||
// { | ||
// // a | ||
// "a": 1, | ||
// // b | ||
// "b": 2 | ||
// } | ||
``` | ||
## parse() | ||
@@ -81,0 +120,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42172
536