Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hjson

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hjson - npm Package Compare versions

Comparing version 1.7.3 to 1.7.4

out.txt

6

history.md
# hjson-js History
- v1.7.4
- fix trailing space in quoteless strings
- fix default braces
- v1.7.3
- fix root check
- better error messages
- v1.7.2

@@ -4,0 +10,0 @@ - fixed stringify, see laktak/hjson#29

11

lib/hjson.js
/*! @preserve
* Hjson v1.7.3
* Hjson v1.7.4
* http://hjson.org

@@ -353,3 +353,6 @@ *

}
if (isEol) return value;
if (isEol) {
// remove any whitespace at the end (ignored in quoteless strings)
return value.trim();
}
}

@@ -778,4 +781,4 @@ value += ch;

},
bracesSameLine: function() { return bracesSameLine; },
setBracesSameLine: function(v) { bracesSameLine = v; },
bracesSameLine: function() { return defaultBracesSameLine; },
setBracesSameLine: function(v) { defaultBracesSameLine = v; },

@@ -782,0 +785,0 @@ // round trip shortcut

/*! @preserve
* Hjson v1.7.3
* Hjson v1.7.4
* http://hjson.org

@@ -12,2 +12,2 @@ *

*/
var Hjson=function(){"use strict";var r="\n",e=!1,n=function(r,e){function n(){return f=r.charAt(a),a++,f}var t,f,u="",i=0,o=!0,a=0;for(n(),"-"===f&&(u="-",n());f>="0"&&"9">=f;)o&&("0"==f?i++:o=!1),u+=f,n();if(o&&i--,"."===f)for(u+=".";n()&&f>="0"&&"9">=f;)u+=f;if("e"===f||"E"===f)for(u+=f,n(),("-"===f||"+"===f)&&(u+=f,n());f>="0"&&"9">=f;)u+=f,n();for(;f&&" ">=f;)n();return e&&(","===f||"}"===f||"]"===f||"#"===f||"/"===f&&("/"===r[a]||"*"===r[a]))&&(f=0),t=+u,f||i||!isFinite(t)?void 0:t},t=function(){var r,e,t,f,u={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:" "},i=function(n){var t,f=0,u=1;for(t=e-1;t>0&&"\n"!==r[t];t--,f++);for(;t>0;t--)"\n"===r[t]&&u++;throw new Error(n+" at line "+u+","+f+" >>>"+r.substr(e-f,20)+" ...")},o=function(n){return n&&n!==t&&i("Expected '"+n+"' instead of '"+t+"'"),t=r.charAt(e),e++,t},a=function(n){return r.charAt(e+n)},s=function(){var r,e,n,f="";if('"'===t)for(;o();){if('"'===t)return o(),f;if("\\"===t)if(o(),"u"===t){for(n=0,e=0;4>e&&(r=parseInt(o(),16),isFinite(r));e++)n=16*n+r;f+=String.fromCharCode(n)}else{if("string"!=typeof u[t])break;f+=u[t]}else f+=t}i("Bad string")},c=function(){for(var r="",e=0,n=0;;){var f=a(-n-5);if(!f||"\n"===f)break;n++}for(var u=function(){for(var r=n;t&&" ">=t&&"\n"!==t&&r-->0;)o()};t&&" ">=t&&"\n"!==t;)o();for("\n"===t&&(o(),u());;){if(t){if("'"===t){if(e++,o(),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"===t?(r+="\n",o(),u()):("\r"!==t&&(r+=t),o())}},l=function(){if('"'===t)return s();for(var r="";;){if(":"===t)return r||i("Found ':' but no key name (for an empty key name use quotes)"),r;(" ">=t||"{"===t||"}"===t||"["===t||"]"===t||","===t)&&i("Found '"+t+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"),r+=t,o()}},p=function(){for(;t;){for(;t&&" ">=t;)o();if("#"===t||"/"===t&&"/"===a(0))for(;t&&"\n"!==t;)o();else{if("/"!==t||"*"!==a(0))break;for(o(),o();t&&("*"!==t||"/"!==a(0));)o();t&&(o(),o())}}},b=function(){for(var r=t;o();){if(3===r.length&&"'''"===r)return c();var e="\r"===t||"\n"===t;if(e||","===t||"}"===t||"]"===t||"#"===t||"/"===t&&("/"===a(0)||"*"===a(0))){var f=r[0];switch(f){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("-"===f||f>="0"&&"9">=f){var u=n(r);if(void 0!==u)return u}}if(e)return r}r+=t}i("End of input while parsing a value")},h=function(n){var t;for(n--,t=e-2;t>n&&r[t]<=" "&&"\n"!==r[t];t--);"\n"===r[t]&&t--,"\r"===r[t]&&t--;var f=r.substr(n,t-n+1);for(t=0;t<f.length;t++)if(f[t]>" ")return f;return""},d=function(){var r,n,u=[];if(f&&(Object.defineProperty&&Object.defineProperty(u,"__WSC__",{enumerable:!1,writable:!0}),u.__WSC__=r=[]),o(),n=e,p(),r&&r.push(h(n)),"]"===t)return o(),u;for(;t;){if(u.push(g()),n=e,p(),","===t&&(o(),n=e,p()),r&&r.push(h(n)),"]"===t)return o(),u;p()}i("End of input while parsing an array (did you forget a closing ']'?)")},v=function(r){function n(r){a.c[r]=h(s),r&&a.o.push(r)}var u,a,s,c={};if(f&&(Object.defineProperty&&Object.defineProperty(c,"__WSC__",{enumerable:!1,writable:!0}),c.__WSC__=a={c:{},o:[]},r&&(a.noRootBraces=!0)),r?s=1:(o(),s=e),p(),a&&n(""),"}"===t&&!r)return o(),c;for(;t;){if(u=l(),p(),o(":"),c[u]=g(),s=e,p(),","===t&&(o(),s=e,p()),a&&n(u),"}"===t&&!r)return o(),c;p()}return r?c:void i("End of input while parsing an object (did you forget a closing '}'?)")},g=function(){switch(p(),t){case"{":return v();case"[":return d();case'"':return s();default:return b()}},y=function(){switch(p(),t){case"{":return v();case"[":return d()}for(var e=0;e<r.length;e++)if("\n"===r[e])return v(!0);return g()};return function(n,u){var o;return f=u&&u.keepWsc,r=n,e=0,t=" ",o=y(),p(),t&&i("Syntax error, found trailing characters"),o}}(),f=function(){function t(r){return" ">=r}function f(r){return r.replace(h,function(r){var e=y[r];return"string"==typeof e?e:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})}function u(r,e,u,o){if(!r)return'""';d.lastIndex=0,g.lastIndex=0;var a=p||u||d.test(r),s=r[0],c=r[r.length-1];return a||t(s)||'"'===s||"#"===s||"/"===s&&("*"===r[1]||"/"===r[1])||"{"===s||"["===s||t(c)||void 0!==n(r,!0)||g.test(r)?(h.lastIndex=0,v.lastIndex=0,h.test(r)?v.test(r)||o?'"'+f(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 f=s+e+"'''";for(n=0;n<t.length;n++)f+=s,t[n]&&(f+=e+t[n]);return f+s+e+"'''"}function o(r){return r?x.test(r)?(h.lastIndex=0,'"'+(h.test(r)?f(r):r)+'"'):r:'""'}function a(r,e,n,t){function f(r){return r&&"\n"===r["\r"===r[0]?1:0]}function i(r){return r&&!f(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 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 h,d;c&&(h=r.__WSC__);var v="[object Array]"===Object.prototype.toString.apply(r),g=v||!t||(h?!h.noRootBraces:b),y=m;g&&(m+=j);var x,_,w,k,S=s+y,O=s+m,E=n||l?"":S,L=[];if(v){for(x=0,_=r.length;_>x;x++)h&&L.push(p(h[x])+O),L.push(a(r[x],h?i(h[x+1]):!1,!0)||"null");h&&L.push(p(h[x])+S),k=h?E+"["+L.join("")+"]":0===L.length?"[]":E+"["+O+L.join(O)+S+"]"}else{if(h){d=p(h.c[""]);var W=h.o.slice();for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&W.indexOf(w)<0&&W.push(w);for(x=0,_=W.length;_>x;x++)w=W[x],(g||x>0||d)&&L.push(d+O),d=p(h.c[w]),k=a(r[w],i(d)),k&&L.push(o(w)+(f(k)?":":": ")+k);(g||d)&&L.push(d+S)}else for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&(k=a(r[w]),k&&L.push(o(w)+(f(k)?":":": ")+k));k=0===L.length?"{}":g?h?E+"{"+L.join("")+"}":E+"{"+O+L.join(O)+S+"}":L.join(h?"":O)}return m=y,k}}var s,c,l,p,b,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,v=/'''|[\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*((,|\]|\}|#|\/\/|\/\*).*)?$/,y={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},x=/[,\{\[\}\]\s]/,m="",j=" ";return function(n,t){var f,u;if(s=r,j=" ",c=!1,l=e,b=!0,p=!1,t&&"object"==typeof t&&(("\n"===t.eol||"\r\n"===t.eol)&&(s=t.eol),u=t.space,c=t.keepWsc,l=t.bracesSameLine||e,b=t.emitRootBraces,p="always"===t.quotes),"number"==typeof u)for(j="",f=0;u>f;f++)j+=" ";else"string"==typeof u&&(j=u);return a(n,null,!0,!0)}}();return{parse:t,stringify:f,endOfLine:function(){return r},setEndOfLine:function(e){("\n"===e||"\r\n"===e)&&(r=e)},bracesSameLine:function(){return bracesSameLine},setBracesSameLine:function(r){bracesSameLine=r},rt:{parse:function(r,e){return(e=e||{}).keepWsc=!0,t(r,e)},stringify:function(r,e){return(e=e||{}).keepWsc=!0,f(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 f=r.charAt(a),a++,f}var t,f,u="",i=0,o=!0,a=0;for(n(),"-"===f&&(u="-",n());f>="0"&&"9">=f;)o&&("0"==f?i++:o=!1),u+=f,n();if(o&&i--,"."===f)for(u+=".";n()&&f>="0"&&"9">=f;)u+=f;if("e"===f||"E"===f)for(u+=f,n(),("-"===f||"+"===f)&&(u+=f,n());f>="0"&&"9">=f;)u+=f,n();for(;f&&" ">=f;)n();return e&&(","===f||"}"===f||"]"===f||"#"===f||"/"===f&&("/"===r[a]||"*"===r[a]))&&(f=0),t=+u,f||i||!isFinite(t)?void 0:t},t=function(){var r,e,t,f,u={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:" "},i=function(n){var t,f=0,u=1;for(t=e-1;t>0&&"\n"!==r[t];t--,f++);for(;t>0;t--)"\n"===r[t]&&u++;throw new Error(n+" at line "+u+","+f+" >>>"+r.substr(e-f,20)+" ...")},o=function(n){return n&&n!==t&&i("Expected '"+n+"' instead of '"+t+"'"),t=r.charAt(e),e++,t},a=function(n){return r.charAt(e+n)},s=function(){var r,e,n,f="";if('"'===t)for(;o();){if('"'===t)return o(),f;if("\\"===t)if(o(),"u"===t){for(n=0,e=0;4>e&&(r=parseInt(o(),16),isFinite(r));e++)n=16*n+r;f+=String.fromCharCode(n)}else{if("string"!=typeof u[t])break;f+=u[t]}else f+=t}i("Bad string")},c=function(){for(var r="",e=0,n=0;;){var f=a(-n-5);if(!f||"\n"===f)break;n++}for(var u=function(){for(var r=n;t&&" ">=t&&"\n"!==t&&r-->0;)o()};t&&" ">=t&&"\n"!==t;)o();for("\n"===t&&(o(),u());;){if(t){if("'"===t){if(e++,o(),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"===t?(r+="\n",o(),u()):("\r"!==t&&(r+=t),o())}},l=function(){if('"'===t)return s();for(var r="";;){if(":"===t)return r||i("Found ':' but no key name (for an empty key name use quotes)"),r;(" ">=t||"{"===t||"}"===t||"["===t||"]"===t||","===t)&&i("Found '"+t+"' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"),r+=t,o()}},p=function(){for(;t;){for(;t&&" ">=t;)o();if("#"===t||"/"===t&&"/"===a(0))for(;t&&"\n"!==t;)o();else{if("/"!==t||"*"!==a(0))break;for(o(),o();t&&("*"!==t||"/"!==a(0));)o();t&&(o(),o())}}},h=function(){for(var r=t;o();){if(3===r.length&&"'''"===r)return c();var e="\r"===t||"\n"===t;if(e||","===t||"}"===t||"]"===t||"#"===t||"/"===t&&("/"===a(0)||"*"===a(0))){var f=r[0];switch(f){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("-"===f||f>="0"&&"9">=f){var u=n(r);if(void 0!==u)return u}}if(e)return r.trim()}r+=t}i("End of input while parsing a value")},d=function(n){var t;for(n--,t=e-2;t>n&&r[t]<=" "&&"\n"!==r[t];t--);"\n"===r[t]&&t--,"\r"===r[t]&&t--;var f=r.substr(n,t-n+1);for(t=0;t<f.length;t++)if(f[t]>" ")return f;return""},b=function(){var r,n,u=[];if(f&&(Object.defineProperty&&Object.defineProperty(u,"__WSC__",{enumerable:!1,writable:!0}),u.__WSC__=r=[]),o(),n=e,p(),r&&r.push(d(n)),"]"===t)return o(),u;for(;t;){if(u.push(g()),n=e,p(),","===t&&(o(),n=e,p()),r&&r.push(d(n)),"]"===t)return o(),u;p()}i("End of input while parsing an array (did you forget a closing ']'?)")},v=function(r){function n(r){a.c[r]=d(s),r&&a.o.push(r)}var u,a,s,c={};if(f&&(Object.defineProperty&&Object.defineProperty(c,"__WSC__",{enumerable:!1,writable:!0}),c.__WSC__=a={c:{},o:[]},r&&(a.noRootBraces=!0)),r?s=1:(o(),s=e),p(),a&&n(""),"}"===t&&!r)return o(),c;for(;t;){if(u=l(),p(),o(":"),c[u]=g(),s=e,p(),","===t&&(o(),s=e,p()),a&&n(u),"}"===t&&!r)return o(),c;p()}return r?c:void i("End of input while parsing an object (did you forget a closing '}'?)")},g=function(){switch(p(),t){case"{":return v();case"[":return b();case'"':return s();default:return h()}},y=function(){switch(p(),t){case"{":return v();case"[":return b()}for(var e=0;e<r.length;e++)if("\n"===r[e])return v(!0);return g()};return function(n,u){var o;return f=u&&u.keepWsc,r=n,e=0,t=" ",o=y(),p(),t&&i("Syntax error, found trailing characters"),o}}(),f=function(){function t(r){return" ">=r}function f(r){return r.replace(d,function(r){var e=y[r];return"string"==typeof e?e:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})}function u(r,e,u,o){if(!r)return'""';b.lastIndex=0,g.lastIndex=0;var a=p||u||b.test(r),s=r[0],c=r[r.length-1];return a||t(s)||'"'===s||"#"===s||"/"===s&&("*"===r[1]||"/"===r[1])||"{"===s||"["===s||t(c)||void 0!==n(r,!0)||g.test(r)?(d.lastIndex=0,v.lastIndex=0,d.test(r)?v.test(r)||o?'"'+f(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 f=s+e+"'''";for(n=0;n<t.length;n++)f+=s,t[n]&&(f+=e+t[n]);return f+s+e+"'''"}function o(r){return r?x.test(r)?(d.lastIndex=0,'"'+(d.test(r)?f(r):r)+'"'):r:'""'}function a(r,e,n,t){function f(r){return r&&"\n"===r["\r"===r[0]?1:0]}function i(r){return r&&!f(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 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,b;c&&(d=r.__WSC__);var v="[object Array]"===Object.prototype.toString.apply(r),g=v||!t||(d?!d.noRootBraces:h),y=m;g&&(m+=j);var x,_,w,k,O=s+y,S=s+m,E=n||l?"":O,W=[];if(v){for(x=0,_=r.length;_>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),k=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(w in r)Object.prototype.hasOwnProperty.call(r,w)&&C.indexOf(w)<0&&C.push(w);for(x=0,_=C.length;_>x;x++)w=C[x],(g||x>0||b)&&W.push(b+S),b=p(d.c[w]),k=a(r[w],i(b)),k&&W.push(o(w)+(f(k)?":":": ")+k);(g||b)&&W.push(b+O)}else for(w in r)Object.prototype.hasOwnProperty.call(r,w)&&(k=a(r[w]),k&&W.push(o(w)+(f(k)?":":": ")+k));k=0===W.length?"{}":g?d?E+"{"+W.join("")+"}":E+"{"+S+W.join(S)+O+"}":W.join(d?"":S)}return m=y,k}}var s,c,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,v=/'''|[\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*((,|\]|\}|#|\/\/|\/\*).*)?$/,y={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},x=/[,\{\[\}\]\s]/,m="",j=" ";return function(n,t){var f,u;if(s=r,j=" ",c=!1,l=e,h=!0,p=!1,t&&"object"==typeof t&&(("\n"===t.eol||"\r\n"===t.eol)&&(s=t.eol),u=t.space,c=t.keepWsc,l=t.bracesSameLine||e,h=t.emitRootBraces,p="always"===t.quotes),"number"==typeof u)for(j="",f=0;u>f;f++)j+=" ";else"string"==typeof u&&(j=u);return a(n,null,!0,!0)}}();return{parse:t,stringify:f,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,f(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": "1.7.3",
"version": "1.7.4",
"keywords": [

@@ -33,11 +33,6 @@ "json",

},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/laktak/hjson-js/raw/master/LICENSE"
}
],
"license": "MIT",
"devDependencies": {
"uglify-js": "^2.4.16"
"uglify-js": "^2.4.24"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc