Comparing version 1.6.1 to 1.6.3
@@ -0,8 +1,15 @@ | ||
/*! @preserve | ||
* Hjson v1.6.3 | ||
* http://hjson.org | ||
* | ||
* Copyright 2014 Christian Zangl, MIT license | ||
* Details and documentation: | ||
* https://github.com/laktak/hjson-js | ||
* | ||
* This code is based on the the JSON version by Douglas Crockford: | ||
* https://github.com/douglascrockford/JSON-js (json_parse.js, json2.js) | ||
*/ | ||
/* | ||
hjson.js | ||
Public Domain. | ||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | ||
This file creates a Hjson object: | ||
@@ -22,6 +29,3 @@ | ||
The code is based on the the JSON version by Douglas Crockford: | ||
https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js | ||
Hjson.stringify(value, options) | ||
@@ -31,10 +35,21 @@ | ||
options { | ||
options { all options are | ||
keepWsc boolean, keep white space. See parse. | ||
space an optional parameter that specifies the indentation | ||
of nested structures. If it is a number, it will specify | ||
the number of spaces to indent at each level. If it is | ||
a string (such as '\t' or ' '), it contains the | ||
characters used to indent at each level. | ||
bracesSameLine | ||
boolean, makes braces appear on the same line as the key | ||
name. Default false. | ||
quotes string, controls how strings are displayed. | ||
"min" - no quotes whenever possible (default) | ||
"always" - always use quotes | ||
space specifies the indentation of nested structures. If it is | ||
a number, it will specify the number of spaces to indent | ||
at each level. If it is a string (such as '\t' or ' '), | ||
it contains the characters used to indent at each level. | ||
eol specifies the EOL sequence (default is set by | ||
Hjson.setEndOfLine()) | ||
} | ||
@@ -49,17 +64,10 @@ | ||
The code is based on the the JSON version by Douglas Crockford: | ||
https://github.com/douglascrockford/JSON-js/blob/master/json2.js | ||
Hjson.endOfLine() | ||
Hjson.setEndOfLine(eol) | ||
Gets or sets the EOL character ('\n' or '\r\n'). | ||
Gets or sets the stringify EOL sequence ('\n' or '\r\n'). | ||
When running with node.js this defaults to os.EOL. | ||
Hjson.bracesSameLine() | ||
Hjson.setBracesSameLine(b) | ||
Gets or sets if braces should appear on the same line (for stringify). | ||
Hjson.rt { parse, stringify } | ||
@@ -71,6 +79,14 @@ | ||
OBSOLETE: Hjson.bracesSameLine() | ||
OBSOLETE: Hjson.setBracesSameLine(b) | ||
OBSOLETE: use stringify options instead of this global setting. | ||
Gets or sets if braces should appear on the same line (for stringify). | ||
This is a reference implementation. You are free to copy, modify, or | ||
redistribute. | ||
This code should be minified before deployment. | ||
*/ | ||
@@ -82,3 +98,3 @@ | ||
var EOL = '\n'; | ||
var bracesSameLine = false; | ||
var defaultBracesSameLine = false; | ||
@@ -482,3 +498,3 @@ var tryParseNumber = function (text) { | ||
var indent = ' '; | ||
var keepWsc; | ||
var eol, keepWsc, bracesSameLine, quoteAlways; | ||
@@ -500,3 +516,3 @@ function isWhite(c) { return c <= ' '; } | ||
needsQuotes.lastIndex = 0; | ||
var doEscape = hasComment || needsQuotes.test(string); | ||
var doEscape = quoteAlways || hasComment || needsQuotes.test(string); | ||
@@ -549,8 +565,8 @@ // Check if we can insert this string without quotes | ||
else { | ||
var res = EOL + gap + "'''"; | ||
var res = eol + gap + "'''"; | ||
for (i = 0; i < a.length; i++) { | ||
res += EOL; | ||
res += eol; | ||
if (a[i]) res += gap + a[i]; | ||
} | ||
return res + EOL + gap + "'''"; | ||
return res + eol + gap + "'''"; | ||
} | ||
@@ -614,4 +630,4 @@ } | ||
gap += indent; | ||
var eolMind = EOL + mind; | ||
var eolGap = EOL + gap; | ||
var eolMind = eol + mind; | ||
var eolGap = eol + gap; | ||
var prefix = rootObject || bracesSameLine ? '' : eolMind; | ||
@@ -694,8 +710,14 @@ var partial = []; | ||
eol = EOL; | ||
indent = ' '; | ||
keepWsc = false; | ||
bracesSameLine = defaultBracesSameLine; | ||
quoteAlways = false; | ||
if (opt && typeof opt === 'object') { | ||
if (opt.eol === '\n' || opt.eol === '\r\n') eol = opt.eol; | ||
space = opt.space; | ||
keepWsc = opt.keepWsc; | ||
bracesSameLine = opt.bracesSameLine || defaultBracesSameLine; | ||
quoteAlways = opt.quotes === 'always'; | ||
} | ||
@@ -702,0 +724,0 @@ |
@@ -6,7 +6,3 @@ { | ||
"author": "Christian Zangl", | ||
"version": "1.6.1", | ||
"tags": [ | ||
"json", | ||
"hjson" | ||
], | ||
"version": "1.6.3", | ||
"keywords": [ | ||
@@ -18,3 +14,4 @@ "json", | ||
"parser", | ||
"serializer" | ||
"serializer", | ||
"human" | ||
], | ||
@@ -26,3 +23,4 @@ "bin": { | ||
"test": "node ./test/test.js", | ||
"lint": "jshint bin/hjson lib" | ||
"lint": "jshint bin/hjson lib/hjson.js", | ||
"min": "node node_modules/uglify-js/bin/uglifyjs lib/hjson.js --comments -c -m -o lib/hjson.min.js" | ||
}, | ||
@@ -42,3 +40,6 @@ "homepage": "http://hjson.org", | ||
} | ||
] | ||
} | ||
], | ||
"devDependencies": { | ||
"uglify-js": "^2.4.16" | ||
} | ||
} |
@@ -8,4 +8,29 @@ # hjson-js | ||
It supports `#`, `//` and `/**/` style comments as well as avoiding trailing/missing comma and other mistakes. For details and syntax see [hjson.org](http://hjson.org). | ||
``` | ||
{ | ||
# This is Hjson | ||
/* | ||
Why? | ||
JSON is a great tool that does its job very well. Maybe too well. JSON is a | ||
great hammer but not everything is a nail. | ||
Configuration files are edited by end-users, not developers. Users should not | ||
have to worry about putting commas in the correct place. Software should | ||
empower the user not hinder him. | ||
*/ | ||
"JSON": "is Hjson", | ||
but: commas and quotes are optional! | ||
and: those are allowed: // /**/ # | ||
so: less mistakes, more comments ;-) | ||
} | ||
``` | ||
For details see [hjson.org](http://hjson.org). | ||
# Install from npm | ||
@@ -67,12 +92,13 @@ | ||
- *keepWsc*: boolean, keep white space. See parse. | ||
- *space*: an optional parameter that specifies the indentation of nested structures. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t' or ' '), it contains the characters used to indent at each level. | ||
- *bracesSameLine*: boolean, makes braces appear on the same line as the key name. Default false. | ||
- *quotes*: string, controls how strings are displayed. | ||
- "min": no quotes whenever possible (default) | ||
- "always": always use quotes | ||
- *space*: specifies the indentation of nested structures. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t' or ' '), it contains the characters used to indent at each level. | ||
- *eol*: specifies the EOL sequence (default is set by Hjson.setEndOfLine()) | ||
### Hjson.endOfLine(), .setEndOfLine(eol) | ||
Gets or sets the EOL character ('\n' or '\r\n'). | ||
Gets or sets the stringify EOL sequence ('\n' or '\r\n'). When running with node.js this defaults to os.EOL. | ||
### Hjson.bracesSameLine(), .setBracesSameLine(b) | ||
Gets or sets if braces should appear on the same line (for stringify). | ||
### Hjson.rt { parse, stringify } | ||
@@ -114,2 +140,4 @@ | ||
- v1.6.3 | ||
- added stringify options | ||
- v1.6.1 | ||
@@ -116,0 +144,0 @@ - fixed stringify with options===null |
Sorry, the diff of this file is not supported yet
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
55076
68
1024
166
1
1