comment-json
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -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) { |
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
17297
483