Comparing version 1.8.4 to 2.0.1
# hjson-js History | ||
- v2.0.1 | ||
- simpler stringify | ||
- v2.0.0 | ||
- add stricter check for {}[],: at the start of a quoteless string | ||
- v1.8.4 | ||
- fix multiline stringify | ||
- v1.8.3 | ||
- fix stringify for key names containing comments/control characters | ||
- v1.8.2 | ||
- better parse for single JSON values | ||
- v1.8.1 | ||
- detect EOF when looking for a key name | ||
- v1.7.6 | ||
@@ -4,0 +16,0 @@ - fix trailing whitespace in keyname |
/*! @preserve | ||
* Hjson v1.8.4 | ||
* Hjson v2.0.1 | ||
* http://hjson.org | ||
@@ -147,3 +147,3 @@ * | ||
if (stopAtNext) { | ||
// end scan if we find a control character like ,}] or a comment | ||
// end scan if we find a punctuator character like ,}] or a comment | ||
if (ch === ',' || ch === '}' || ch === ']' || | ||
@@ -190,2 +190,6 @@ ch === '#' || ch === '/' && (text[at] === '/' || text[at] === '*')) ch = 0; | ||
function isPunctuatorChar(c) { | ||
return c === '{' || c === '}' || c === '[' || c === ']' || c === ',' || c === ':'; | ||
} | ||
// Call error when something is wrong. | ||
@@ -316,3 +320,3 @@ var error = function (m) { | ||
} | ||
else if (ch === '{' || ch === '}' || ch === '[' || ch === ']' || 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)"); | ||
@@ -347,2 +351,5 @@ } | ||
var value = ch; | ||
if (isPunctuatorChar(ch)) | ||
error("Found a punctuator character '" + ch + "' when excpecting a quoteless string (check your syntax)"); | ||
for(;;) { | ||
@@ -352,4 +359,4 @@ next(); | ||
var isEol = ch === '\r' || ch === '\n' || ch === ''; | ||
if (isEol || ch === ',' || | ||
ch === '}' || ch === ']' || | ||
if (isEol || | ||
ch === ',' || ch === '}' || ch === ']' || | ||
ch === '#' || | ||
@@ -533,2 +540,3 @@ ch === '/' && (peek(0) === '/' || peek(0) === '*') | ||
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; | ||
// ''' || (needsQuotes but without \n and \r) | ||
@@ -554,4 +562,2 @@ 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; | ||
function isWhite(c) { return c <= ' '; } | ||
function quoteReplace(string) { | ||
@@ -569,4 +575,4 @@ return string.replace(needsEscape, function (a) { | ||
needsQuotes.lastIndex = 0; | ||
needsQuotes2.lastIndex = 0; | ||
startsWithKeyword.lastIndex = 0; | ||
var doEscape = quoteAlways || hasComment || needsQuotes.test(string); | ||
@@ -576,12 +582,4 @@ // Check if we can insert this string without quotes | ||
var first = string[0], last = string[string.length-1]; | ||
if (doEscape || | ||
isWhite(first) || | ||
first === '"' || | ||
first === '\'' && string[1] === '\'' && string[2] === '\'' || | ||
first === '#' || | ||
first === '/' && (string[1] === '*' || string[1] === '/') || | ||
first === '{' || | ||
first === '[' || | ||
isWhite(last) || | ||
if (quoteAlways || hasComment || | ||
needsQuotes.test(string) || needsQuotes2.test(string) || | ||
tryParseNumber(string, true) !== undefined || | ||
@@ -588,0 +586,0 @@ startsWithKeyword.test(string)) { |
/*! @preserve | ||
* Hjson v1.8.4 | ||
* Hjson v2.0.1 | ||
* 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="",i=0,o=!0,a=0;for(n(),"-"===u&&(f="-",n());u>="0"&&"9">=u;)o&&("0"==u?i++:o=!1),f+=u,n();if(o&&i--,"."===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||i||!isFinite(t)?void 0:t},t=function(){function r(){t=0,u=" "}var e,t,u,f,i={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:" "},o=function(r){var n,u=0,f=1;for(n=t-1;n>0&&"\n"!==e[n];n--,u++);for(;n>0;n--)"\n"===e[n]&&f++;throw new Error(r+" at line "+f+","+u+" >>>"+e.substr(t-u,20)+" ...")},a=function(r){return r&&r!==u&&o("Expected '"+r+"' instead of '"+u+"'"),u=e.charAt(t),t++,u},c=function(r){return e.charAt(t+r)},s=function(){var r,e,n,t="";if('"'===u)for(;a();){if('"'===u)return a(),t;if("\\"===u)if(a(),"u"===u){for(n=0,e=0;4>e&&(r=parseInt(a(),16),isFinite(r));e++)n=16*n+r;t+=String.fromCharCode(n)}else{if("string"!=typeof i[u])break;t+=i[u]}else t+=u}o("Bad string")},l=function(){for(var r="",e=0,n=0;;){var t=c(-n-5);if(!t||"\n"===t)break;n++}for(var f=function(){for(var r=n;u&&" ">=u&&"\n"!==u&&r-->0;)a()};u&&" ">=u&&"\n"!==u;)a();for("\n"===u&&(a(),f());;){if(u){if("'"===u){if(e++,a(),3===e)return"\n"===r.slice(-1)&&(r=r.slice(0,-1)),r;continue}for(;e>0;)r+="'",e--}else o("Bad multiline string");"\n"===u?(r+="\n",a(),f()):("\r"!==u&&(r+=u),a())}},p=function(){if('"'===u)return s();for(var r="",e=t,n=-1;;){if(":"===u)return r?n>=0&&n!==r.length&&(t=e+n,o("Found whitespace in your key name (use quotes to include)")):o("Found ':' but no key name (for an empty key name use quotes)"),r;" ">=u?u?0>n&&(n=r.length):o("Found EOF while looking for a key name (check your syntax)"):"{"===u||"}"===u||"["===u||"]"===u||","===u?o("Found '"+u+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"):r+=u,a()}},h=function(){for(;u;){for(;u&&" ">=u;)a();if("#"===u||"/"===u&&"/"===c(0))for(;u&&"\n"!==u;)a();else{if("/"!==u||"*"!==c(0))break;for(a(),a();u&&("*"!==u||"/"!==c(0));)a();u&&(a(),a())}}},d=function(){for(var r=u;;){if(a(),3===r.length&&"'''"===r)return l();var e="\r"===u||"\n"===u||""===u;if(e||","===u||"}"===u||"]"===u||"#"===u||"/"===u&&("/"===c(0)||"*"===c(0))){var t=r[0];switch(t){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("-"===t||t>="0"&&"9">=t){var f=n(r);if(void 0!==f)return f}}if(e)return r.trim()}r+=u}},b=function(r){var n;for(r--,n=t-2;n>r&&e[n]<=" "&&"\n"!==e[n];n--);"\n"===e[n]&&n--,"\r"===e[n]&&n--;var u=e.substr(r,n-r+1);for(n=0;n<u.length;n++)if(u[n]>" ")return u;return""},y=function(){var r,e,n=[];if(f&&(Object.defineProperty&&Object.defineProperty(n,"__WSC__",{enumerable:!1,writable:!0}),n.__WSC__=r=[]),a(),e=t,h(),r&&r.push(b(e)),"]"===u)return a(),n;for(;u;){if(n.push(v()),e=t,h(),","===u&&(a(),e=t,h()),r&&r.push(b(e)),"]"===u)return a(),n;h()}o("End of input while parsing an array (did you forget a closing ']'?)")},g=function(r){function e(r){i.c[r]=b(c),r&&i.o.push(r)}var n,i,c,s={};if(f&&(Object.defineProperty&&Object.defineProperty(s,"__WSC__",{enumerable:!1,writable:!0}),s.__WSC__=i={c:{},o:[]},r&&(i.noRootBraces=!0)),r?c=1:(a(),c=t),h(),i&&e(""),"}"===u&&!r)return a(),s;for(;u;){if(n=p(),h(),a(":"),s[n]=v(),c=t,h(),","===u&&(a(),c=t,h()),i&&e(n),"}"===u&&!r)return a(),s;h()}return r?s:void o("End of input while parsing an object (did you forget a closing '}'?)")},v=function(){switch(h(),u){case"{":return g();case"[":return y();case'"':return s();default:return d()}},x=function(){switch(h(),u){case"{":return g();case"[":return y()}try{return g(!0)}catch(e){r();try{return v()}catch(n){throw e}}};return function(n,t){var i;return f=t&&t.keepWsc,e=n,r(),i=x(),h(),u&&o("Syntax error, found trailing characters"),i}}(),u=function(){function t(r){return" ">=r}function u(r){return r.replace(d,function(r){var e=v[r];return"string"==typeof e?e:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})}function f(r,e,f,o){if(!r)return'""';b.lastIndex=0,g.lastIndex=0;var a=p||f||b.test(r),c=r[0],s=r[r.length-1];return a||t(c)||'"'===c||"'"===c&&"'"===r[1]&&"'"===r[2]||"#"===c||"/"===c&&("*"===r[1]||"/"===r[1])||"{"===c||"["===c||t(s)||void 0!==n(r,!0)||g.test(r)?(d.lastIndex=0,y.lastIndex=0,d.test(r)?y.test(r)||o?'"'+u(r)+'"':i(r,e):'"'+r+'"'):r}function i(r,e){var n,t=r.replace(/\r/g,"").split("\n");if(e+=j,1===t.length)return"'''"+t[0]+"'''";var u=c+e+"'''";for(n=0;n<t.length;n++)u+=c,t[n]&&(u+=e+t[n]);return u+c+e+"'''"}function o(r){return r?x.test(r)?(d.lastIndex=0,'"'+(d.test(r)?u(r):r)+'"'):r:'""'}function a(r,e,n,t){function u(r){return r&&"\n"===r["\r"===r[0]?1:0]}function i(r){return r&&!u(r)}function p(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 f(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,b;s&&(d=r.__WSC__);var y="[object Array]"===Object.prototype.toString.apply(r),g=y||!t||(d?!d.noRootBraces:h),v=m;g&&(m+=j);var x,k,_,w,O=c+v,S=c+m,E=n||l?"":O,W=[];if(y){for(x=0,k=r.length;k>x;x++)d&&W.push(p(d[x])+S),W.push(a(r[x],d?i(d[x+1]):!1,!0)||"null");d&&W.push(p(d[x])+O),w=d?E+"["+W.join("")+"]":0===W.length?"[]":E+"["+S+W.join(S)+O+"]"}else{if(d){b=p(d.c[""]);var C=d.o.slice();for(_ in r)Object.prototype.hasOwnProperty.call(r,_)&&C.indexOf(_)<0&&C.push(_);for(x=0,k=C.length;k>x;x++)_=C[x],(g||x>0||b)&&W.push(b+S),b=p(d.c[_]),w=a(r[_],i(b)),w&&W.push(o(_)+(u(w)?":":": ")+w);(g||b)&&W.push(b+O)}else for(_ in r)Object.prototype.hasOwnProperty.call(r,_)&&(w=a(r[_]),w&&W.push(o(_)+(u(w)?":":": ")+w));w=0===W.length?"{}":g?d?E+"{"+W.join("")+"}":E+"{"+S+W.join(S)+O+"}":W.join(d?"":S)}return m=v,w}}var c,s,l,p,h,d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,b=/[\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/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,g=/^(true|false|null)\s*((,|\]|\}|#|\/\/|\/\*).*)?$/,v={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},x=/[,\{\[\}\]\s:#"]|\/\/|\/\*|'''/,m="",j=" ";return function(n,t){var u,f;if(c=r,j=" ",s=!1,l=e,h=!0,p=!1,t&&"object"==typeof t&&(("\n"===t.eol||"\r\n"===t.eol)&&(c=t.eol),f=t.space,s=t.keepWsc,l=t.bracesSameLine||e,h=t.emitRootBraces,p="always"===t.quotes),"number"==typeof f)for(j="",u=0;f>u;u++)j+=" ";else"string"==typeof f&&(j=f);return a(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=!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} |
{ | ||
"name": "hjson", | ||
"description": "JSON for Humans, allows comments and is less error prone.", | ||
"description": "JSON for Humans. A configuration file format with relaxed syntax, fewer mistakes and more comments.", | ||
"main": "./lib/hjson.js", | ||
"author": "Christian Zangl", | ||
"version": "1.8.4", | ||
"version": "2.0.1", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "json", |
@@ -92,2 +92,3 @@ # hjson-js | ||
- *bracesSameLine*: boolean, makes braces appear on the same line as the key name. Default false. | ||
- *emitRootBraces*: boolean, show braces for the root object. Default true. | ||
- *quotes*: string, controls how strings are displayed. | ||
@@ -94,0 +95,0 @@ - "min": no quotes whenever possible (default) |
@@ -19,3 +19,3 @@ [ | ||
"E": 1.23456789e+34, | ||
"": 2.3456789012e+76, | ||
"-": 2.3456789012e+76, | ||
"zero": 0, | ||
@@ -22,0 +22,0 @@ "one": 1, |
@@ -15,3 +15,3 @@ [ | ||
"E": 1.234567890E+34, | ||
"": 23456789012E66, | ||
"-": 23456789012E66, | ||
"zero": 0, | ||
@@ -18,0 +18,0 @@ "one": 1, |
@@ -1,1 +0,1 @@ | ||
"foo=bar" | ||
"allow quoteless strings" |
@@ -52,4 +52,3 @@ { | ||
"minus": "-3" | ||
}, | ||
"": "empty" | ||
} | ||
} |
@@ -9,5 +9,7 @@ | ||
var filter=argv[0]; | ||
var success=true; | ||
function failErr(name, type, s1, s2) { | ||
console.log(name+" "+type+" FAILED!"); | ||
function failErr(name, type, s1, s2, msg) { | ||
msg=msg||" "+name+" "+type+" FAILED!"; | ||
console.log(msg); | ||
if (s1 || s2) { | ||
@@ -19,3 +21,3 @@ console.log("--- actual:"); | ||
} | ||
process.exit(1); | ||
success=false; | ||
} | ||
@@ -51,3 +53,3 @@ | ||
} | ||
else failErr(name, "should fail"); | ||
else failErr(name, null, null, null, " should fail but succeeded"); | ||
} | ||
@@ -61,3 +63,3 @@ catch (err) { | ||
var tests=fs.readdirSync(rootDir); | ||
var tests=fs.readFileSync(path.join(rootDir, "testlist.txt"), "utf8").split("\n"); | ||
tests.forEach(function(file) { | ||
@@ -70,2 +72,4 @@ var name = file.split("_test."); | ||
if (filter && name.indexOf(filter) < 0) return; // ignore | ||
console.log("- "+name); | ||
test(name, file, isJson, false, false); | ||
@@ -75,6 +79,5 @@ test(name, file, isJson, false, true); | ||
test(name, file, isJson, true, true); | ||
console.log("- "+name+" OK"); | ||
}); | ||
console.log("ALL OK!"); | ||
console.log(success?"ALL OK!":"FAIL!"); | ||
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
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
66230
96
1162
149