Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

comment-json

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comment-json - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc