Comparing version 2.0.1 to 2.0.2
# hjson-js History | ||
- v2.0.2 | ||
- remove obsoletes | ||
- v2.0.1 | ||
@@ -4,0 +6,0 @@ - simpler stringify |
/*! @preserve | ||
* Hjson v2.0.1 | ||
* Hjson v2.0.2 | ||
* http://hjson.org | ||
@@ -80,13 +80,5 @@ * | ||
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. | ||
*/ | ||
@@ -98,3 +90,2 @@ | ||
var EOL = '\n'; | ||
var defaultBracesSameLine = false; | ||
@@ -762,3 +753,3 @@ var tryParseNumber = function (text, stopAtNext) { | ||
keepWsc = false; | ||
bracesSameLine = defaultBracesSameLine; | ||
bracesSameLine = false; | ||
emitRootBraces = true; | ||
@@ -771,3 +762,3 @@ quoteAlways = false; | ||
keepWsc = opt.keepWsc; | ||
bracesSameLine = opt.bracesSameLine || defaultBracesSameLine; | ||
bracesSameLine = opt.bracesSameLine; | ||
emitRootBraces = opt.emitRootBraces; | ||
@@ -799,4 +790,2 @@ quoteAlways = opt.quotes === 'always'; | ||
}, | ||
bracesSameLine: function() { return defaultBracesSameLine; }, | ||
setBracesSameLine: function(v) { defaultBracesSameLine = v; }, | ||
@@ -803,0 +792,0 @@ // round trip shortcut |
/*! @preserve | ||
* Hjson v2.0.1 | ||
* Hjson v2.0.2 | ||
* http://hjson.org | ||
@@ -12,2 +12,2 @@ * | ||
*/ | ||
var Hjson=function(){"use strict";var r="\n",e=!1,n=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},t=function(){function r(){u=0,f=" "}function e(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(r){return r&&r!==f&&a("Expected '"+r+"' instead of '"+f+"'"),f=t.charAt(u),u++,f},s=function(r){return t.charAt(u+r)},l=function(){var r,e,n,t="";if('"'===f)for(;c();){if('"'===f)return c(),t;if("\\"===f)if(c(),"u"===f){for(n=0,e=0;4>e&&(r=parseInt(c(),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=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="",n=u,t=-1;;){if(":"===f)return r?t>=0&&t!==r.length&&(u=n+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)"):e(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(e(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=n(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(),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()}},m=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=m(),d(),f&&a("Syntax error, found trailing characters"),u}}(),u=function(){function t(r){return r.replace(h,function(r){var e=v[r];return"string"==typeof e?e:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})}function u(r,e,u,o){return r?(d.lastIndex=0,y.lastIndex=0,g.lastIndex=0,l||u||d.test(r)||y.test(r)||void 0!==n(r,!0)||g.test(r)?(h.lastIndex=0,b.lastIndex=0,h.test(r)?b.test(r)||o?'"'+t(r)+'"':f(r,e):'"'+r+'"'):r):'""'}function f(r,e){var n,t=r.replace(/\r/g,"").split("\n");if(e+=k,1===t.length)return"'''"+t[0]+"'''";var u=a+e+"'''";for(n=0;n<t.length;n++)u+=a,t[n]&&(u+=e+t[n]);return u+a+e+"'''"}function o(r){return r?x.test(r)?(h.lastIndex=0,'"'+(h.test(r)?t(r):r)+'"'):r:'""'}function i(r,e,n,t){function f(r){return r&&"\n"===r["\r"===r[0]?1:0]}function l(r){return r&&!f(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 u(r,m,e,t);case"number":return isFinite(r)?String(r):"null";case"boolean":return String(r);case"object":if(!r)return"null";var d,y;c&&(d=r.__WSC__);var b="[object Array]"===Object.prototype.toString.apply(r),g=b||!t||(d?!d.noRootBraces:p),v=m;g&&(m+=k);var x,j,w,_,O=a+v,S=a+m,E=n||s?"":O,F=[];if(b){for(x=0,j=r.length;j>x;x++)d&&F.push(h(d[x])+S),F.push(i(r[x],d?l(d[x+1]):!1,!0)||"null");d&&F.push(h(d[x])+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(x=0,j=W.length;j>x;x++)w=W[x],(g||x>0||y)&&F.push(y+S),y=h(d.c[w]),_=i(r[w],l(y)),_&&F.push(o(w)+(f(_)?":":": ")+_);(g||y)&&F.push(y+O)}else for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&(_=i(r[w]),_&&F.push(o(w)+(f(_)?":":": ")+_));_=0===F.length?"{}":g?d?E+"{"+F.join("")+"}":E+"{"+S+F.join(S)+O+"}":F.join(d?"":S)}return m=v,_}}var a,c,s,l,p,h=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d=/[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,y=/^\s|^"|^'''|^#|^\/\*|^\/\/|^\{|^\[|\s$"/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,g=/^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/,v={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},x=/[,\{\[\}\]\s:#"]|\/\/|\/\*|'''/,m="",k=" ";return function(n,t){var u,f;if(a=r,k=" ",c=!1,s=e,p=!0,l=!1,t&&"object"==typeof t&&(("\n"===t.eol||"\r\n"===t.eol)&&(a=t.eol),f=t.space,c=t.keepWsc,s=t.bracesSameLine||e,p=t.emitRootBraces,l="always"===t.quotes),"number"==typeof f)for(k="",u=0;f>u;u++)k+=" ";else"string"==typeof f&&(k=f);return i(n,null,!0,!0)}}();return{parse:t,stringify:u,endOfLine:function(){return r},setEndOfLine:function(e){("\n"===e||"\r\n"===e)&&(r=e)},bracesSameLine:function(){return e},setBracesSameLine:function(r){e=r},rt:{parse:function(r,e){return(e=e||{}).keepWsc=!0,t(r,e)},stringify:function(r,e){return(e=e||{}).keepWsc=!0,u(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)+" ...")},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} |
@@ -6,3 +6,3 @@ { | ||
"author": "Christian Zangl", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"keywords": [ | ||
@@ -9,0 +9,0 @@ "json", |
65742
1155