Comparing version 2.0.2 to 2.0.3
# hjson-js History | ||
- v2.0.3 | ||
- fix stringify regression | ||
- add test | ||
- v2.0.2 | ||
@@ -4,0 +7,0 @@ - remove obsoletes |
112
lib/hjson.js
/*! @preserve | ||
* Hjson v2.0.2 | ||
* Hjson v2.0.3 | ||
* http://hjson.org | ||
@@ -144,5 +144,3 @@ * | ||
number = +string; | ||
if (ch || leadingZeros || !isFinite(number)) { | ||
return undefined; | ||
} | ||
if (ch || leadingZeros || !isFinite(number)) return undefined; | ||
else return number; | ||
@@ -193,11 +191,4 @@ }; | ||
var next = function (c) { | ||
// If a c parameter is provided, verify that it matches the current character. | ||
if (c && c !== ch) | ||
error("Expected '" + c + "' instead of '" + ch + "'"); | ||
// Get the next character. When there are no more characters, | ||
// return the empty string. | ||
var next = function () { | ||
// get the next character. | ||
ch = text.charAt(at); | ||
@@ -215,3 +206,3 @@ at++; | ||
// Parse a string value. | ||
var hex, i, string = '', uffff; | ||
var string = ''; | ||
@@ -228,15 +219,19 @@ // When parsing for string values, we must look for " and \ characters. | ||
if (ch === 'u') { | ||
uffff = 0; | ||
for (i = 0; i < 4; i++) { | ||
hex = parseInt(next(), 16); | ||
if (!isFinite(hex)) | ||
break; | ||
var uffff = 0; | ||
for (var i = 0; i < 4; i++) { | ||
next(); | ||
var c = ch.charCodeAt(0), hex; | ||
if (ch >= '0' && ch <= '9') hex = c - 48; | ||
else if (ch >= 'a' && ch <= 'f') hex = c - 97 + 0xa; | ||
else if (ch >= 'A' && ch <= 'F') hex = c - 65 + 0xa; | ||
else error("Bad \\u char " + ch); | ||
uffff = uffff * 16 + hex; | ||
} | ||
string += String.fromCharCode(uffff); | ||
} | ||
else if (typeof escapee[ch] === 'string') string += escapee[ch]; | ||
else break; | ||
} else if (typeof escapee[ch] === 'string') { | ||
string += escapee[ch]; | ||
} else break; | ||
} else { | ||
string += ch; | ||
} | ||
else string += ch; | ||
} | ||
@@ -270,4 +265,5 @@ } | ||
while (true) { | ||
if (!ch) error("Bad multiline string"); | ||
else if (ch === '\'') { | ||
if (!ch) { | ||
error("Bad multiline string"); | ||
} else if (ch === '\'') { | ||
triple++; | ||
@@ -278,9 +274,9 @@ next(); | ||
return string; | ||
} else continue; | ||
} else { | ||
while (triple > 0) { | ||
string += '\''; | ||
triple--; | ||
} | ||
else continue; | ||
} | ||
else while (triple > 0) { | ||
string += '\''; | ||
triple--; | ||
} | ||
if (ch === '\n') { | ||
@@ -290,4 +286,3 @@ string += '\n'; | ||
skipIndent(); | ||
} | ||
else { | ||
} else { | ||
if (ch !== '\r') string += ch; | ||
@@ -311,11 +306,10 @@ next(); | ||
return name; | ||
} | ||
else if (ch <= ' ') { | ||
} else if (ch <= ' ') { | ||
if (!ch) error("Found EOF while looking for a key name (check your syntax)"); | ||
else if (space < 0) space = name.length; | ||
} | ||
else if (isPunctuatorChar(ch)) { | ||
} else if (isPunctuatorChar(ch)) { | ||
error("Found '" + ch + "' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"); | ||
} else { | ||
name += ch; | ||
} | ||
else name += ch; | ||
next(); | ||
@@ -332,10 +326,7 @@ } | ||
while (ch && ch !== '\n') next(); | ||
} | ||
else if (ch === '/' && peek(0) === '*') | ||
{ | ||
} else if (ch === '/' && peek(0) === '*') { | ||
next(); next(); | ||
while (ch && !(ch === '*' && peek(0) === '/')) next(); | ||
if (ch) { next(); next(); } | ||
} | ||
else break; | ||
} else break; | ||
} | ||
@@ -396,3 +387,3 @@ }; | ||
// Parse an array value. | ||
// assumeing ch === '[' | ||
// assuming ch === '[' | ||
@@ -449,4 +440,3 @@ var array = []; | ||
wat = at; | ||
} | ||
else wat = 1; | ||
} else wat = 1; | ||
@@ -462,3 +452,4 @@ white(); | ||
white(); | ||
next(':'); | ||
if (ch !== ':') error("Expected ':' instead of '" + ch + "'"); | ||
next(); | ||
// duplicate keys overwrite the previous value | ||
@@ -538,3 +529,3 @@ object[key] = value(); | ||
var needsQuotes = /[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g; | ||
var needsQuotes2 = /^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\[|\s$"/g; | ||
var needsQuotes2 = /^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\[|\s$/g; | ||
// ''' || (needsQuotes but without \n and \r) | ||
@@ -594,4 +585,3 @@ 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; | ||
else return '"' + quoteReplace(string) + '"'; | ||
} | ||
else { | ||
} else { | ||
// return without quotes | ||
@@ -613,4 +603,3 @@ return string; | ||
return "'''" + a[0] + "'''"; | ||
} | ||
else { | ||
} else { | ||
var res = eol + gap + "'''"; | ||
@@ -633,4 +622,3 @@ for (i = 0; i < a.length; i++) { | ||
return '"' + (needsEscape.test(name) ? quoteReplace(name) : name) + '"'; | ||
} | ||
else { | ||
} else { | ||
// return without quotes | ||
@@ -713,4 +701,3 @@ return name; | ||
else v = prefix + '[' + eolGap + partial.join(eolGap) + eolMind + ']'; | ||
} | ||
else { | ||
} else { | ||
// Otherwise, iterate through all of the keys in the object. | ||
@@ -734,4 +721,3 @@ | ||
if (showBraces || kwl) partial.push(kwl + eolMind); | ||
} | ||
else { | ||
} else { | ||
for (k in value) { | ||
@@ -746,9 +732,11 @@ if (Object.prototype.hasOwnProperty.call(value, k)) { | ||
// Join all of the member texts together, separated with newlines | ||
if (partial.length === 0) v = '{}'; | ||
else if (showBraces) { | ||
if (partial.length === 0) { | ||
v = '{}'; | ||
} else if (showBraces) { | ||
// and wrap them in braces | ||
if (kw) v = prefix + '{' + partial.join('') + '}'; | ||
else v = prefix + '{' + eolGap + partial.join(eolGap) + eolMind + '}'; | ||
} else { | ||
v = partial.join(kw ? '' : eolGap); | ||
} | ||
else v = partial.join(kw ? '' : eolGap); | ||
} | ||
@@ -789,5 +777,5 @@ | ||
for (i = 0; i < space; i++) indent += ' '; | ||
} else if (typeof space === 'string') { | ||
indent = space; | ||
} | ||
else if (typeof space === 'string') | ||
indent = space; | ||
@@ -794,0 +782,0 @@ // Return the result of stringifying the value. |
/*! @preserve | ||
* Hjson v2.0.2 | ||
* Hjson v2.0.3 | ||
* http://hjson.org | ||
@@ -12,2 +12,2 @@ * | ||
*/ | ||
var Hjson=function(){"use strict";var r="\n",e=function(r,e){function n(){return u=r.charAt(a),a++,u}var t,u,f="",o=0,i=!0,a=0;for(n(),"-"===u&&(f="-",n());u>="0"&&"9">=u;)i&&("0"==u?o++:i=!1),f+=u,n();if(i&&o--,"."===u)for(f+=".";n()&&u>="0"&&"9">=u;)f+=u;if("e"===u||"E"===u)for(f+=u,n(),("-"===u||"+"===u)&&(f+=u,n());u>="0"&&"9">=u;)f+=u,n();for(;u&&" ">=u;)n();return e&&(","===u||"}"===u||"]"===u||"#"===u||"/"===u&&("/"===r[a]||"*"===r[a]))&&(u=0),t=+f,u||o||!isFinite(t)?void 0:t},n=function(){function r(){u=0,f=" "}function n(r){return"{"===r||"}"===r||"["===r||"]"===r||","===r||":"===r}var t,u,f,o,i={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:" "},a=function(r){var e,n=0,f=1;for(e=u-1;e>0&&"\n"!==t[e];e--,n++);for(;e>0;e--)"\n"===t[e]&&f++;throw new Error(r+" at line "+f+","+n+" >>>"+t.substr(u-n,20)+" ...")},s=function(r){return r&&r!==f&&a("Expected '"+r+"' instead of '"+f+"'"),f=t.charAt(u),u++,f},c=function(r){return t.charAt(u+r)},l=function(){var r,e,n,t="";if('"'===f)for(;s();){if('"'===f)return s(),t;if("\\"===f)if(s(),"u"===f){for(n=0,e=0;4>e&&(r=parseInt(s(),16),isFinite(r));e++)n=16*n+r;t+=String.fromCharCode(n)}else{if("string"!=typeof i[f])break;t+=i[f]}else t+=f}a("Bad string")},p=function(){for(var r="",e=0,n=0;;){var t=c(-n-5);if(!t||"\n"===t)break;n++}for(var u=function(){for(var r=n;f&&" ">=f&&"\n"!==f&&r-->0;)s()};f&&" ">=f&&"\n"!==f;)s();for("\n"===f&&(s(),u());;){if(f){if("'"===f){if(e++,s(),3===e)return"\n"===r.slice(-1)&&(r=r.slice(0,-1)),r;continue}for(;e>0;)r+="'",e--}else a("Bad multiline string");"\n"===f?(r+="\n",s(),u()):("\r"!==f&&(r+=f),s())}},h=function(){if('"'===f)return l();for(var r="",e=u,t=-1;;){if(":"===f)return r?t>=0&&t!==r.length&&(u=e+t,a("Found whitespace in your key name (use quotes to include)")):a("Found ':' but no key name (for an empty key name use quotes)"),r;" ">=f?f?0>t&&(t=r.length):a("Found EOF while looking for a key name (check your syntax)"):n(f)?a("Found '"+f+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"):r+=f,s()}},d=function(){for(;f;){for(;f&&" ">=f;)s();if("#"===f||"/"===f&&"/"===c(0))for(;f&&"\n"!==f;)s();else{if("/"!==f||"*"!==c(0))break;for(s(),s();f&&("*"!==f||"/"!==c(0));)s();f&&(s(),s())}}},y=function(){var r=f;for(n(f)&&a("Found a punctuator character '"+f+"' when excpecting a quoteless string (check your syntax)");;){if(s(),3===r.length&&"'''"===r)return p();var t="\r"===f||"\n"===f||""===f;if(t||","===f||"}"===f||"]"===f||"#"===f||"/"===f&&("/"===c(0)||"*"===c(0))){var u=r[0];switch(u){case"f":if("false"===r.trim())return!1;break;case"n":if("null"===r.trim())return null;break;case"t":if("true"===r.trim())return!0;break;default:if("-"===u||u>="0"&&"9">=u){var o=e(r);if(void 0!==o)return o}}if(t)return r.trim()}r+=f}},b=function(r){var e;for(r--,e=u-2;e>r&&t[e]<=" "&&"\n"!==t[e];e--);"\n"===t[e]&&e--,"\r"===t[e]&&e--;var n=t.substr(r,e-r+1);for(e=0;e<n.length;e++)if(n[e]>" ")return n;return""},g=function(){var r,e,n=[];if(o&&(Object.defineProperty&&Object.defineProperty(n,"__WSC__",{enumerable:!1,writable:!0}),n.__WSC__=r=[]),s(),e=u,d(),r&&r.push(b(e)),"]"===f)return s(),n;for(;f;){if(n.push(x()),e=u,d(),","===f&&(s(),e=u,d()),r&&r.push(b(e)),"]"===f)return s(),n;d()}a("End of input while parsing an array (did you forget a closing ']'?)")},v=function(r){function e(r){t.c[r]=b(i),r&&t.o.push(r)}var n,t,i,c={};if(o&&(Object.defineProperty&&Object.defineProperty(c,"__WSC__",{enumerable:!1,writable:!0}),c.__WSC__=t={c:{},o:[]},r&&(t.noRootBraces=!0)),r?i=1:(s(),i=u),d(),t&&e(""),"}"===f&&!r)return s(),c;for(;f;){if(n=h(),d(),s(":"),c[n]=x(),i=u,d(),","===f&&(s(),i=u,d()),t&&e(n),"}"===f&&!r)return s(),c;d()}return r?c:void a("End of input while parsing an object (did you forget a closing '}'?)")},x=function(){switch(d(),f){case"{":return v();case"[":return g();case'"':return l();default:return y()}},k=function(){switch(d(),f){case"{":return v();case"[":return g()}try{return v(!0)}catch(e){r();try{return x()}catch(n){throw e}}};return function(e,n){var u;return o=n&&n.keepWsc,t=e,r(),u=k(),d(),f&&a("Syntax error, found trailing characters"),u}}(),t=function(){function n(r){return r.replace(p,function(r){var e=g[r];return"string"==typeof e?e:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})}function t(r,t,f,o){return r?(h.lastIndex=0,d.lastIndex=0,b.lastIndex=0,c||f||h.test(r)||d.test(r)||void 0!==e(r,!0)||b.test(r)?(p.lastIndex=0,y.lastIndex=0,p.test(r)?y.test(r)||o?'"'+n(r)+'"':u(r,t):'"'+r+'"'):r):'""'}function u(r,e){var n,t=r.replace(/\r/g,"").split("\n");if(e+=k,1===t.length)return"'''"+t[0]+"'''";var u=i+e+"'''";for(n=0;n<t.length;n++)u+=i,t[n]&&(u+=e+t[n]);return u+i+e+"'''"}function f(r){return r?v.test(r)?(p.lastIndex=0,'"'+(p.test(r)?n(r):r)+'"'):r:'""'}function o(r,e,n,u){function c(r){return r&&"\n"===r["\r"===r[0]?1:0]}function p(r){return r&&!c(r)}function h(r){if(!r)return"";for(var e=0;e<r.length;e++){var n=r[e];if("\n"===n||"#"===n||"/"===n&&("/"===r[e+1]||"*"===r[e+1]))break;if(n>" ")return" # "+r}return r}switch(typeof r){case"string":return t(r,x,e,u);case"number":return isFinite(r)?String(r):"null";case"boolean":return String(r);case"object":if(!r)return"null";var d,y;a&&(d=r.__WSC__);var b="[object Array]"===Object.prototype.toString.apply(r),g=b||!u||(d?!d.noRootBraces:l),v=x;g&&(x+=k);var m,j,w,_,O=i+v,S=i+x,E=n||s?"":O,F=[];if(b){for(m=0,j=r.length;j>m;m++)d&&F.push(h(d[m])+S),F.push(o(r[m],d?p(d[m+1]):!1,!0)||"null");d&&F.push(h(d[m])+O),_=d?E+"["+F.join("")+"]":0===F.length?"[]":E+"["+S+F.join(S)+O+"]"}else{if(d){y=h(d.c[""]);var W=d.o.slice();for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&W.indexOf(w)<0&&W.push(w);for(m=0,j=W.length;j>m;m++)w=W[m],(g||m>0||y)&&F.push(y+S),y=h(d.c[w]),_=o(r[w],p(y)),_&&F.push(f(w)+(c(_)?":":": ")+_);(g||y)&&F.push(y+O)}else for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&(_=o(r[w]),_&&F.push(f(w)+(c(_)?":":": ")+_));_=0===F.length?"{}":g?d?E+"{"+F.join("")+"}":E+"{"+S+F.join(S)+O+"}":F.join(d?"":S)}return x=v,_}}var i,a,s,c,l,p=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,h=/[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d=/^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\[|\s$"/g,y=/'''|[\x00-\x09\x0b\x0c\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,b=/^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/,g={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},v=/[,\{\[\}\]\s:#"]|\/\/|\/\*|'''/,x="",k=" ";return function(e,n){var t,u;if(i=r,k=" ",a=!1,s=!1,l=!0,c=!1,n&&"object"==typeof n&&(("\n"===n.eol||"\r\n"===n.eol)&&(i=n.eol),u=n.space,a=n.keepWsc,s=n.bracesSameLine,l=n.emitRootBraces,c="always"===n.quotes),"number"==typeof u)for(k="",t=0;u>t;t++)k+=" ";else"string"==typeof u&&(k=u);return o(e,null,!0,!0)}}();return{parse:n,stringify:t,endOfLine:function(){return r},setEndOfLine:function(e){("\n"===e||"\r\n"===e)&&(r=e)},rt:{parse:function(r,e){return(e=e||{}).keepWsc=!0,n(r,e)},stringify:function(r,e){return(e=e||{}).keepWsc=!0,t(r,e)}}}}();if("object"==typeof module){if("function"==typeof require){var os=require("os");Hjson.setEndOfLine(os.EOL)}module.exports=Hjson} | ||
var Hjson=function(){"use strict";var r="\n",e=function(r,e){function n(){return u=r.charAt(a),a++,u}var t,u,f="",o=0,i=!0,a=0;for(n(),"-"===u&&(f="-",n());u>="0"&&"9">=u;)i&&("0"==u?o++:i=!1),f+=u,n();if(i&&o--,"."===u)for(f+=".";n()&&u>="0"&&"9">=u;)f+=u;if("e"===u||"E"===u)for(f+=u,n(),("-"===u||"+"===u)&&(f+=u,n());u>="0"&&"9">=u;)f+=u,n();for(;u&&" ">=u;)n();return e&&(","===u||"}"===u||"]"===u||"#"===u||"/"===u&&("/"===r[a]||"*"===r[a]))&&(u=0),t=+f,u||o||!isFinite(t)?void 0:t},n=function(){function r(){u=0,f=" "}function n(r){return"{"===r||"}"===r||"["===r||"]"===r||","===r||":"===r}var t,u,f,o,i={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:" "},a=function(r){var e,n=0,f=1;for(e=u-1;e>0&&"\n"!==t[e];e--,n++);for(;e>0;e--)"\n"===t[e]&&f++;throw new Error(r+" at line "+f+","+n+" >>>"+t.substr(u-n,20)+" ...")},c=function(){return f=t.charAt(u),u++,f},s=function(r){return t.charAt(u+r)},l=function(){var r="";if('"'===f)for(;c();){if('"'===f)return c(),r;if("\\"===f)if(c(),"u"===f){for(var e=0,n=0;4>n;n++){c();var t,u=f.charCodeAt(0);f>="0"&&"9">=f?t=u-48:f>="a"&&"f">=f?t=u-97+10:f>="A"&&"F">=f?t=u-65+10:a("Bad \\u char "+f),e=16*e+t}r+=String.fromCharCode(e)}else{if("string"!=typeof i[f])break;r+=i[f]}else r+=f}a("Bad string")},p=function(){for(var r="",e=0,n=0;;){var t=s(-n-5);if(!t||"\n"===t)break;n++}for(var u=function(){for(var r=n;f&&" ">=f&&"\n"!==f&&r-->0;)c()};f&&" ">=f&&"\n"!==f;)c();for("\n"===f&&(c(),u());;){if(f){if("'"===f){if(e++,c(),3===e)return"\n"===r.slice(-1)&&(r=r.slice(0,-1)),r;continue}for(;e>0;)r+="'",e--}else a("Bad multiline string");"\n"===f?(r+="\n",c(),u()):("\r"!==f&&(r+=f),c())}},h=function(){if('"'===f)return l();for(var r="",e=u,t=-1;;){if(":"===f)return r?t>=0&&t!==r.length&&(u=e+t,a("Found whitespace in your key name (use quotes to include)")):a("Found ':' but no key name (for an empty key name use quotes)"),r;" ">=f?f?0>t&&(t=r.length):a("Found EOF while looking for a key name (check your syntax)"):n(f)?a("Found '"+f+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"):r+=f,c()}},d=function(){for(;f;){for(;f&&" ">=f;)c();if("#"===f||"/"===f&&"/"===s(0))for(;f&&"\n"!==f;)c();else{if("/"!==f||"*"!==s(0))break;for(c(),c();f&&("*"!==f||"/"!==s(0));)c();f&&(c(),c())}}},y=function(){var r=f;for(n(f)&&a("Found a punctuator character '"+f+"' when excpecting a quoteless string (check your syntax)");;){if(c(),3===r.length&&"'''"===r)return p();var t="\r"===f||"\n"===f||""===f;if(t||","===f||"}"===f||"]"===f||"#"===f||"/"===f&&("/"===s(0)||"*"===s(0))){var u=r[0];switch(u){case"f":if("false"===r.trim())return!1;break;case"n":if("null"===r.trim())return null;break;case"t":if("true"===r.trim())return!0;break;default:if("-"===u||u>="0"&&"9">=u){var o=e(r);if(void 0!==o)return o}}if(t)return r.trim()}r+=f}},b=function(r){var e;for(r--,e=u-2;e>r&&t[e]<=" "&&"\n"!==t[e];e--);"\n"===t[e]&&e--,"\r"===t[e]&&e--;var n=t.substr(r,e-r+1);for(e=0;e<n.length;e++)if(n[e]>" ")return n;return""},g=function(){var r,e,n=[];if(o&&(Object.defineProperty&&Object.defineProperty(n,"__WSC__",{enumerable:!1,writable:!0}),n.__WSC__=r=[]),c(),e=u,d(),r&&r.push(b(e)),"]"===f)return c(),n;for(;f;){if(n.push(x()),e=u,d(),","===f&&(c(),e=u,d()),r&&r.push(b(e)),"]"===f)return c(),n;d()}a("End of input while parsing an array (did you forget a closing ']'?)")},v=function(r){function e(r){t.c[r]=b(i),r&&t.o.push(r)}var n,t,i,s={};if(o&&(Object.defineProperty&&Object.defineProperty(s,"__WSC__",{enumerable:!1,writable:!0}),s.__WSC__=t={c:{},o:[]},r&&(t.noRootBraces=!0)),r?i=1:(c(),i=u),d(),t&&e(""),"}"===f&&!r)return c(),s;for(;f;){if(n=h(),d(),":"!==f&&a("Expected ':' instead of '"+f+"'"),c(),s[n]=x(),i=u,d(),","===f&&(c(),i=u,d()),t&&e(n),"}"===f&&!r)return c(),s;d()}return r?s:void a("End of input while parsing an object (did you forget a closing '}'?)")},x=function(){switch(d(),f){case"{":return v();case"[":return g();case'"':return l();default:return y()}},k=function(){switch(d(),f){case"{":return v();case"[":return g()}try{return v(!0)}catch(e){r();try{return x()}catch(n){throw e}}};return function(e,n){var u;return o=n&&n.keepWsc,t=e,r(),u=k(),d(),f&&a("Syntax error, found trailing characters"),u}}(),t=function(){function n(r){return r.replace(p,function(r){var e=g[r];return"string"==typeof e?e:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})}function t(r,t,f,o){return r?(h.lastIndex=0,d.lastIndex=0,b.lastIndex=0,s||f||h.test(r)||d.test(r)||void 0!==e(r,!0)||b.test(r)?(p.lastIndex=0,y.lastIndex=0,p.test(r)?y.test(r)||o?'"'+n(r)+'"':u(r,t):'"'+r+'"'):r):'""'}function u(r,e){var n,t=r.replace(/\r/g,"").split("\n");if(e+=k,1===t.length)return"'''"+t[0]+"'''";var u=i+e+"'''";for(n=0;n<t.length;n++)u+=i,t[n]&&(u+=e+t[n]);return u+i+e+"'''"}function f(r){return r?v.test(r)?(p.lastIndex=0,'"'+(p.test(r)?n(r):r)+'"'):r:'""'}function o(r,e,n,u){function s(r){return r&&"\n"===r["\r"===r[0]?1:0]}function p(r){return r&&!s(r)}function h(r){if(!r)return"";for(var e=0;e<r.length;e++){var n=r[e];if("\n"===n||"#"===n||"/"===n&&("/"===r[e+1]||"*"===r[e+1]))break;if(n>" ")return" # "+r}return r}switch(typeof r){case"string":return t(r,x,e,u);case"number":return isFinite(r)?String(r):"null";case"boolean":return String(r);case"object":if(!r)return"null";var d,y;a&&(d=r.__WSC__);var b="[object Array]"===Object.prototype.toString.apply(r),g=b||!u||(d?!d.noRootBraces:l),v=x;g&&(x+=k);var m,j,w,_,O=i+v,S=i+x,C=n||c?"":O,E=[];if(b){for(m=0,j=r.length;j>m;m++)d&&E.push(h(d[m])+S),E.push(o(r[m],d?p(d[m+1]):!1,!0)||"null");d&&E.push(h(d[m])+O),_=d?C+"["+E.join("")+"]":0===E.length?"[]":C+"["+S+E.join(S)+O+"]"}else{if(d){y=h(d.c[""]);var F=d.o.slice();for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&F.indexOf(w)<0&&F.push(w);for(m=0,j=F.length;j>m;m++)w=F[m],(g||m>0||y)&&E.push(y+S),y=h(d.c[w]),_=o(r[w],p(y)),_&&E.push(f(w)+(s(_)?":":": ")+_);(g||y)&&E.push(y+O)}else for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&(_=o(r[w]),_&&E.push(f(w)+(s(_)?":":": ")+_));_=0===E.length?"{}":g?d?C+"{"+E.join("")+"}":C+"{"+S+E.join(S)+O+"}":E.join(d?"":S)}return x=v,_}}var i,a,c,s,l,p=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,h=/[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d=/^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\[|\s$/g,y=/'''|[\x00-\x09\x0b\x0c\x0e-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,b=/^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/,g={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},v=/[,\{\[\}\]\s:#"]|\/\/|\/\*|'''/,x="",k=" ";return function(e,n){var t,u;if(i=r,k=" ",a=!1,c=!1,l=!0,s=!1,n&&"object"==typeof n&&(("\n"===n.eol||"\r\n"===n.eol)&&(i=n.eol),u=n.space,a=n.keepWsc,c=n.bracesSameLine,l=n.emitRootBraces,s="always"===n.quotes),"number"==typeof u)for(k="",t=0;u>t;t++)k+=" ";else"string"==typeof u&&(k=u);return o(e,null,!0,!0)}}();return{parse:n,stringify:t,endOfLine:function(){return r},setEndOfLine:function(e){("\n"===e||"\r\n"===e)&&(r=e)},rt:{parse:function(r,e){return(e=e||{}).keepWsc=!0,n(r,e)},stringify:function(r,e){return(e=e||{}).keepWsc=!0,t(r,e)}}}}();if("object"==typeof module){if("function"==typeof require){var os=require("os");Hjson.setEndOfLine(os.EOL)}module.exports=Hjson} |
@@ -6,3 +6,3 @@ { | ||
"author": "Christian Zangl", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"keywords": [ | ||
@@ -9,0 +9,0 @@ "json", |
@@ -5,3 +5,5 @@ { | ||
"text3": "You need quotes\tfor escapes", | ||
"text4": " untrimmed ", | ||
"text4a": " untrimmed ", | ||
"text4b": " untrimmed", | ||
"text4c": "untrimmed ", | ||
"multiline1": "first line\n indented line\nlast line", | ||
@@ -8,0 +10,0 @@ "multiline2": "first line\n indented line\nlast line", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
66033
1148