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

hjson

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hjson - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

test/asset/fname1_result.json

52

lib/hjson.js

@@ -457,4 +457,4 @@ /*

var needsEscape = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
var needsEscapeExceptBS = /[\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // like needsEscape but without \\
var needsEscapeExceptBSLF = /[\"\x00-\x09\x0b\x0c\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // like needsEscape but without \\, \n and \r
var needsQuotes = /[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // like needsEscape but without \\ and \"
var needsEscapeML = /'''|[\x00-\x09\x0b\x0c\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; // ''' || (needsQuotes but without \n and \r)
var meta =

@@ -494,4 +494,4 @@ { // table of character substitutions

needsEscapeExceptBS.lastIndex = 0;
var doEscape = hasComment || needsEscapeExceptBS.test(string);
needsQuotes.lastIndex = 0;
var doEscape = hasComment || needsQuotes.test(string);

@@ -504,2 +504,3 @@ // Check if we can insert this string without quotes

isDigit(first) ||
first === '"' ||
first === '#' ||

@@ -514,9 +515,10 @@ first === '-' ||

// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// Otherwise we first check if the string can be expressed in multiline
// format or we must replace the offending characters with safe escape
// sequences.
needsEscape.lastIndex = 0;
needsEscapeExceptBSLF.lastIndex = 0;
needsEscapeML.lastIndex = 0;
if (!needsEscape.test(string)) return '"' + string + '"';
else if (!needsEscapeExceptBSLF.test(string)) return mlString(string, gap);
else if (!needsEscapeML.test(string)) return mlString(string, gap);
else return '"' + quoteReplace(string) + '"';

@@ -533,10 +535,22 @@ }

{
// wrap the string into the ''' (multiline) format
var i, a = string.replace(/\r/g, "").split('\n');
gap += indent;
var res = hjson_EOL + gap + "'''";
for (i = 0; i < a.length; i++)
var res;
if (a.length === 1)
{
res += hjson_EOL + gap + a[i];
// The string contains only a single line. We still use the multiline
// format as it avoids escaping the \ character (e.g. when used in a
// regex).
res = "'''" + a[0];
}
else
{
res = hjson_EOL + gap + "'''";
for (i = 0; i < a.length; i++)
res += hjson_EOL + gap + a[i];
}
return res + "'''";

@@ -563,5 +577,5 @@ }

function str(key, holder, hasComment)
function str(value, hasComment, rootObject)
{
// Produce a string from holder[key].
// Produce a string from value.

@@ -582,4 +596,2 @@ function startsWithNL(str) { return str && str[str[0] === '\r' ? 1 : 0] === '\n'; }

var value = holder[key];
// What happens next depends on the value's type.

@@ -617,3 +629,3 @@

var eolGap = hjson_EOL + gap;
var prefix = hjson_bracesSameLine ? '' : eolMind;
var prefix = rootObject || hjson_bracesSameLine ? '' : eolMind;
var partial = [];

@@ -637,3 +649,3 @@

if (kw) partial.push(wsc(kw[i]) + eolGap);
partial.push(str(i, value, kw ? testWsc(kw[i + 1]) : false) || 'null');
partial.push(str(value[i], kw ? testWsc(kw[i + 1]) : false) || 'null');
}

@@ -669,3 +681,3 @@ if (kw) partial.push(wsc(kw[i]) + eolMind);

kwl = wsc(kw.c[k]);
v = str(k, value, testWsc(kwl));
v = str(value[k], testWsc(kwl));
if (v) partial.push(quoteName(k) + (startsWithNL(v) ? ':' : ': ') + v);

@@ -681,3 +693,3 @@ }

{
v = str(k, value);
v = str(value[k]);
if (v) partial.push(quoteName(k) + (startsWithNL(v) ? ':' : ': ') + v);

@@ -734,6 +746,4 @@ }

// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return str('', { '': value });
return str(value, null, true);
};

@@ -740,0 +750,0 @@ }());

@@ -6,8 +6,10 @@ {

"author": "Christian Zangl",
"version": "1.0.1",
"tags": [
"version": "1.0.2",
"tags":
[
"json",
"hjson"
],
"keywords": [
"keywords":
[
"json",

@@ -20,5 +22,10 @@ "config",

],
"bin": {
"bin":
{
"hjson": "./bin/hjson"
},
"scripts":
{
"test" : "node ./test/test.js"
},
"homepage": "http://laktak.github.io/hjson",

@@ -25,0 +32,0 @@ "repository":

# hjson-js
Hjson JavaScript reference implementation.
Hjson, the Human JSON. A data format that caters to humans and helps reduce the errors they make.
Hjson is JSON - commas + comments for Humans.
For details and syntax see http://laktak.github.io/hjson.
It should be used for configuration files, for debug output or where it is likely that JSON data is read or will be edited by a human.
That means that you can write:
```
{
# look, no quotes or commas!
foo: Hello World!
bar: Hello Hjson!
# don't bother with escapes
html: <div class="hello">world</div>
# Hjson is a superset so the normal JSON syntax can be used
"array": [ 1, "two" ]
}
```
instead of:
```
{
"foo": "Hello World!",
"bar": "Hello Hjson!",
"html": "<div class=\"hello\">world</div>",
"array": [ 1, "two" ]
}
```
For details see http://laktak.github.io/hjson.
# Install from npm

@@ -110,2 +80,6 @@

## v1.0.2
- stringify bug fixes
## v1.0.0

@@ -112,0 +86,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