Comparing version 2.3.1 to 2.4.0
@@ -317,4 +317,2 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Hjson = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var common = require("./hjson-common"); | ||
function loadDsf(col, type) { | ||
@@ -365,3 +363,3 @@ | ||
function nopDsf(value) { | ||
function nopDsf(/*value*/) { | ||
} | ||
@@ -374,3 +372,3 @@ | ||
function math(opt) { | ||
function math(/*opt*/) { | ||
return { | ||
@@ -417,3 +415,3 @@ name: "math", | ||
function date(opt) { | ||
function date(/*opt*/) { | ||
return { | ||
@@ -448,3 +446,3 @@ name: "date", | ||
},{"./hjson-common":2}],4:[function(require,module,exports){ | ||
},{}],4:[function(require,module,exports){ | ||
/* Hjson http://hjson.org */ | ||
@@ -454,3 +452,3 @@ /* jslint node: true */ | ||
module.exports = function($source, $opt) { | ||
module.exports = function(source, opt) { | ||
@@ -548,3 +546,3 @@ var common = require("./hjson-common"); | ||
var indent = 0; | ||
while (true) { | ||
for (;;) { | ||
var c=peek(-indent-5); | ||
@@ -565,3 +563,3 @@ if (!c || c === '\n') break; | ||
// When parsing multiline string values, we must look for ' characters. | ||
while (true) { | ||
for (;;) { | ||
if (!ch) { | ||
@@ -600,3 +598,3 @@ error("Bad multiline string"); | ||
var name = "", start = at, space = -1; | ||
while (true) { | ||
for (;;) { | ||
if (ch === ':') { | ||
@@ -879,16 +877,12 @@ if (!name) error("Found ':' but no key name (for an empty key name use quotes)"); | ||
function hjsonParse(source, opt) { | ||
if (typeof source!=="string") throw new Error("source is not a string"); | ||
var dsfDef = null; | ||
if (opt && typeof opt === 'object') { | ||
keepComments = opt.keepWsc; | ||
dsfDef = opt.dsf; | ||
} | ||
runDsf = dsf.loadDsf(dsfDef, "parse"); | ||
text = source; | ||
resetAt(); | ||
return rootValue(); | ||
if (typeof source!=="string") throw new Error("source is not a string"); | ||
var dsfDef = null; | ||
if (opt && typeof opt === 'object') { | ||
keepComments = opt.keepWsc; | ||
dsfDef = opt.dsf; | ||
} | ||
return hjsonParse($source, $opt); | ||
runDsf = dsf.loadDsf(dsfDef, "parse"); | ||
text = source; | ||
resetAt(); | ||
return rootValue(); | ||
}; | ||
@@ -901,3 +895,3 @@ | ||
module.exports = function($value, $opt) { | ||
module.exports = function(data, opt) { | ||
@@ -907,14 +901,69 @@ var common = require("./hjson-common"); | ||
// options | ||
var eol = common.EOL; | ||
var indent = ' '; | ||
var keepComments = false; | ||
var bracesSameLine = false; | ||
var quoteKeys = false; | ||
var quoteStrings = false; | ||
var multiline = 1; // std=1, no-tabs=2, off=0 | ||
var separator = ''; // comma separator | ||
var dsfDef = null; | ||
if (opt && typeof opt === 'object') { | ||
opt.quotes = opt.quotes === 'always' ? 'strings' : opt.quotes; // legacy | ||
if (opt.eol === '\n' || opt.eol === '\r\n') eol = opt.eol; | ||
keepComments = opt.keepWsc; | ||
bracesSameLine = opt.bracesSameLine; | ||
quoteKeys = opt.quotes === 'all' || opt.quotes === 'keys'; | ||
quoteStrings = opt.quotes === 'all' || opt.quotes === 'strings' || opt.separator === true; | ||
if (quoteStrings || opt.multiline == 'off') multiline = 0; | ||
else multiline = opt.multiline == 'no-tabs' ? 2 : 1; | ||
separator = opt.separator === true ? ',' : ''; | ||
dsfDef = opt.dsf; | ||
// If the space parameter is a number, make an indent string containing that | ||
// many spaces. If it is a string, it will be used as the indent string. | ||
if (typeof opt.space === 'number') { | ||
indent = new Array(opt.space + 1).join(' '); | ||
} else if (typeof opt.space === 'string') { | ||
indent = opt.space; | ||
} | ||
if (opt.colors === true) { | ||
token = { | ||
obj: [ '\x1b[30;1m{\x1b[0m', '\x1b[30;1m}\x1b[0m' ], | ||
arr: [ '\x1b[30;1m[\x1b[0m', '\x1b[30;1m]\x1b[0m' ], | ||
key: [ '\x1b[33m', '\x1b[0m' ], | ||
qkey: [ '\x1b[33m"', '"\x1b[0m' ], | ||
col: [ '\x1b[37m:\x1b[0m' ], | ||
str: [ '\x1b[37;1m', '\x1b[0m' ], | ||
qstr: [ '\x1b[37;1m"', '"\x1b[0m' ], | ||
mstr: [ "\x1b[37;1m'''", "'''\x1b[0m" ], | ||
num: [ '\x1b[36;1m', '\x1b[0m' ], | ||
lit: [ '\x1b[36m', '\x1b[0m' ], | ||
dsf: [ '\x1b[37m', '\x1b[0m' ], | ||
esc: [ '\x1b[31m\\', '\x1b[0m' ], | ||
uni: [ '\x1b[31m\\u', '\x1b[0m' ], | ||
rem: [ '\x1b[30;1m', '\x1b[0m' ], | ||
}; | ||
} | ||
} | ||
// | ||
var runDsf; // domain specific formats | ||
var commonRange='\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff'; | ||
// needsEscape tests if the string can be written without escapes | ||
var needsEscape = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; | ||
// needsQuotes tests if the string can be written as a quoteless string (includes needsEscape but without \\ and \") | ||
var needsQuotes = /^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\}|^\[|^\]|^:|^,|\s$|[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; | ||
// needsEscapeML tests if the string can be written as a multiline string (includes needsEscape but without \n, \r, \\ 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; | ||
var needsEscape = new RegExp('[\\\\\\"\x00-\x1f'+commonRange+']', 'g'); | ||
// needsQuotes tests if the string can be written as a quoteless string (like needsEscape but without \\ and \") | ||
var needsQuotes = new RegExp('^\\s|^"|^\'\'\'|^#|^\\/\\*|^\\/\\/|^\\{|^\\}|^\\[|^\\]|^:|^,|\\s$|[\x00-\x1f'+commonRange+']', 'g'); | ||
// needsEscapeML tests if the string can be written as a multiline string (like needsEscape but without \n, \r, \\, \", \t unless multines is 'std') | ||
var needsEscapeML = new RegExp('\'\'\'|^[\\s]+$|[\x00-'+(multiline === 2 ? '\x09' : '\x08')+'\x0b\x0c\x0e-\x1f'+commonRange+']', 'g'); | ||
// starts with a keyword and optionally is followed by a comment | ||
var startsWithKeyword = /^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/; | ||
var meta = | ||
{ // table of character substitutions | ||
var startsWithKeyword = new RegExp('^(true|false|null)\\s*((,|\\]|\\}|#|//|/\\*).*)?$'); | ||
var meta = { | ||
// table of character substitutions | ||
'\b': 'b', | ||
@@ -930,5 +979,2 @@ '\t': 't', | ||
var gap = ''; | ||
var indent = ' '; | ||
// options | ||
var eol, keepComments, bracesSameLine, quoteAlways; | ||
var token = { | ||
@@ -970,3 +1016,3 @@ obj: [ '{', '}' ], | ||
if (quoteAlways || hasComment || | ||
if (quoteStrings || hasComment || | ||
needsQuotes.test(string) || | ||
@@ -985,3 +1031,3 @@ common.tryParseNumber(string, true) !== undefined || | ||
if (!needsEscape.test(string)) return wrap(token.qstr, string); | ||
else if (!needsEscapeML.test(string) && !isRootObject) return mlString(string, gap); | ||
else if (!needsEscapeML.test(string) && !isRootObject && multiline) return mlString(string, gap); | ||
else return wrap(token.qstr, quoteReplace(string)); | ||
@@ -1020,3 +1066,3 @@ } else { | ||
if (needsEscapeName.test(name)) { | ||
if (quoteKeys || needsEscapeName.test(name)) { | ||
needsEscape.lastIndex = 0; | ||
@@ -1098,3 +1144,3 @@ return wrap(token.qkey, needsEscape.test(name) ? quoteReplace(name) : name); | ||
} | ||
partial.push(str(value[i], comments ? ca : false, true) || wrap(token.lit, 'null')); | ||
partial.push(str(value[i], comments ? ca : false, true) + (i < length -1 ? separator : '') || wrap(token.lit, 'null')); | ||
if (comments && c[1]) partial.push(makeComment(c[1], ca ? " " : "\n", ca)); | ||
@@ -1119,5 +1165,6 @@ } | ||
// Otherwise, iterate through all of the keys in the object. | ||
var keys; | ||
if (comments) { | ||
var keys = comments.o.slice(); | ||
keys = comments.o.slice(); | ||
for (k in value) { | ||
@@ -1135,3 +1182,3 @@ if (Object.prototype.hasOwnProperty.call(value, k) && keys.indexOf(k) < 0) | ||
v = str(value[k], ca); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v + (i < length - 1 ? separator : '')); | ||
if (comments && c[1]) partial.push(makeComment(c[1], ca ? " " : "\n", ca)); | ||
@@ -1146,6 +1193,9 @@ } | ||
} else { | ||
for (k in value) { | ||
keys = Object.keys(value); | ||
for (i = 0, length = keys.length; i < length; i++) { | ||
k = keys[i]; | ||
if (Object.prototype.hasOwnProperty.call(value, k)) { | ||
v = str(value[k]); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v + (i < length - 1 ? separator : '')); | ||
} | ||
@@ -1170,73 +1220,23 @@ } | ||
function hjsonStringify(value, opt) { | ||
var i, space; | ||
var dsfDef = null; | ||
eol = common.EOL; | ||
indent = ' '; | ||
keepComments = false; | ||
bracesSameLine = false; | ||
quoteAlways = false; | ||
runDsf = dsf.loadDsf(dsfDef, 'stringify'); | ||
if (opt && typeof opt === 'object') { | ||
if (opt.eol === '\n' || opt.eol === '\r\n') eol = opt.eol; | ||
space = opt.space; | ||
keepComments = opt.keepWsc; | ||
bracesSameLine = opt.bracesSameLine; | ||
quoteAlways = opt.quotes === 'always'; | ||
dsfDef = opt.dsf; | ||
var res = ""; | ||
var comments = keepComments ? comments = (common.getComment(data) || {}).r : null; | ||
if (comments && comments[0]) res = comments[0] + '\n'; | ||
if (opt.colors === true) { | ||
token = { | ||
obj: [ '\x1b[30;1m{\x1b[0m', '\x1b[30;1m}\x1b[0m' ], | ||
arr: [ '\x1b[30;1m[\x1b[0m', '\x1b[30;1m]\x1b[0m' ], | ||
key: [ '\x1b[33m', '\x1b[0m' ], | ||
qkey: [ '\x1b[33m"', '"\x1b[0m' ], | ||
col: [ '\x1b[37m:\x1b[0m' ], | ||
str: [ '\x1b[37;1m', '\x1b[0m' ], | ||
qstr: [ '\x1b[37;1m"', '"\x1b[0m' ], | ||
mstr: [ "\x1b[37;1m'''", "'''\x1b[0m" ], | ||
num: [ '\x1b[36;1m', '\x1b[0m' ], | ||
lit: [ '\x1b[36m', '\x1b[0m' ], | ||
dsf: [ '\x1b[37m', '\x1b[0m' ], | ||
esc: [ '\x1b[31m\\', '\x1b[0m' ], | ||
uni: [ '\x1b[31m\\u', '\x1b[0m' ], | ||
rem: [ '\x1b[30;1m', '\x1b[0m' ], | ||
}; | ||
} | ||
} | ||
// get the result of stringifying the data. | ||
res += str(data, null, true, true); | ||
runDsf = dsf.loadDsf(dsfDef, 'stringify'); | ||
if (comments) res += comments[1]||""; | ||
// If the space parameter is a number, make an indent string containing that | ||
// many spaces. If it is a string, it will be used as the indent string. | ||
if (typeof space === 'number') { | ||
indent = ''; | ||
for (i = 0; i < space; i++) indent += ' '; | ||
} else if (typeof space === 'string') { | ||
indent = space; | ||
} | ||
var res = ""; | ||
var comments = keepComments ? comments = (common.getComment(value) || {}).r : null; | ||
if (comments && comments[0]) res = comments[0] + '\n'; | ||
// get the result of stringifying the value. | ||
res += str(value, null, true, true); | ||
if (comments) res += comments[1]||""; | ||
return res; | ||
} | ||
return hjsonStringify($value, $opt); | ||
return res; | ||
}; | ||
},{"./hjson-common":2,"./hjson-dsf":3}],6:[function(require,module,exports){ | ||
module.exports="2.3.1"; | ||
module.exports="2.4.0"; | ||
},{}],7:[function(require,module,exports){ | ||
/*! @preserve | ||
* Hjson v2.3.1 | ||
* Hjson v2.4.0 | ||
* http://hjson.org | ||
@@ -1287,5 +1287,17 @@ * | ||
quotes string, controls how strings are displayed. | ||
setting separator implies "strings" | ||
"min" - no quotes whenever possible (default) | ||
"always" - always use quotes | ||
"keys" - use quotes around keys | ||
"strings" - use quotes around string values | ||
"all" - use quotes around keys and string values | ||
multiline string, controls how multiline strings are displayed. | ||
setting quotes implies "off" | ||
"std" - strings containing \n are shown in | ||
multiline format (default) | ||
"no-tabs" - like std but disallow tabs | ||
"off" - show in JSON format | ||
separator boolean, output a comma separator between elements. Default false. | ||
space specifies the indentation of nested structures. If it is | ||
@@ -1292,0 +1304,0 @@ a number, it will specify the number of spaces to indent |
@@ -1,3 +0,3 @@ | ||
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.Hjson=n()}}(function(){return function n(r,e,t){function o(f,u){if(!e[f]){if(!r[f]){var a="function"==typeof require&&require;if(!u&&a)return a(f,!0);if(i)return i(f,!0);var s=new Error("Cannot find module '"+f+"'");throw s.code="MODULE_NOT_FOUND",s}var c=e[f]={exports:{}};r[f][0].call(c.exports,function(n){var e=r[f][1][n];return o(e?e:n)},c,c.exports,n,r,e,t)}return e[f].exports}for(var i="function"==typeof require&&require,f=0;f<t.length;f++)o(t[f]);return o}({1:[function(n,r,e){"use strict";function t(n,r,e){var t;return n&&(t={b:n}),r&&((t=t||{}).a=r),e&&((t=t||{}).x=e),t}function o(n,r){if(null!==n&&"object"==typeof n){var e=m.getComment(n);e&&m.removeComment(n);var i,f,a,s;if("[object Array]"===Object.prototype.toString.apply(n)){for(s={a:[]},i=0,f=n.length;i<f;i++)u(s.a,i,e.a[i],o(n[i]))&&(a=!0);!a&&e.e&&(s.e=t(e.e[0],e.e[1]),a=!0)}else{s={s:{}};var c,l=Object.keys(n);for(e&&e.o?(c=[],e.o.concat(l).forEach(function(r){Object.prototype.hasOwnProperty.call(n,r)&&c.indexOf(r)<0&&c.push(r)})):c=l,s.o=c,i=0,f=c.length;i<f;i++){var p=c[i];u(s.s,p,e.c[p],o(n[p]))&&(a=!0)}!a&&e.e&&(s.e=t(e.e[0],e.e[1]),a=!0)}return r&&e&&e.r&&(s.r=t(e.r[0],e.r[1])),a?s:void 0}}function i(){var n="";return[].forEach.call(arguments,function(r){r&&""!==r.trim()&&(n&&(n+="; "),n+=r.trim())}),n}function f(n,r){var e=[];if(c(n,r,e,[]),e.length>0){var t=l(r,null,1);t+="\n# Orphaned comments:\n",e.forEach(function(n){t+=("# "+n.path.join("/")+": "+i(n.b,n.a,n.e)).replace("\n","\\n ")+"\n"}),l(r,t,1)}}function u(n,r,e,o){var i=t(e?e[0]:void 0,e?e[1]:void 0,o);return i&&(n[r]=i),i}function a(n,r){var e=t(r.b,r.a);return e.path=n,e}function s(n,r,e){if(n){var t,o;if(n.a)for(t=0,o=n.a.length;t<o;t++){var i=e.slice().concat([t]),f=n.a[t];f&&(r.push(a(i,f)),s(f.x,r,i))}else n.o&&n.o.forEach(function(t){var o=e.slice().concat([t]),i=n.s[t];i&&(r.push(a(o,i)),s(i.x,r,o))});n.e&&r.push(a(e,n.e))}}function c(n,r,e,t){if(n){if(null===r||"object"!=typeof r)return void s(n,e,t);var o,i,f=m.createComment(r);if(0===t.length&&n.r&&(f.r=[n.r.b,n.r.a]),"[object Array]"===Object.prototype.toString.apply(r)){for(f.a=[],o=0,i=(n.a||[]).length;o<i;o++){var u=t.slice().concat([o]),l=n.a[o];l&&(o<r.length?(f.a.push([l.b,l.a]),c(l.x,r[o],e,u)):(e.push(a(u,l)),s(l.x,e,u)))}0===o&&n.e&&(f.e=[n.e.b,n.e.a])}else f.c={},f.o=[],(n.o||[]).forEach(function(o){var i=t.slice().concat([o]),u=n.s[o];Object.prototype.hasOwnProperty.call(r,o)?(f.o.push(o),u&&(f.c[o]=[u.b,u.a],c(u.x,r[o],e,i))):u&&(e.push(a(i,u)),s(u.x,e,i))}),n.e&&(f.e=[n.e.b,n.e.a])}}function l(n,r,e){var t=m.createComment(n,m.getComment(n));return t.r||(t.r=["",""]),(r||""===r)&&(t.r[e]=m.forceComment(r)),t.r[e]||""}var m=n("./hjson-common");r.exports={extract:function(n){return o(n,!0)},merge:f,header:function(n,r){return l(n,r,0)},footer:function(n,r){return l(n,r,1)}}},{"./hjson-common":2}],2:[function(n,r,e){"use strict";function t(n,r){function e(){return o=n.charAt(a),a++,o}var t,o,i="",f=0,u=!0,a=0;for(e(),"-"===o&&(i="-",e());o>="0"&&o<="9";)u&&("0"==o?f++:u=!1),i+=o,e();if(u&&f--,"."===o)for(i+=".";e()&&o>="0"&&o<="9";)i+=o;if("e"===o||"E"===o)for(i+=o,e(),"-"!==o&&"+"!==o||(i+=o,e());o>="0"&&o<="9";)i+=o,e();for(;o&&o<=" ";)e();return r&&(","!==o&&"}"!==o&&"]"!==o&&"#"!==o&&("/"!==o||"/"!==n[a]&&"*"!==n[a])||(o=0)),t=+i,o||f||!isFinite(t)?void 0:t}function o(n,r){return Object.defineProperty&&Object.defineProperty(n,"__COMMENTS__",{enumerable:!1,writable:!0}),n.__COMMENTS__=r||{}}function i(n){Object.defineProperty(n,"__COMMENTS__",{value:void 0})}function f(n){return n.__COMMENTS__}function u(n){if(!n)return"";var r,e,t,o,i=n.split("\n");for(t=0;t<i.length;t++)for(r=i[t],o=r.length,e=0;e<o;e++){var f=r[e];if("#"===f)break;if("/"===f&&("/"===r[e+1]||"*"===r[e+1])){"*"===r[e+1]&&(t=i.length);break}if(f>" "){i[t]="# "+r;break}}return i.join("\n")}var a=n("os");r.exports={EOL:a.EOL||"\n",tryParseNumber:t,createComment:o,removeComment:i,getComment:f,forceComment:u}},{os:8}],3:[function(n,r,e){"use strict";function t(n,r){function e(n){return"[object Function]"==={}.toString.call(n)}if("[object Array]"!==Object.prototype.toString.apply(n)){if(n)throw new Error("dsf option must contain an array!");return i}if(0===n.length)return i;var t=[];return n.forEach(function(n){if(!n.name||!e(n.parse)||!e(n.stringify))throw new Error("extension does not match the DSF interface");t.push(function(){try{if("parse"==r)return n.parse.apply(null,arguments);if("stringify"==r){var e=n.stringify.apply(null,arguments);if(void 0!==e&&("string"!=typeof e||0===e.length||'"'===e[0]||[].some.call(e,function(n){return f(n)})))throw new Error("value may not be empty, start with a quote or contain a punctuator character except colon: "+e);return e}throw new Error("Invalid type")}catch(r){throw new Error("DSF-"+n.name+" failed; "+r.message)}})}),o.bind(null,t)}function o(n,r){if(n)for(var e=0;e<n.length;e++){var t=n[e](r);if(void 0!==t)return t}}function i(n){}function f(n){return"{"===n||"}"===n||"["===n||"]"===n||","===n}function u(n){return{name:"math",parse:function(n){switch(n){case"+inf":case"inf":case"+Inf":case"Inf":return 1/0;case"-inf":case"-Inf":return-(1/0);case"nan":case"NaN":return NaN}},stringify:function(n){if("number"==typeof n)return 1/n===-(1/0)?"-0":n===1/0?"Inf":n===-(1/0)?"-Inf":isNaN(n)?"NaN":void 0}}}function a(n){var r=n&&n.out;return{name:"hex",parse:function(n){if(/^0x[0-9A-Fa-f]+$/.test(n))return parseInt(n,16)},stringify:function(n){if(r&&Number.isInteger(n))return"0x"+n.toString(16)}}}function s(n){return{name:"date",parse:function(n){if(/^\d{4}-\d{2}-\d{2}$/.test(n)||/^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(?:.\d+)(?:Z|[+-]\d{2}:\d{2})$/.test(n)){var r=Date.parse(n);if(!isNaN(r))return new Date(r)}},stringify:function(n){if("[object Date]"===Object.prototype.toString.call(n)){var r=n.toISOString();return r.indexOf("T00:00:00.000Z",r.length-14)!==-1?r.substr(0,10):r}}}}n("./hjson-common");u.description="support for Inf/inf, -Inf/-inf, Nan/naN and -0",a.description="parse hexadecimal numbers prefixed with 0x",s.description="support ISO dates",r.exports={loadDsf:t,std:{math:u,hex:a,date:s}}},{"./hjson-common":2}],4:[function(n,r,e){"use strict";r.exports=function(r,e){function t(){w=0,O=" "}function o(n){return"{"===n||"}"===n||"["===n||"]"===n||","===n||":"===n}function i(n){var r,e=0,t=1;for(r=w-1;r>0&&"\n"!==x[r];r--,e++);for(;r>0;r--)"\n"===x[r]&&t++;throw new Error(n+" at line "+t+","+e+" >>>"+x.substr(w-e,20)+" ...")}function f(){return O=x.charAt(w),w++,O}function u(n){return x.charAt(w+n)}function a(){var n="";if('"'===O)for(;f();){if('"'===O)return f(),n;if("\\"===O)if(f(),"u"===O){for(var r=0,e=0;e<4;e++){f();var t,o=O.charCodeAt(0);O>="0"&&O<="9"?t=o-48:O>="a"&&O<="f"?t=o-97+10:O>="A"&&O<="F"?t=o-65+10:i("Bad \\u char "+O),r=16*r+t}n+=String.fromCharCode(r)}else{if("string"!=typeof N[O])break;n+=N[O]}else n+=O}i("Bad string")}function s(){function n(){for(var n=t;O&&O<=" "&&"\n"!==O&&n-- >0;)f()}for(var r="",e=0,t=0;;){var o=u(-t-5);if(!o||"\n"===o)break;t++}for(;O&&O<=" "&&"\n"!==O;)f();for("\n"===O&&(f(),n());;){if(O){if("'"===O){if(e++,f(),3===e)return"\n"===r.slice(-1)&&(r=r.slice(0,-1)),r;continue}for(;e>0;)r+="'",e--}else i("Bad multiline string");"\n"===O?(r+="\n",f(),n()):("\r"!==O&&(r+=O),f())}}function c(){if('"'===O)return a();for(var n="",r=w,e=-1;;){if(":"===O)return n?e>=0&&e!==n.length&&(w=r+e,i("Found whitespace in your key name (use quotes to include)")):i("Found ':' but no key name (for an empty key name use quotes)"),n;O<=" "?O?e<0&&(e=n.length):i("Found EOF while looking for a key name (check your syntax)"):o(O)?i("Found '"+O+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"):n+=O,f()}}function l(){for(;O;){for(;O&&O<=" ";)f();if("#"===O||"/"===O&&"/"===u(0))for(;O&&"\n"!==O;)f();else{if("/"!==O||"*"!==u(0))break;for(f(),f();O&&("*"!==O||"/"!==u(0));)f();O&&(f(),f())}}}function m(){var n=O;for(o(O)&&i("Found a punctuator character '"+O+"' when expecting a quoteless string (check your syntax)");;){if(f(),3===n.length&&"'''"===n)return s();var r="\r"===O||"\n"===O||""===O;if(r||","===O||"}"===O||"]"===O||"#"===O||"/"===O&&("/"===u(0)||"*"===u(0))){var e=n[0];switch(e){case"f":if("false"===n.trim())return!1;break;case"n":if("null"===n.trim())return null;break;case"t":if("true"===n.trim())return!0;break;default:if("-"===e||e>="0"&&e<="9"){var t=C.tryParseNumber(n);if(void 0!==t)return t}}if(r){n=n.trim();var a=E(n);return void 0!==a?a:n}}n+=O}}function p(n,r){var e;for(n--,e=w-2;e>n&&x[e]<=" "&&"\n"!==x[e];e--);"\n"===x[e]&&e--,"\r"===x[e]&&e--;var t=x.substr(n,e-n+1);for(e=0;e<t.length;e++)if(t[e]>" "){var o=t.indexOf("\n");if(o>=0){var i=[t.substr(0,o),t.substr(o+1)];return r&&0===i[0].trim().length&&i.shift(),i}return[t]}return[]}function h(n){function r(n,e){var t,o,i,f;switch(typeof n){case"string":n.indexOf(e)>=0&&(f=n);break;case"object":if("[object Array]"===Object.prototype.toString.apply(n))for(t=0,i=n.length;t<i;t++)f=r(n[t],e)||f;else for(o in n)Object.prototype.hasOwnProperty.call(n,o)&&(f=r(n[o],e)||f)}return f}function e(e){var t=r(n,e);return t?"found '"+e+"' in a string value, your mistake could be with:\n > "+t+"\n (unquoted strings contain everything up to the next line!)":""}return e("}")||e("]")}function d(){var n,r,e,t=[];try{if(k&&(n=C.createComment(t,{a:[]})),f(),r=w,l(),n&&(e=p(r,!0).join("\n")),"]"===O)return f(),n&&(n.e=[e]),t;for(;O;){if(t.push(v()),r=w,l(),","===O&&(f(),r=w,l()),n){var o=p(r);n.a.push([e||"",o[0]||""]),e=o[1]}if("]"===O)return f(),n&&(n.a[n.a.length-1][1]+=e||""),t;l()}i("End of input while parsing an array (missing ']')")}catch(n){throw n.hint=n.hint||h(t),n}}function y(n){var r,e,t,o="",u={};try{if(k&&(r=C.createComment(u,{c:{},o:[]})),n?e=1:(f(),e=w),l(),r&&(t=p(e,!0).join("\n")),"}"===O&&!n)return r&&(r.e=[t]),f(),u;for(;O;){if(o=c(),l(),":"!==O&&i("Expected ':' instead of '"+O+"'"),f(),u[o]=v(),e=w,l(),","===O&&(f(),e=w,l()),r){var a=p(e);r.c[o]=[t||"",a[0]||""],t=a[1],r.o.push(o)}if("}"===O&&!n)return f(),r&&(r.c[o][1]+=t||""),u;l()}if(n)return u;i("End of input while parsing an object (missing '}')")}catch(n){throw n.hint=n.hint||h(u),n}}function v(){switch(l(),O){case"{":return y();case"[":return d();case'"':return a();default:return m()}}function g(n,r){var e=w;if(l(),O&&i("Syntax error, found trailing characters"),k){var t=r.join("\n"),o=p(e).join("\n");if(o||t){var f=C.createComment(n,C.getComment(n));f.r=[t,o]}}return n}function b(){l();var n=k?p(1):null;switch(O){case"{":return g(y(),n);case"[":return g(d(),n)}try{return g(y(!0),n)}catch(r){t();try{return g(v(),n)}catch(n){throw r}}}function j(n,r){if("string"!=typeof n)throw new Error("source is not a string");var e=null;return r&&"object"==typeof r&&(k=r.keepWsc,e=r.dsf),E=S.loadDsf(e,"parse"),x=n,t(),b()}var x,w,O,k,E,C=n("./hjson-common"),S=n("./hjson-dsf"),N={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};return j(r,e)}},{"./hjson-common":2,"./hjson-dsf":3}],5:[function(n,r,e){"use strict";r.exports=function(r,e){function t(n,r){return n[0]+r+n[1]}function o(n){return n.replace(v,function(n){var r=x[n];return"string"==typeof r?t(E.esc,r):t(E.uni,("0000"+n.charCodeAt(0).toString(16)).slice(-4))})}function i(n,r,e,i){return n?(g.lastIndex=0,j.lastIndex=0,h||e||g.test(n)||void 0!==d.tryParseNumber(n,!0)||j.test(n)?(v.lastIndex=0,b.lastIndex=0,v.test(n)?b.test(n)||i?t(E.qstr,o(n)):f(n,r):t(E.qstr,n)):t(E.str,n)):t(E.qstr,"")}function f(n,r){var e,o=n.replace(/\r/g,"").split("\n");if(r+=k,1===o.length)return t(E.mstr,o[0]);var i=l+r+E.mstr[0];for(e=0;e<o.length;e++)i+=l,o[e]&&(i+=r+o[e]);return i+l+r+E.mstr[1]}function u(n){return n?w.test(n)?(v.lastIndex=0,t(E.qkey,v.test(n)?o(n):n)):t(E.key,n):'""'}function a(n,r,e,o){function f(n){return n&&"\n"===n["\r"===n[0]?1:0]}function s(n){return n&&!f(n)}function h(n,r,e){if(!n)return"";n=d.forceComment(n);var o,i=n.length;for(o=0;o<i&&n[o]<=" ";o++);return e&&o>0&&(n=n.substr(o)),o<i?r+t(E.rem,n):n}var y=c(n);if(void 0!==y)return t(E.dsf,y);switch(typeof n){case"string":return i(n,O,r,o);case"number":return isFinite(n)?t(E.num,String(n)):t(E.lit,"null");case"boolean":return t(E.lit,String(n));case"object":if(!n)return t(E.lit,"null");var v;m&&(v=d.getComment(n));var g="[object Array]"===Object.prototype.toString.apply(n),b=O;O+=k;var j,x,w,C,S,N,q=l+b,_=l+O,I=e||p?"":q,F=[];if(g){for(j=0,x=n.length;j<x;j++)v&&(S=v.a[j]||[],N=s(S[1]),F.push(h(S[0],"\n")+_)),F.push(a(n[j],!!v&&N,!0)||t(E.lit,"null")),v&&S[1]&&F.push(h(S[1],N?" ":"\n",N));v&&(0===x?F.push((v.e?h(v.e[0],"\n"):"")+q):F.push(q)),C=v?I+t(E.arr,F.join("")):0===F.length?t(E.arr,""):I+t(E.arr,_+F.join(_)+q)}else{if(v){var A=v.o.slice();for(w in n)Object.prototype.hasOwnProperty.call(n,w)&&A.indexOf(w)<0&&A.push(w);for(j=0,x=A.length;j<x;j++)w=A[j],S=v.c[w]||[],N=s(S[1]),F.push(h(S[0],"\n")+_),C=a(n[w],N),C&&F.push(u(w)+E.col+(f(C)?"":" ")+C),v&&S[1]&&F.push(h(S[1],N?" ":"\n",N));0===x?F.push((v.e?h(v.e[0],"\n"):"")+q):F.push(q)}else for(w in n)Object.prototype.hasOwnProperty.call(n,w)&&(C=a(n[w]),C&&F.push(u(w)+E.col+(f(C)?"":" ")+C));C=0===F.length?t(E.obj,""):v?I+t(E.obj,F.join("")):I+t(E.obj,_+F.join(_)+q)}return O=b,C}}function s(n,r){var e,t,o=null;if(l=d.EOL,k=" ",m=!1,p=!1,h=!1,r&&"object"==typeof r&&("\n"!==r.eol&&"\r\n"!==r.eol||(l=r.eol),t=r.space,m=r.keepWsc,p=r.bracesSameLine,h="always"===r.quotes,o=r.dsf,r.colors===!0&&(E={obj:["[30;1m{[0m","[30;1m}[0m"],arr:["[30;1m[[0m","[30;1m][0m"],key:["[33m","[0m"],qkey:['[33m"','"[0m'],col:["[37m:[0m"],str:["[37;1m","[0m"],qstr:['[37;1m"','"[0m'],mstr:["[37;1m'''","'''[0m"],num:["[36;1m","[0m"],lit:["[36m","[0m"],dsf:["[37m","[0m"],esc:["[31m\\","[0m"],uni:["[31m\\u","[0m"],rem:["[30;1m","[0m"]})),c=y.loadDsf(o,"stringify"),"number"==typeof t)for(k="",e=0;e<t;e++)k+=" ";else"string"==typeof t&&(k=t);var i="",f=m?f=(d.getComment(n)||{}).r:null;return f&&f[0]&&(i=f[0]+"\n"),i+=a(n,null,!0,!0),f&&(i+=f[1]||""),i}var c,l,m,p,h,d=n("./hjson-common"),y=n("./hjson-dsf"),v=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,g=/^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\}|^\[|^\]|^:|^,|\s$|[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,b=/'''|[\x00-\x09\x0b\x0c\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,j=/^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/,x={"\b":"b","\t":"t","\n":"n","\f":"f","\r":"r",'"':'"',"\\":"\\"},w=/[,\{\[\}\]\s:#"]|\/\/|\/\*|'''/,O="",k=" ",E={obj:["{","}"],arr:["[","]"],key:["",""],qkey:['"','"'],col:[":"],str:["",""],qstr:['"','"'],mstr:["'''","'''"],num:["",""],lit:["",""],dsf:["",""],esc:["\\",""],uni:["\\u",""],rem:["",""]};return s(r,e)}},{"./hjson-common":2,"./hjson-dsf":3}],6:[function(n,r,e){r.exports="2.3.1"},{}],7:[function(n,r,e){/*! @preserve | ||
* Hjson v2.3.1 | ||
!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.Hjson=n()}}(function(){return function n(r,e,t){function o(a,u){if(!e[a]){if(!r[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(i)return i(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=e[a]={exports:{}};r[a][0].call(c.exports,function(n){var e=r[a][1][n];return o(e?e:n)},c,c.exports,n,r,e,t)}return e[a].exports}for(var i="function"==typeof require&&require,a=0;a<t.length;a++)o(t[a]);return o}({1:[function(n,r,e){"use strict";function t(n,r,e){var t;return n&&(t={b:n}),r&&((t=t||{}).a=r),e&&((t=t||{}).x=e),t}function o(n,r){if(null!==n&&"object"==typeof n){var e=p.getComment(n);e&&p.removeComment(n);var i,a,s,f;if("[object Array]"===Object.prototype.toString.apply(n)){for(f={a:[]},i=0,a=n.length;i<a;i++)u(f.a,i,e.a[i],o(n[i]))&&(s=!0);!s&&e.e&&(f.e=t(e.e[0],e.e[1]),s=!0)}else{f={s:{}};var c,l=Object.keys(n);for(e&&e.o?(c=[],e.o.concat(l).forEach(function(r){Object.prototype.hasOwnProperty.call(n,r)&&c.indexOf(r)<0&&c.push(r)})):c=l,f.o=c,i=0,a=c.length;i<a;i++){var m=c[i];u(f.s,m,e.c[m],o(n[m]))&&(s=!0)}!s&&e.e&&(f.e=t(e.e[0],e.e[1]),s=!0)}return r&&e&&e.r&&(f.r=t(e.r[0],e.r[1])),s?f:void 0}}function i(){var n="";return[].forEach.call(arguments,function(r){r&&""!==r.trim()&&(n&&(n+="; "),n+=r.trim())}),n}function a(n,r){var e=[];if(c(n,r,e,[]),e.length>0){var t=l(r,null,1);t+="\n# Orphaned comments:\n",e.forEach(function(n){t+=("# "+n.path.join("/")+": "+i(n.b,n.a,n.e)).replace("\n","\\n ")+"\n"}),l(r,t,1)}}function u(n,r,e,o){var i=t(e?e[0]:void 0,e?e[1]:void 0,o);return i&&(n[r]=i),i}function s(n,r){var e=t(r.b,r.a);return e.path=n,e}function f(n,r,e){if(n){var t,o;if(n.a)for(t=0,o=n.a.length;t<o;t++){var i=e.slice().concat([t]),a=n.a[t];a&&(r.push(s(i,a)),f(a.x,r,i))}else n.o&&n.o.forEach(function(t){var o=e.slice().concat([t]),i=n.s[t];i&&(r.push(s(o,i)),f(i.x,r,o))});n.e&&r.push(s(e,n.e))}}function c(n,r,e,t){if(n){if(null===r||"object"!=typeof r)return void f(n,e,t);var o,i,a=p.createComment(r);if(0===t.length&&n.r&&(a.r=[n.r.b,n.r.a]),"[object Array]"===Object.prototype.toString.apply(r)){for(a.a=[],o=0,i=(n.a||[]).length;o<i;o++){var u=t.slice().concat([o]),l=n.a[o];l&&(o<r.length?(a.a.push([l.b,l.a]),c(l.x,r[o],e,u)):(e.push(s(u,l)),f(l.x,e,u)))}0===o&&n.e&&(a.e=[n.e.b,n.e.a])}else a.c={},a.o=[],(n.o||[]).forEach(function(o){var i=t.slice().concat([o]),u=n.s[o];Object.prototype.hasOwnProperty.call(r,o)?(a.o.push(o),u&&(a.c[o]=[u.b,u.a],c(u.x,r[o],e,i))):u&&(e.push(s(i,u)),f(u.x,e,i))}),n.e&&(a.e=[n.e.b,n.e.a])}}function l(n,r,e){var t=p.createComment(n,p.getComment(n));return t.r||(t.r=["",""]),(r||""===r)&&(t.r[e]=p.forceComment(r)),t.r[e]||""}var p=n("./hjson-common");r.exports={extract:function(n){return o(n,!0)},merge:a,header:function(n,r){return l(n,r,0)},footer:function(n,r){return l(n,r,1)}}},{"./hjson-common":2}],2:[function(n,r,e){"use strict";function t(n,r){function e(){return o=n.charAt(s),s++,o}var t,o,i="",a=0,u=!0,s=0;for(e(),"-"===o&&(i="-",e());o>="0"&&o<="9";)u&&("0"==o?a++:u=!1),i+=o,e();if(u&&a--,"."===o)for(i+=".";e()&&o>="0"&&o<="9";)i+=o;if("e"===o||"E"===o)for(i+=o,e(),"-"!==o&&"+"!==o||(i+=o,e());o>="0"&&o<="9";)i+=o,e();for(;o&&o<=" ";)e();return r&&(","!==o&&"}"!==o&&"]"!==o&&"#"!==o&&("/"!==o||"/"!==n[s]&&"*"!==n[s])||(o=0)),t=+i,o||a||!isFinite(t)?void 0:t}function o(n,r){return Object.defineProperty&&Object.defineProperty(n,"__COMMENTS__",{enumerable:!1,writable:!0}),n.__COMMENTS__=r||{}}function i(n){Object.defineProperty(n,"__COMMENTS__",{value:void 0})}function a(n){return n.__COMMENTS__}function u(n){if(!n)return"";var r,e,t,o,i=n.split("\n");for(t=0;t<i.length;t++)for(r=i[t],o=r.length,e=0;e<o;e++){var a=r[e];if("#"===a)break;if("/"===a&&("/"===r[e+1]||"*"===r[e+1])){"*"===r[e+1]&&(t=i.length);break}if(a>" "){i[t]="# "+r;break}}return i.join("\n")}var s=n("os");r.exports={EOL:s.EOL||"\n",tryParseNumber:t,createComment:o,removeComment:i,getComment:a,forceComment:u}},{os:8}],3:[function(n,r,e){"use strict";function t(n,r){function e(n){return"[object Function]"==={}.toString.call(n)}if("[object Array]"!==Object.prototype.toString.apply(n)){if(n)throw new Error("dsf option must contain an array!");return i}if(0===n.length)return i;var t=[];return n.forEach(function(n){if(!n.name||!e(n.parse)||!e(n.stringify))throw new Error("extension does not match the DSF interface");t.push(function(){try{if("parse"==r)return n.parse.apply(null,arguments);if("stringify"==r){var e=n.stringify.apply(null,arguments);if(void 0!==e&&("string"!=typeof e||0===e.length||'"'===e[0]||[].some.call(e,function(n){return a(n)})))throw new Error("value may not be empty, start with a quote or contain a punctuator character except colon: "+e);return e}throw new Error("Invalid type")}catch(r){throw new Error("DSF-"+n.name+" failed; "+r.message)}})}),o.bind(null,t)}function o(n,r){if(n)for(var e=0;e<n.length;e++){var t=n[e](r);if(void 0!==t)return t}}function i(){}function a(n){return"{"===n||"}"===n||"["===n||"]"===n||","===n}function u(){return{name:"math",parse:function(n){switch(n){case"+inf":case"inf":case"+Inf":case"Inf":return 1/0;case"-inf":case"-Inf":return-(1/0);case"nan":case"NaN":return NaN}},stringify:function(n){if("number"==typeof n)return 1/n===-(1/0)?"-0":n===1/0?"Inf":n===-(1/0)?"-Inf":isNaN(n)?"NaN":void 0}}}function s(n){var r=n&&n.out;return{name:"hex",parse:function(n){if(/^0x[0-9A-Fa-f]+$/.test(n))return parseInt(n,16)},stringify:function(n){if(r&&Number.isInteger(n))return"0x"+n.toString(16)}}}function f(){return{name:"date",parse:function(n){if(/^\d{4}-\d{2}-\d{2}$/.test(n)||/^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(?:.\d+)(?:Z|[+-]\d{2}:\d{2})$/.test(n)){var r=Date.parse(n);if(!isNaN(r))return new Date(r)}},stringify:function(n){if("[object Date]"===Object.prototype.toString.call(n)){var r=n.toISOString();return r.indexOf("T00:00:00.000Z",r.length-14)!==-1?r.substr(0,10):r}}}}u.description="support for Inf/inf, -Inf/-inf, Nan/naN and -0",s.description="parse hexadecimal numbers prefixed with 0x",f.description="support ISO dates",r.exports={loadDsf:t,std:{math:u,hex:s,date:f}}},{}],4:[function(n,r,e){"use strict";r.exports=function(r,e){function t(){w=0,x=" "}function o(n){return"{"===n||"}"===n||"["===n||"]"===n||","===n||":"===n}function i(n){var r,e=0,t=1;for(r=w-1;r>0&&"\n"!==j[r];r--,e++);for(;r>0;r--)"\n"===j[r]&&t++;throw new Error(n+" at line "+t+","+e+" >>>"+j.substr(w-e,20)+" ...")}function a(){return x=j.charAt(w),w++,x}function u(n){return j.charAt(w+n)}function s(){var n="";if('"'===x)for(;a();){if('"'===x)return a(),n;if("\\"===x)if(a(),"u"===x){for(var r=0,e=0;e<4;e++){a();var t,o=x.charCodeAt(0);x>="0"&&x<="9"?t=o-48:x>="a"&&x<="f"?t=o-97+10:x>="A"&&x<="F"?t=o-65+10:i("Bad \\u char "+x),r=16*r+t}n+=String.fromCharCode(r)}else{if("string"!=typeof q[x])break;n+=q[x]}else n+=x}i("Bad string")}function f(){function n(){for(var n=t;x&&x<=" "&&"\n"!==x&&n-- >0;)a()}for(var r="",e=0,t=0;;){var o=u(-t-5);if(!o||"\n"===o)break;t++}for(;x&&x<=" "&&"\n"!==x;)a();for("\n"===x&&(a(),n());;){if(x){if("'"===x){if(e++,a(),3===e)return"\n"===r.slice(-1)&&(r=r.slice(0,-1)),r;continue}for(;e>0;)r+="'",e--}else i("Bad multiline string");"\n"===x?(r+="\n",a(),n()):("\r"!==x&&(r+=x),a())}}function c(){if('"'===x)return s();for(var n="",r=w,e=-1;;){if(":"===x)return n?e>=0&&e!==n.length&&(w=r+e,i("Found whitespace in your key name (use quotes to include)")):i("Found ':' but no key name (for an empty key name use quotes)"),n;x<=" "?x?e<0&&(e=n.length):i("Found EOF while looking for a key name (check your syntax)"):o(x)?i("Found '"+x+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"):n+=x,a()}}function l(){for(;x;){for(;x&&x<=" ";)a();if("#"===x||"/"===x&&"/"===u(0))for(;x&&"\n"!==x;)a();else{if("/"!==x||"*"!==u(0))break;for(a(),a();x&&("*"!==x||"/"!==u(0));)a();x&&(a(),a())}}}function p(){var n=x;for(o(x)&&i("Found a punctuator character '"+x+"' when expecting a quoteless string (check your syntax)");;){if(a(),3===n.length&&"'''"===n)return f();var r="\r"===x||"\n"===x||""===x;if(r||","===x||"}"===x||"]"===x||"#"===x||"/"===x&&("/"===u(0)||"*"===u(0))){var e=n[0];switch(e){case"f":if("false"===n.trim())return!1;break;case"n":if("null"===n.trim())return null;break;case"t":if("true"===n.trim())return!0;break;default:if("-"===e||e>="0"&&e<="9"){var t=E.tryParseNumber(n);if(void 0!==t)return t}}if(r){n=n.trim();var s=k(n);return void 0!==s?s:n}}n+=x}}function m(n,r){var e;for(n--,e=w-2;e>n&&j[e]<=" "&&"\n"!==j[e];e--);"\n"===j[e]&&e--,"\r"===j[e]&&e--;var t=j.substr(n,e-n+1);for(e=0;e<t.length;e++)if(t[e]>" "){var o=t.indexOf("\n");if(o>=0){var i=[t.substr(0,o),t.substr(o+1)];return r&&0===i[0].trim().length&&i.shift(),i}return[t]}return[]}function h(n){function r(n,e){var t,o,i,a;switch(typeof n){case"string":n.indexOf(e)>=0&&(a=n);break;case"object":if("[object Array]"===Object.prototype.toString.apply(n))for(t=0,i=n.length;t<i;t++)a=r(n[t],e)||a;else for(o in n)Object.prototype.hasOwnProperty.call(n,o)&&(a=r(n[o],e)||a)}return a}function e(e){var t=r(n,e);return t?"found '"+e+"' in a string value, your mistake could be with:\n > "+t+"\n (unquoted strings contain everything up to the next line!)":""}return e("}")||e("]")}function d(){var n,r,e,t=[];try{if(O&&(n=E.createComment(t,{a:[]})),a(),r=w,l(),n&&(e=m(r,!0).join("\n")),"]"===x)return a(),n&&(n.e=[e]),t;for(;x;){if(t.push(v()),r=w,l(),","===x&&(a(),r=w,l()),n){var o=m(r);n.a.push([e||"",o[0]||""]),e=o[1]}if("]"===x)return a(),n&&(n.a[n.a.length-1][1]+=e||""),t;l()}i("End of input while parsing an array (missing ']')")}catch(n){throw n.hint=n.hint||h(t),n}}function y(n){var r,e,t,o="",u={};try{if(O&&(r=E.createComment(u,{c:{},o:[]})),n?e=1:(a(),e=w),l(),r&&(t=m(e,!0).join("\n")),"}"===x&&!n)return r&&(r.e=[t]),a(),u;for(;x;){if(o=c(),l(),":"!==x&&i("Expected ':' instead of '"+x+"'"),a(),u[o]=v(),e=w,l(),","===x&&(a(),e=w,l()),r){var s=m(e);r.c[o]=[t||"",s[0]||""],t=s[1],r.o.push(o)}if("}"===x&&!n)return a(),r&&(r.c[o][1]+=t||""),u;l()}if(n)return u;i("End of input while parsing an object (missing '}')")}catch(n){throw n.hint=n.hint||h(u),n}}function v(){switch(l(),x){case"{":return y();case"[":return d();case'"':return s();default:return p()}}function g(n,r){var e=w;if(l(),x&&i("Syntax error, found trailing characters"),O){var t=r.join("\n"),o=m(e).join("\n");if(o||t){var a=E.createComment(n,E.getComment(n));a.r=[t,o]}}return n}function b(){l();var n=O?m(1):null;switch(x){case"{":return g(y(),n);case"[":return g(d(),n)}try{return g(y(!0),n)}catch(r){t();try{return g(v(),n)}catch(n){throw r}}}var j,w,x,O,k,E=n("./hjson-common"),C=n("./hjson-dsf"),q={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:"\t"};if("string"!=typeof r)throw new Error("source is not a string");var S=null;return e&&"object"==typeof e&&(O=e.keepWsc,S=e.dsf),k=C.loadDsf(S,"parse"),j=r,t(),b()}},{"./hjson-common":2,"./hjson-dsf":3}],5:[function(n,r,e){"use strict";r.exports=function(r,e){function t(n,r){return n[0]+r+n[1]}function o(n){return n.replace(x,function(n){var r=C[n];return"string"==typeof r?t(N.esc,r):t(N.uni,("0000"+n.charCodeAt(0).toString(16)).slice(-4))})}function i(n,r,e,i){return n?(O.lastIndex=0,E.lastIndex=0,y||e||O.test(n)||void 0!==f.tryParseNumber(n,!0)||E.test(n)?(x.lastIndex=0,k.lastIndex=0,x.test(n)?k.test(n)||i||!v?t(N.qstr,o(n)):a(n,r):t(N.qstr,n)):t(N.str,n)):t(N.qstr,"")}function a(n,r){var e,o=n.replace(/\r/g,"").split("\n");if(r+=p,1===o.length)return t(N.mstr,o[0]);var i=l+r+N.mstr[0];for(e=0;e<o.length;e++)i+=l,o[e]&&(i+=r+o[e]);return i+l+r+N.mstr[1]}function u(n){return n?d||q.test(n)?(x.lastIndex=0,t(N.qkey,x.test(n)?o(n):n)):t(N.key,n):'""'}function s(n,r,e,o){function a(n){return n&&"\n"===n["\r"===n[0]?1:0]}function c(n){return n&&!a(n)}function d(n,r,e){if(!n)return"";n=f.forceComment(n);var o,i=n.length;for(o=0;o<i&&n[o]<=" ";o++);return e&&o>0&&(n=n.substr(o)),o<i?r+t(N.rem,n):n}var y=j(n);if(void 0!==y)return t(N.dsf,y);switch(typeof n){case"string":return i(n,S,r,o);case"number":return isFinite(n)?t(N.num,String(n)):t(N.lit,"null");case"boolean":return t(N.lit,String(n));case"object":if(!n)return t(N.lit,"null");var v;m&&(v=f.getComment(n));var b="[object Array]"===Object.prototype.toString.apply(n),w=S;S+=p;var x,O,k,E,C,q,_=l+w,I=l+S,F=e||h?"":_,A=[];if(b){for(x=0,O=n.length;x<O;x++)v&&(C=v.a[x]||[],q=c(C[1]),A.push(d(C[0],"\n")+I)),A.push(s(n[x],!!v&&q,!0)+(x<O-1?g:"")||t(N.lit,"null")),v&&C[1]&&A.push(d(C[1],q?" ":"\n",q));v&&(0===O?A.push((v.e?d(v.e[0],"\n"):"")+_):A.push(_)),E=v?F+t(N.arr,A.join("")):0===A.length?t(N.arr,""):F+t(N.arr,I+A.join(I)+_)}else{var P;if(v){P=v.o.slice();for(k in n)Object.prototype.hasOwnProperty.call(n,k)&&P.indexOf(k)<0&&P.push(k);for(x=0,O=P.length;x<O;x++)k=P[x],C=v.c[k]||[],q=c(C[1]),A.push(d(C[0],"\n")+I),E=s(n[k],q),E&&A.push(u(k)+N.col+(a(E)?"":" ")+E+(x<O-1?g:"")),v&&C[1]&&A.push(d(C[1],q?" ":"\n",q));0===O?A.push((v.e?d(v.e[0],"\n"):"")+_):A.push(_)}else for(P=Object.keys(n),x=0,O=P.length;x<O;x++)k=P[x],Object.prototype.hasOwnProperty.call(n,k)&&(E=s(n[k]),E&&A.push(u(k)+N.col+(a(E)?"":" ")+E+(x<O-1?g:"")));E=0===A.length?t(N.obj,""):v?F+t(N.obj,A.join("")):F+t(N.obj,I+A.join(I)+_)}return S=w,E}}var f=n("./hjson-common"),c=n("./hjson-dsf"),l=f.EOL,p=" ",m=!1,h=!1,d=!1,y=!1,v=1,g="",b=null;e&&"object"==typeof e&&(e.quotes="always"===e.quotes?"strings":e.quotes,"\n"!==e.eol&&"\r\n"!==e.eol||(l=e.eol),m=e.keepWsc,h=e.bracesSameLine,d="all"===e.quotes||"keys"===e.quotes,y="all"===e.quotes||"strings"===e.quotes||e.separator===!0,v=y||"off"==e.multiline?0:"no-tabs"==e.multiline?2:1,g=e.separator===!0?",":"",b=e.dsf,"number"==typeof e.space?p=new Array(e.space+1).join(" "):"string"==typeof e.space&&(p=e.space),e.colors===!0&&(N={obj:["[30;1m{[0m","[30;1m}[0m"],arr:["[30;1m[[0m","[30;1m][0m"],key:["[33m","[0m"],qkey:['[33m"','"[0m'],col:["[37m:[0m"],str:["[37;1m","[0m"],qstr:['[37;1m"','"[0m'],mstr:["[37;1m'''","'''[0m"],num:["[36;1m","[0m"],lit:["[36m","[0m"],dsf:["[37m","[0m"],esc:["[31m\\","[0m"],uni:["[31m\\u","[0m"],rem:["[30;1m","[0m"]}));var j,w="--឴឵-\u2028- -\ufeff-",x=new RegExp('[\\\\\\"\0-'+w+"]","g"),O=new RegExp("^\\s|^\"|^'''|^#|^\\/\\*|^\\/\\/|^\\{|^\\}|^\\[|^\\]|^:|^,|\\s$|[\0-"+w+"]","g"),k=new RegExp("'''|^[\\s]+$|[\0-"+(2===v?"\t":"\b")+"\v\f-"+w+"]","g"),E=new RegExp("^(true|false|null)\\s*((,|\\]|\\}|#|//|/\\*).*)?$"),C={"\b":"b","\t":"t","\n":"n","\f":"f","\r":"r",'"':'"',"\\":"\\"},q=/[,\{\[\}\]\s:#"]|\/\/|\/\*|'''/,S="",N={obj:["{","}"],arr:["[","]"],key:["",""],qkey:['"','"'],col:[":"],str:["",""],qstr:['"','"'],mstr:["'''","'''"],num:["",""],lit:["",""],dsf:["",""],esc:["\\",""],uni:["\\u",""],rem:["",""]};j=c.loadDsf(b,"stringify");var _="",I=m?I=(f.getComment(r)||{}).r:null;return I&&I[0]&&(_=I[0]+"\n"),_+=s(r,null,!0,!0),I&&(_+=I[1]||""),_}},{"./hjson-common":2,"./hjson-dsf":3}],6:[function(n,r,e){r.exports="2.4.0"},{}],7:[function(n,r,e){/*! @preserve | ||
* Hjson v2.4.0 | ||
* http://hjson.org | ||
@@ -12,2 +12,2 @@ * | ||
*/ | ||
"use strict";var t=n("./hjson-common"),o=n("./hjson-version"),i=n("./hjson-parse"),f=n("./hjson-stringify"),u=n("./hjson-comments"),a=n("./hjson-dsf");r.exports={parse:i,stringify:f,endOfLine:function(){return t.EOL},setEndOfLine:function(n){"\n"!==n&&"\r\n"!==n||(t.EOL=n)},version:o,rt:{parse:function(n,r){return(r=r||{}).keepWsc=!0,i(n,r)},stringify:function(n,r){return(r=r||{}).keepWsc=!0,f(n,r)}},comments:u,dsf:a.std}},{"./hjson-comments":1,"./hjson-common":2,"./hjson-dsf":3,"./hjson-parse":4,"./hjson-stringify":5,"./hjson-version":6}],8:[function(n,r,e){},{}]},{},[7])(7)}); | ||
"use strict";var t=n("./hjson-common"),o=n("./hjson-version"),i=n("./hjson-parse"),a=n("./hjson-stringify"),u=n("./hjson-comments"),s=n("./hjson-dsf");r.exports={parse:i,stringify:a,endOfLine:function(){return t.EOL},setEndOfLine:function(n){"\n"!==n&&"\r\n"!==n||(t.EOL=n)},version:o,rt:{parse:function(n,r){return(r=r||{}).keepWsc=!0,i(n,r)},stringify:function(n,r){return(r=r||{}).keepWsc=!0,a(n,r)}},comments:u,dsf:s.std}},{"./hjson-comments":1,"./hjson-common":2,"./hjson-dsf":3,"./hjson-parse":4,"./hjson-stringify":5,"./hjson-version":6}],8:[function(n,r,e){},{}]},{},[7])(7)}); |
# hjson-js History | ||
- v2.4.0 | ||
- new stringify options: | ||
- quotes for keys and strings (SamVerschueren) | ||
- comma separator (SamVerschueren) | ||
- multiline strings output (hmalphettes) | ||
- v2.3.1 | ||
@@ -4,0 +9,0 @@ - add comments api (merge/extract) |
@@ -5,4 +5,2 @@ /* Hjson http://hjson.org */ | ||
var common = require("./hjson-common"); | ||
function loadDsf(col, type) { | ||
@@ -53,3 +51,3 @@ | ||
function nopDsf(value) { | ||
function nopDsf(/*value*/) { | ||
} | ||
@@ -62,3 +60,3 @@ | ||
function math(opt) { | ||
function math(/*opt*/) { | ||
return { | ||
@@ -105,3 +103,3 @@ name: "math", | ||
function date(opt) { | ||
function date(/*opt*/) { | ||
return { | ||
@@ -108,0 +106,0 @@ name: "date", |
@@ -5,3 +5,3 @@ /* Hjson http://hjson.org */ | ||
module.exports = function($source, $opt) { | ||
module.exports = function(source, opt) { | ||
@@ -99,3 +99,3 @@ var common = require("./hjson-common"); | ||
var indent = 0; | ||
while (true) { | ||
for (;;) { | ||
var c=peek(-indent-5); | ||
@@ -116,3 +116,3 @@ if (!c || c === '\n') break; | ||
// When parsing multiline string values, we must look for ' characters. | ||
while (true) { | ||
for (;;) { | ||
if (!ch) { | ||
@@ -151,3 +151,3 @@ error("Bad multiline string"); | ||
var name = "", start = at, space = -1; | ||
while (true) { | ||
for (;;) { | ||
if (ch === ':') { | ||
@@ -430,16 +430,12 @@ if (!name) error("Found ':' but no key name (for an empty key name use quotes)"); | ||
function hjsonParse(source, opt) { | ||
if (typeof source!=="string") throw new Error("source is not a string"); | ||
var dsfDef = null; | ||
if (opt && typeof opt === 'object') { | ||
keepComments = opt.keepWsc; | ||
dsfDef = opt.dsf; | ||
} | ||
runDsf = dsf.loadDsf(dsfDef, "parse"); | ||
text = source; | ||
resetAt(); | ||
return rootValue(); | ||
if (typeof source!=="string") throw new Error("source is not a string"); | ||
var dsfDef = null; | ||
if (opt && typeof opt === 'object') { | ||
keepComments = opt.keepWsc; | ||
dsfDef = opt.dsf; | ||
} | ||
return hjsonParse($source, $opt); | ||
runDsf = dsf.loadDsf(dsfDef, "parse"); | ||
text = source; | ||
resetAt(); | ||
return rootValue(); | ||
}; |
@@ -5,3 +5,3 @@ /* Hjson http://hjson.org */ | ||
module.exports = function($value, $opt) { | ||
module.exports = function(data, opt) { | ||
@@ -11,14 +11,69 @@ var common = require("./hjson-common"); | ||
// options | ||
var eol = common.EOL; | ||
var indent = ' '; | ||
var keepComments = false; | ||
var bracesSameLine = false; | ||
var quoteKeys = false; | ||
var quoteStrings = false; | ||
var multiline = 1; // std=1, no-tabs=2, off=0 | ||
var separator = ''; // comma separator | ||
var dsfDef = null; | ||
if (opt && typeof opt === 'object') { | ||
opt.quotes = opt.quotes === 'always' ? 'strings' : opt.quotes; // legacy | ||
if (opt.eol === '\n' || opt.eol === '\r\n') eol = opt.eol; | ||
keepComments = opt.keepWsc; | ||
bracesSameLine = opt.bracesSameLine; | ||
quoteKeys = opt.quotes === 'all' || opt.quotes === 'keys'; | ||
quoteStrings = opt.quotes === 'all' || opt.quotes === 'strings' || opt.separator === true; | ||
if (quoteStrings || opt.multiline == 'off') multiline = 0; | ||
else multiline = opt.multiline == 'no-tabs' ? 2 : 1; | ||
separator = opt.separator === true ? ',' : ''; | ||
dsfDef = opt.dsf; | ||
// If the space parameter is a number, make an indent string containing that | ||
// many spaces. If it is a string, it will be used as the indent string. | ||
if (typeof opt.space === 'number') { | ||
indent = new Array(opt.space + 1).join(' '); | ||
} else if (typeof opt.space === 'string') { | ||
indent = opt.space; | ||
} | ||
if (opt.colors === true) { | ||
token = { | ||
obj: [ '\x1b[30;1m{\x1b[0m', '\x1b[30;1m}\x1b[0m' ], | ||
arr: [ '\x1b[30;1m[\x1b[0m', '\x1b[30;1m]\x1b[0m' ], | ||
key: [ '\x1b[33m', '\x1b[0m' ], | ||
qkey: [ '\x1b[33m"', '"\x1b[0m' ], | ||
col: [ '\x1b[37m:\x1b[0m' ], | ||
str: [ '\x1b[37;1m', '\x1b[0m' ], | ||
qstr: [ '\x1b[37;1m"', '"\x1b[0m' ], | ||
mstr: [ "\x1b[37;1m'''", "'''\x1b[0m" ], | ||
num: [ '\x1b[36;1m', '\x1b[0m' ], | ||
lit: [ '\x1b[36m', '\x1b[0m' ], | ||
dsf: [ '\x1b[37m', '\x1b[0m' ], | ||
esc: [ '\x1b[31m\\', '\x1b[0m' ], | ||
uni: [ '\x1b[31m\\u', '\x1b[0m' ], | ||
rem: [ '\x1b[30;1m', '\x1b[0m' ], | ||
}; | ||
} | ||
} | ||
// | ||
var runDsf; // domain specific formats | ||
var commonRange='\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff'; | ||
// needsEscape tests if the string can be written without escapes | ||
var needsEscape = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; | ||
// needsQuotes tests if the string can be written as a quoteless string (includes needsEscape but without \\ and \") | ||
var needsQuotes = /^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\}|^\[|^\]|^:|^,|\s$|[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; | ||
// needsEscapeML tests if the string can be written as a multiline string (includes needsEscape but without \n, \r, \\ 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; | ||
var needsEscape = new RegExp('[\\\\\\"\x00-\x1f'+commonRange+']', 'g'); | ||
// needsQuotes tests if the string can be written as a quoteless string (like needsEscape but without \\ and \") | ||
var needsQuotes = new RegExp('^\\s|^"|^\'\'\'|^#|^\\/\\*|^\\/\\/|^\\{|^\\}|^\\[|^\\]|^:|^,|\\s$|[\x00-\x1f'+commonRange+']', 'g'); | ||
// needsEscapeML tests if the string can be written as a multiline string (like needsEscape but without \n, \r, \\, \", \t unless multines is 'std') | ||
var needsEscapeML = new RegExp('\'\'\'|^[\\s]+$|[\x00-'+(multiline === 2 ? '\x09' : '\x08')+'\x0b\x0c\x0e-\x1f'+commonRange+']', 'g'); | ||
// starts with a keyword and optionally is followed by a comment | ||
var startsWithKeyword = /^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/; | ||
var meta = | ||
{ // table of character substitutions | ||
var startsWithKeyword = new RegExp('^(true|false|null)\\s*((,|\\]|\\}|#|//|/\\*).*)?$'); | ||
var meta = { | ||
// table of character substitutions | ||
'\b': 'b', | ||
@@ -34,5 +89,2 @@ '\t': 't', | ||
var gap = ''; | ||
var indent = ' '; | ||
// options | ||
var eol, keepComments, bracesSameLine, quoteAlways; | ||
var token = { | ||
@@ -74,3 +126,3 @@ obj: [ '{', '}' ], | ||
if (quoteAlways || hasComment || | ||
if (quoteStrings || hasComment || | ||
needsQuotes.test(string) || | ||
@@ -89,3 +141,3 @@ common.tryParseNumber(string, true) !== undefined || | ||
if (!needsEscape.test(string)) return wrap(token.qstr, string); | ||
else if (!needsEscapeML.test(string) && !isRootObject) return mlString(string, gap); | ||
else if (!needsEscapeML.test(string) && !isRootObject && multiline) return mlString(string, gap); | ||
else return wrap(token.qstr, quoteReplace(string)); | ||
@@ -124,3 +176,3 @@ } else { | ||
if (needsEscapeName.test(name)) { | ||
if (quoteKeys || needsEscapeName.test(name)) { | ||
needsEscape.lastIndex = 0; | ||
@@ -202,3 +254,3 @@ return wrap(token.qkey, needsEscape.test(name) ? quoteReplace(name) : name); | ||
} | ||
partial.push(str(value[i], comments ? ca : false, true) || wrap(token.lit, 'null')); | ||
partial.push(str(value[i], comments ? ca : false, true) + (i < length -1 ? separator : '') || wrap(token.lit, 'null')); | ||
if (comments && c[1]) partial.push(makeComment(c[1], ca ? " " : "\n", ca)); | ||
@@ -223,5 +275,6 @@ } | ||
// Otherwise, iterate through all of the keys in the object. | ||
var keys; | ||
if (comments) { | ||
var keys = comments.o.slice(); | ||
keys = comments.o.slice(); | ||
for (k in value) { | ||
@@ -239,3 +292,3 @@ if (Object.prototype.hasOwnProperty.call(value, k) && keys.indexOf(k) < 0) | ||
v = str(value[k], ca); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v + (i < length - 1 ? separator : '')); | ||
if (comments && c[1]) partial.push(makeComment(c[1], ca ? " " : "\n", ca)); | ||
@@ -250,6 +303,9 @@ } | ||
} else { | ||
for (k in value) { | ||
keys = Object.keys(value); | ||
for (i = 0, length = keys.length; i < length; i++) { | ||
k = keys[i]; | ||
if (Object.prototype.hasOwnProperty.call(value, k)) { | ||
v = str(value[k]); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v); | ||
if (v) partial.push(quoteKey(k) + token.col + (startsWithNL(v) ? '' : ' ') + v + (i < length - 1 ? separator : '')); | ||
} | ||
@@ -274,65 +330,15 @@ } | ||
function hjsonStringify(value, opt) { | ||
var i, space; | ||
var dsfDef = null; | ||
eol = common.EOL; | ||
indent = ' '; | ||
keepComments = false; | ||
bracesSameLine = false; | ||
quoteAlways = false; | ||
runDsf = dsf.loadDsf(dsfDef, 'stringify'); | ||
if (opt && typeof opt === 'object') { | ||
if (opt.eol === '\n' || opt.eol === '\r\n') eol = opt.eol; | ||
space = opt.space; | ||
keepComments = opt.keepWsc; | ||
bracesSameLine = opt.bracesSameLine; | ||
quoteAlways = opt.quotes === 'always'; | ||
dsfDef = opt.dsf; | ||
var res = ""; | ||
var comments = keepComments ? comments = (common.getComment(data) || {}).r : null; | ||
if (comments && comments[0]) res = comments[0] + '\n'; | ||
if (opt.colors === true) { | ||
token = { | ||
obj: [ '\x1b[30;1m{\x1b[0m', '\x1b[30;1m}\x1b[0m' ], | ||
arr: [ '\x1b[30;1m[\x1b[0m', '\x1b[30;1m]\x1b[0m' ], | ||
key: [ '\x1b[33m', '\x1b[0m' ], | ||
qkey: [ '\x1b[33m"', '"\x1b[0m' ], | ||
col: [ '\x1b[37m:\x1b[0m' ], | ||
str: [ '\x1b[37;1m', '\x1b[0m' ], | ||
qstr: [ '\x1b[37;1m"', '"\x1b[0m' ], | ||
mstr: [ "\x1b[37;1m'''", "'''\x1b[0m" ], | ||
num: [ '\x1b[36;1m', '\x1b[0m' ], | ||
lit: [ '\x1b[36m', '\x1b[0m' ], | ||
dsf: [ '\x1b[37m', '\x1b[0m' ], | ||
esc: [ '\x1b[31m\\', '\x1b[0m' ], | ||
uni: [ '\x1b[31m\\u', '\x1b[0m' ], | ||
rem: [ '\x1b[30;1m', '\x1b[0m' ], | ||
}; | ||
} | ||
} | ||
// get the result of stringifying the data. | ||
res += str(data, null, true, true); | ||
runDsf = dsf.loadDsf(dsfDef, 'stringify'); | ||
if (comments) res += comments[1]||""; | ||
// If the space parameter is a number, make an indent string containing that | ||
// many spaces. If it is a string, it will be used as the indent string. | ||
if (typeof space === 'number') { | ||
indent = ''; | ||
for (i = 0; i < space; i++) indent += ' '; | ||
} else if (typeof space === 'string') { | ||
indent = space; | ||
} | ||
var res = ""; | ||
var comments = keepComments ? comments = (common.getComment(value) || {}).r : null; | ||
if (comments && comments[0]) res = comments[0] + '\n'; | ||
// get the result of stringifying the value. | ||
res += str(value, null, true, true); | ||
if (comments) res += comments[1]||""; | ||
return res; | ||
} | ||
return hjsonStringify($value, $opt); | ||
return res; | ||
}; |
@@ -1,1 +0,1 @@ | ||
module.exports="2.3.1"; | ||
module.exports="2.4.0"; |
/*! @preserve | ||
* Hjson v2.3.1 | ||
* Hjson v2.4.0 | ||
* http://hjson.org | ||
@@ -48,5 +48,17 @@ * | ||
quotes string, controls how strings are displayed. | ||
setting separator implies "strings" | ||
"min" - no quotes whenever possible (default) | ||
"always" - always use quotes | ||
"keys" - use quotes around keys | ||
"strings" - use quotes around string values | ||
"all" - use quotes around keys and string values | ||
multiline string, controls how multiline strings are displayed. | ||
setting quotes implies "off" | ||
"std" - strings containing \n are shown in | ||
multiline format (default) | ||
"no-tabs" - like std but disallow tabs | ||
"off" - show in JSON format | ||
separator boolean, output a comma separator between elements. Default false. | ||
space specifies the indentation of nested structures. If it is | ||
@@ -53,0 +65,0 @@ a number, it will specify the number of spaces to indent |
@@ -6,3 +6,3 @@ { | ||
"author": "Christian Zangl", | ||
"version": "2.3.1", | ||
"version": "2.4.0", | ||
"keywords": [ | ||
@@ -22,7 +22,8 @@ "json", | ||
"test": "node ./test/test.js", | ||
"lint": "jshint bin/hjson lib/*.js", | ||
"min": "browserify lib/hjson.js --ignore os -s Hjson -o bundle/hjson.js && node node_modules/uglify-js/bin/uglifyjs bundle/hjson.js --comments -c -m -o bundle/hjson.min.js", | ||
"ver": "node -e 'console.log(\"module.exports=\\\"\"+eval(\"(\"+process.argv[1]+\")\").version+\"\\\";\");' -- \"`cat package.json`\" > lib/hjson-version.js", | ||
"ver2": "node -e 'var v=\" * Hjson v\"+eval(\"(\"+process.argv[1]+\")\").version; if (v!==process.argv[2]) throw new Error(\"ver\");' -- \"`cat package.json`\" \"`grep -E '\\* Hjson v.*$' lib/hjson.js`\"", | ||
"prep": "npm run ver && npm run ver2 && npm run test && npm run lint && npm run min" | ||
"lint": "node_modules/eslint/bin/eslint.js -f unix bin/hjson lib/*.js", | ||
"build_v1": "node -e 'console.log(\"module.exports=\\\"\"+eval(\"(\"+process.argv[1]+\")\").version+\"\\\";\");' -- \"`cat package.json`\" > lib/hjson-version.js", | ||
"build_v2": "node -e 'var v=\" * Hjson v\"+eval(\"(\"+process.argv[1]+\")\").version; if (v!==process.argv[2]) throw new Error(\"ver\");' -- \"`cat package.json`\" \"`grep -E '\\* Hjson v.*$' lib/hjson.js`\"", | ||
"build_bundle": "node_modules/browserify/bin/cmd.js lib/hjson.js --ignore os -s Hjson -o bundle/hjson.js", | ||
"build_min": "node node_modules/uglify-js/bin/uglifyjs bundle/hjson.js --comments -c -m -o bundle/hjson.min.js", | ||
"build": "npm run build_v1 && npm run build_v2 && npm run test && npm run lint && npm run build_bundle && npm run build_min" | ||
}, | ||
@@ -39,4 +40,6 @@ "homepage": "http://hjson.org", | ||
"devDependencies": { | ||
"browserify": "^13.1.1", | ||
"eslint": "^3.12.2", | ||
"uglify-js": "^2.4.24" | ||
} | ||
} |
@@ -70,7 +70,10 @@ # hjson-js | ||
(-c | -json=compact) output as JSON. | ||
-sl output the opening brace on the same line (Hjson) | ||
-noroot omit braces for the root object (Hjson) | ||
-quote quote all strings (Hjson) | ||
-rt round trip comments (Hjson) | ||
-nocol disable colors (Hjson) | ||
Options for Hjson output: | ||
-sl output the opening brace on the same line | ||
-quote quote all strings | ||
-quote=all quote keys as well | ||
-js output in JavaScript/JSON compatible format | ||
can be used with -rt and // comments | ||
-rt round trip comments | ||
-nocol disable colors | ||
@@ -112,5 +115,12 @@ Domain specific formats are optional extensions to Hjson and can be enabled with the following options: | ||
- *emitRootBraces*: boolean, show braces for the root object. Default true. | ||
- *quotes*: string, controls how strings are displayed. | ||
- *quotes*: string, controls how strings are displayed. (setting separator implies "strings") | ||
- "min": no quotes whenever possible (default) | ||
- "always": always use quotes | ||
- "keys": use quotes around keys | ||
- "strings": use quotes around string values | ||
- "all": use quotes around keys and string values | ||
- *multiline*: string, controls how multiline strings are displayed. (setting quotes implies "off") | ||
- "std": strings containing \n are shown in multiline format (default) | ||
- "no-tabs": like std but disallow tabs | ||
- "off": show in JSON format | ||
- *separator*: boolean, output a comma separator between elements. Default false | ||
- *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. | ||
@@ -156,5 +166,9 @@ - *eol*: specifies the EOL sequence (default is set by Hjson.setEndOfLine()) | ||
``` | ||
# Build | ||
To run all tests and create the bundle output, first install the dev dependencies with `npm i` and then run `npm run build`. | ||
# History | ||
[see history.md](history.md) | ||
@@ -8,2 +8,6 @@ { | ||
"text4c": "untrimmed ", | ||
"notml1": "\n", | ||
"notml2": " \n", | ||
"notml3": "\n \n \n \n", | ||
"notml4": "\t\n", | ||
"multiline1": "first line\n indented line\nlast line", | ||
@@ -10,0 +14,0 @@ "multiline2": "first line\n indented line\nlast line", |
@@ -66,2 +66,3 @@ charset_test.hjson | ||
keys_test.hjson | ||
mltabs_test.json | ||
oa_test.hjson | ||
@@ -76,2 +77,9 @@ pass1_test.json | ||
strings_test.hjson | ||
trail_test.hjson | ||
trail_test.hjson | ||
stringify/quotes_all_test.hjson | ||
stringify/quotes_always_test.hjson | ||
stringify/quotes_keys_test.hjson | ||
stringify/quotes_strings_ml_test.json | ||
stringify/quotes_strings_test.hjson | ||
extra/notabs_test.json | ||
extra/separator_test.json |
@@ -7,3 +7,5 @@ | ||
var argv=process.argv.slice(2) | ||
var args={}, argv=[]; | ||
process.argv.slice(2).forEach(function(x) { if (x[0]==="-") { var i=x.indexOf("="); args[x.substr(1, i>0?i-1:undefined)]=i>0?x.substr(i+1):true; } else argv.push(x); }); | ||
var filter=argv[0]; | ||
@@ -16,6 +18,10 @@ var success=true; | ||
if (s1 || s2) { | ||
console.log("--- actual:"); | ||
var i=0; | ||
while (i<s1.length && s1[i]===s2[i]) i++; | ||
console.log("--- actual (diff at "+i+";"+(s1[i]||'').charCodeAt(0)+":"+(s2[i]||'').charCodeAt(0)+"):"); | ||
console.log(s1); | ||
console.log("--- expected:"); | ||
console.log(s2); | ||
if (args.dump) | ||
fs.writeFileSync(args.dump, s1, "utf8"); | ||
} | ||
@@ -34,2 +40,4 @@ success=false; | ||
var shouldFail = name.substr(0, 4) === "fail"; | ||
var metaPath = path.join(rootDir, name+"_testmeta.hjson"); | ||
var meta = fs.existsSync(metaPath) ? Hjson.parse(fs.readFileSync(metaPath, "utf8")) : {}; | ||
Hjson.setEndOfLine(outputCr?"\r\n":"\n"); | ||
@@ -41,20 +49,22 @@ | ||
if (!shouldFail) { | ||
var text1 = JSON.stringify(data, null, 2); | ||
var hjson1 = Hjson.stringify(data, { emitRootBraces: true }); | ||
var result = JSON.parse(load(name+"_result.json", inputCr)); | ||
var text2 = JSON.stringify(result, null, 2); | ||
var hjson2 = load(name+"_result.hjson", outputCr); | ||
if (text1 !== text2) failErr(name, "parse", text1, text2); | ||
if (hjson1 !== hjson2) failErr(name, "stringify", hjson1, hjson2); | ||
var jsonFromData = JSON.stringify(data, null, 2); | ||
var hjsonFromData = Hjson.stringify(data, meta.options); | ||
var jsonResultRaw = load(name+"_result.json", inputCr); | ||
var jsonResult = JSON.stringify(JSON.parse(jsonResultRaw), null, 2); | ||
var hjsonResult = load(name+"_result.hjson", outputCr); | ||
if (jsonFromData !== jsonResult) return failErr(name, "parse", jsonFromData, jsonResult); | ||
if (hjsonFromData !== hjsonResult) return failErr(name, "stringify", hjsonFromData, hjsonResult); | ||
if (!inputCr && !outputCr && jsonResultRaw !== jsonResult) return failErr(name, "json-input", jsonResultRaw, jsonResult); | ||
if (isJson) { | ||
// also compare Hjson.parse to JSON.parse | ||
// if the input is JSON we can also compare Hjson.parse to JSON.parse | ||
var json1 = JSON.stringify(data), json2 = JSON.stringify(JSON.parse(text)); | ||
if (json1 !== json2) failErr(name, "json chk", json1, json2); | ||
if (json1 !== json2) return failErr(name, "json chk", json1, json2); | ||
} | ||
} | ||
else failErr(name, null, null, null, " should fail but succeeded"); | ||
else return failErr(name, null, null, null, " should fail but succeeded"); | ||
} | ||
catch (err) { | ||
if (!shouldFail) failErr(name, "exception", err.toString(), ""); | ||
if (!shouldFail) return failErr(name, "exception", err.toString(), ""); | ||
} | ||
return true; | ||
} | ||
@@ -74,5 +84,5 @@ | ||
console.log("- "+name); | ||
test(name, file, isJson, false, false); | ||
test(name, file, isJson, false, true); | ||
test(name, file, isJson, true, false); | ||
test(name, file, isJson, false, false) && | ||
test(name, file, isJson, false, true) && | ||
test(name, file, isJson, true, false) && | ||
test(name, file, isJson, true, true); | ||
@@ -83,1 +93,2 @@ }); | ||
process.exit(success?0:1); | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
141815
157
3000
172
3