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 0.1.7 to 0.1.8

30

lib/stringify.js

@@ -246,5 +246,7 @@ 'use strict';

function is_comment (key, holder) {
return !!~key.indexOf(KEY_PREFIX)
// And the corresponding property must exist
&& key.slice(KEY_PREFIX_LENGTH) in holder;
return key === '//^'
|| key === '//$'
|| !!~key.indexOf(KEY_PREFIX)
// And the corresponding property must exist
&& key.slice(KEY_PREFIX_LENGTH) in holder;
}

@@ -287,23 +289,19 @@

var head_comments = join(value, '//^', true);
var foot_comments = join(value, '//$', true);
var head_comments = join(value, '//^');
var foot_comments = join(value, '//$');
var result = str('', {'': value}, replacer, indent, '');
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return head_comments
+ str('', {'': value}, replacer, indent, '');
+ foot_comments;
return indent
? head_comments + result + foot_comments
: result;
};
function join (host, key, extra, remove) {
var str = host[key]
function join (host, key) {
return host[key]
? join_comments(host[key]) + '\n'
: '';
if (remove) {
delete host[key];
}
return str;
}

@@ -310,0 +308,0 @@

{
"name": "comment-json",
"version": "0.1.7",
"version": "0.1.8",
"description": "Parse and stringify JSON file with comments",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -100,2 +100,31 @@ 'use strict';

describe("json.stringify() should take care of prototype", function(){
it("normal case", function(){
var obj = {
a: 1
};
obj.__proto__ = {
b: 1
};
expect(json.stringify(obj)).to.equal('{"a":1}');
});
it("with comments", function(){
var obj = {
a: 1,
'//^': ['// a']
};
obj.__proto__ = {
b: 1
};
expect(json.stringify(obj)).to.equal('{"a":1}');
expect(json.stringify(obj, null, 2)).to.equal('// a\n{\n "a": 1\n}');
});
});
function every (subject, checker) {

@@ -102,0 +131,0 @@ if (Object(subject) !== subject) {

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