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

fast-toml

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-toml - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

2

fast-toml.js

@@ -1,1 +0,1 @@

'use strict';let source="",position=0;function skipWhiteSpaces(a,b=0){let c;while((c=a[b++])&&(c==' '||c=='\t'||c=='\r'));;return b-1}function trueValue(a){switch(a[0]){case undefined:return'';case '"':return escapeSpecials(a.slice(1,-1));case "'":return a.slice(1,-1);case '0':;case '1':;case '2':;case '3':;case '4':;case '5':;case '6':;case '7':;case '8':;case '9':;case '+':;case '-':;case '.':let b=a;b.indexOf('_')!=-1&&(b=b.replace(/_/g,''));if(!isNaN(b))return+b;if(a[4]=='-'&&a[7]=='-'){let b=new Date(a);if(b.toString()!='Invalid Date')return b}else if(a[2]==':'&&a[5]==':'&&a.length>=7){let b=new Date('0000-01-01T'+a+'Z');if(b.toString()!='Invalid Date')return b};return a};switch(a){case 'true':return !0;case 'false':return !1;case 'nan':;case 'NaN':return !1;case 'null':return null;case 'inf':;case '+inf':;case 'Infinity':;case '+Infinity':return Infinity;case '-inf':;case '-Infinity':return-Infinity};return a}function escapeSpecials(a){let b,c=0,d='';while(b=a.indexOf('\\',c)+1){d+=a.slice(c,b-1);switch(a[b]){case '\\':d+='\\';break;case '"':d+='"';break;case '\r':a[b+1]=='\n'&&b++;case '\n':break;case 'b':d+='\b';break;case 't':d+='\t';break;case 'n':d+='\n';break;case 'f':d+='\f';break;case 'r':d+='\r';break;case 'u':d+=String.fromCharCode(parseInt(a.substr(b+1,4),16));b+=4;break;case 'U':d+=String.fromCharCode(parseInt(a.substr(b+1,8),16));b+=8;break;default:throw error(a[b])};c=b+1}return d+a.slice(c)}function error(a){let b=getLocation(),c=String(b.line);a+='\n'+c+' | '+b.lineContent+'\n';a+=' '.repeat(c.length+b.column+2)+'^';return SyntaxError(a)}function fragment(a,b=0,c=!1){let d=a[b],e,f=d,g=d,h=!0,i=!1;switch(d){case '"':;case "'":e=b+1;c&&a[b+1]==d&&a[b+2]==d?(g=d+d+d,e+=2):(i=!0);if(d=="'")e=a.indexOf(g,e)+1;else while(e=a.indexOf(g,e)+1){let b=!0,c=e-1;while(a[--c]=='\\')b=!b;if(b)break};if(!e)throw error("Missing "+g+" closer");if(d!=g)e+=2;else if(i){let c=a.indexOf('\n',b+1)+1;if(c&&c<e){position=c-2;throw error("Forbidden end-of-line character in single-line string")}};return e;case '(':g=')';break;case '{':g='}';break;case '[':g=']';break;case '<':g='>';break;default:h=!1};let j=0;while(d=a[++b]){if(d==g){if(j==0)return b+1;j--}else if(d=='"'||d=="'"){let d=fragment(a,b,c);b=d-1}else h&&d==f&&j++}throw error("Missing "+g)}function getLocation(){let a=source[position],b=position;a=='\n'&&b--;let c=1,d=source.lastIndexOf('\n',b),e=source.indexOf('\n',b);e==-1&&(e=Infinity);(a==','||a=='\n')&&(b=d+1);if(d==-1)return{line:c,column:b+1,position:b,lineContent:source.slice(0,e).trim()};let f=b-d+1,g=source.slice(d+1,e).trim();c++;while((d=source.lastIndexOf('\n',d-1))!=-1)c++;return{line:c,column:f,position:b,lineContent:g}}function splitElements(a){typeof a!='string'&&(a=String(a));let b=-1,c='',d=[],e,f;while(f=a[++b])switch(f){case '.':if(!c)throw error('Unexpected "."');d.push(c);c='';continue;case '"':;case "'":e=fragment(a,b);if(e==b+2)throw error('Empty string key');c+=a.slice(b+1,e-1);b=e-1;continue;default:c+=f};c&&d.push(c);return d}function getTable(a,b=[]){for(let c of b){if(!(c in a))a[c]={};else if(typeof a[c]!='object'){let a='["'+b.slice(0,b.indexOf(c)+1).join('"].["')+'"]';throw error(a+' must be an object')};a=a[c]}return a}class Scope{constructor(a={}){this.data=a;this.scopeList=[]}getCurrentScope(){return this.scopeList[this.scopeList.length-1]}getFullScope(a=null){let b=[];for(let a of this.scopeList)b=b.concat(a.elements);a&&(b=b.concat(a));return b}set(a,b){let c=splitElements(a);a=c.pop();let d=this.getFullScope(c),e=getTable(this.data,d);if(typeof e=='string')return e;e[a]=b}push(a){if(!this.scopeList.length){if(!Array.isArray(this.data)){let a=this.data;this.data=[];Object.assign(this.data,a)}this.data.push(a);return this.data}let b=this.getFullScope(),c=b.pop(),d=getTable(this.data,b);if(typeof d=='string')return d;let e=d[c];switch(typeof e){case 'object':if(Array.isArray(e))break;case undefined:d[c]=Array();Object.assign(d[c],e);e=d[c];break;default:return'["'+b.join('"].["')+'"].["'+c+'"] must be an object'};e.push(a);return e}use(a){let b=globalScope(a),c=this.getCurrentScope();c&&c.isGlobal&&this.scopeList.pop();this.scopeList.push(b);getTable(this.data,this.getFullScope())}useArray(a){this.use(a);let b=this.push({}),c=b.length-1;this.use(a+'.'+c)}enter(a,b=!1){this.scopeList.push(inlineScope(a.trimEnd()));let c=this.getFullScope(),d=c.pop(),e=getTable(this.data,c);(d in e)||(e[d]=b?[]:{})}enterArray(a=!1){let b=this.push(a?[]:{});this.scopeList.push(inlineScope(b.length-1))}exit(){let a;while((a=this.scopeList.pop())&&a.isGlobal);}}let globalScope=a=>({isGlobal:!0,elements:splitElements(a)}),inlineScope=a=>({isInline:!0,elements:splitElements(a)});function parse(a){typeof a!='string'&&(a=String(a));let b=new Scope,c=[];source=a;position=0;let d='',e='',f,g,h=source[0],i=!0,j=()=>{i?(d&&b.push(trueValue(d.trimEnd()))):b.set(d.trimEnd(),trueValue(e.trimEnd()));d='';e='';i=!0};do{switch(h){case ' ':i?(d&&(d+=h)):e&&(e+=h);case '\t':;case '\r':continue;case '#':position=source.indexOf('\n',position+1)-1;position==-2&&(position=Infinity);continue;case '"':;case "'":if(!i&&e){e+=h;continue};let a=source[position+1]==h&&source[position+2]==h;f=fragment(source,position,!0);if(i){if(d)throw error('Unexpected '+h);a?(d+=source.slice(position+2,f-2)):(d+=source.slice(position,f));position=f}else e=source.slice(position,f),position=f,a&&(e=e.slice(2,-2),e[1]=='\n'?(e=e[0]+e.slice(2)):e[1]=='\r'&&e[2]=='\n'&&(e=e[0]+e.slice(3)));position=skipWhiteSpaces(source,position);h=source[position];if(h&&h!=','&&h!='\n'&&h!='#'&&h!='}'&&h!=']'&&h!='=')throw error("Unexpected character after end of string");position--;continue;case '\n':;case ',':;case undefined:j();continue;case '[':;case '{':g=h=='['?']':'}';if(i&&!c.length){if(d)throw error("Unexpected "+h);f=fragment(source,position);if(source[position+1]==h){if(source[f-2]!=g)throw error("Missing "+g+g);b.useArray(source.slice(position+2,f-2))}else b.use(source.slice(position+1,f-1));position=f}else if(i){if(d)throw error("Unexpected "+h);b.enterArray(h=='[');c.push(g)}else{if(e)throw error("Unexpected "+h);b.enter(d,h=='[');c.push(g);d='';i=!0};continue;case ']':;case '}':d&&j();if(c.pop()!=h)throw error("Unexpected "+h);b.exit();position=skipWhiteSpaces(source,position+1);h=source[position];if(h&&h!=','&&h!='\n'&&h!='#'&&h!='}'&&h!=']')throw error("Unexpected character after end of scope");position--;continue;case '=':if(i){if(!d)throw error("Missing key before "+h);i=!1}else throw error("Unexpected "+h);continue;default:i?(d+=h):(e+=h)}}while((h=source[++position])||d);if(c.length)throw error("Missing "+c.pop());return b.data}let fs=null,readFile=null;function TOML(){let a='';for(let b of arguments)a+=typeof b=='string'?b:b[0];return parse(a)}TOML.parse=parse;TOML.parseFile=async function(a){fs||(fs=require('fs'));if(!readFile){let{promisify:a}=require('util');readFile=a(fs.readFile)}let b=await readFile(a);return parse(b)};TOML.parseFileSync=function(a){fs||(fs=require('fs'));return parse(fs.readFileSync(a))};module.exports=TOML
"use strict";let e="",t=0;function i(e,t=0){let i;for(;(i=e[t++])&&(" "==i||"\t"==i||"\r"==i););return t-1}function n(e){switch(e[0]){case void 0:return"";case'"':return function(e){let t,i=0,n="";for(;t=e.indexOf("\\",i)+1;){switch(n+=e.slice(i,t-1),e[t]){case"\\":n+="\\";break;case'"':n+='"';break;case"\r":"\n"==e[t+1]&&t++;case"\n":break;case"b":n+="\b";break;case"t":n+="\t";break;case"n":n+="\n";break;case"f":n+="\f";break;case"r":n+="\r";break;case"u":n+=String.fromCharCode(parseInt(e.substr(t+1,4),16)),t+=4;break;case"U":n+=String.fromCharCode(parseInt(e.substr(t+1,8),16)),t+=8;break;default:throw s(e[t])}i=t+1}return n+e.slice(i)}(e.slice(1,-1));case"'":return e.slice(1,-1);case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"+":case"-":case".":let t=e;if(-1!=t.indexOf("_")&&(t=t.replace(/_/g,"")),!isNaN(t))return+t;if("-"==e[4]&&"-"==e[7]){let t=new Date(e);if("Invalid Date"!=t.toString())return t}else if(":"==e[2]&&":"==e[5]&&e.length>=7){let t=new Date("0000-01-01T"+e+"Z");if("Invalid Date"!=t.toString())return t}return e}switch(e){case"true":return!0;case"false":return!1;case"nan":case"NaN":return!1;case"null":return null;case"inf":case"+inf":case"Infinity":case"+Infinity":return 1/0;case"-inf":case"-Infinity":return-1/0}return e}function s(i){let n=function(){let i=e[t],n=t;"\n"==i&&n--;let s=1,r=e.lastIndexOf("\n",n),a=e.indexOf("\n",n);-1==a&&(a=1/0);","!=i&&"\n"!=i||(n=r+1);if(-1==r)return{line:s,column:n+1,position:n,lineContent:e.slice(0,a).trim()};const c=n-r+1,o=e.slice(r+1,a).trim();s++;for(;-1!=(r=e.lastIndexOf("\n",r-1));)s++;return{line:s,column:c,position:n,lineContent:o}}(),s=String(n.line);return i+="\n"+s+" | "+n.lineContent+"\n",i+=" ".repeat(s.length+n.column+2)+"^",SyntaxError(i)}function r(e,i=0,n=!1){let a,c=e[i],o=c,f=c,l=!0,u=!1;switch(c){case'"':case"'":if(a=i+1,n&&e[i+1]==c&&e[i+2]==c?(f=c+c+c,a+=2):u=!0,"'"==c)a=e.indexOf(f,a)+1;else for(;a=e.indexOf(f,a)+1;){let t=!0,i=a-1;for(;"\\"==e[--i];)t=!t;if(t)break}if(!a)throw s("Missing "+f+" closer");if(c!=f)a+=2;else if(u){let n=e.indexOf("\n",i+1)+1;if(n&&n<a)throw t=n-2,s("Forbidden end-of-line character in single-line string")}return a;case"(":f=")";break;case"{":f="}";break;case"[":f="]";break;case"<":f=">";break;default:l=!1}let h=0;for(;c=e[++i];)if(c==f){if(0==h)return i+1;h--}else if('"'==c||"'"==c){i=r(e,i,n)-1}else l&&c==o&&h++;throw s("Missing "+f)}function a(e){"string"!=typeof e&&(e=String(e));let t,i,n=-1,a="",c=[];for(;i=e[++n];)switch(i){case".":if(!a)throw s('Unexpected "."');c.push(a),a="";continue;case'"':case"'":if(t=r(e,n),t==n+2)throw s("Empty string key");a+=e.slice(n+1,t-1),n=t-1;continue;default:a+=i}return a&&c.push(a),c}function c(e,t=[]){const i=t.pop();for(let i of t){if("object"!=typeof e){throw s('["'+t.slice(0,t.indexOf(i)+1).join('"].["')+'"]'+" must be an object")}void 0===e[i]&&(e[i]={}),(e=e[i])instanceof Array&&(e=e[e.length-1])}return[e,i]}class o{constructor(){this.root={},this.data=this.root,this.inlineScopeList=[]}get isRoot(){return this.data==this.root}set(e,t){let[i,n]=c(this.data,a(e));if("string"==typeof i)throw"Wtf the scope is a string. Please report the bug";if(n in i)throw s(`Re-writing the key '${e}'`);return i[n]=t,t}push(e){if(!(this.data instanceof Array)){if(!this.isRoot)throw s("Missing key");this.data=Object.assign([],this.data),this.root=this.data}return this.data.push(e),this}use(e){return this.data=function(e,t=[]){for(let i of t){if(void 0===e)e=lastData[lastElt]={};else if("object"!=typeof e){throw s('["'+t.slice(0,t.indexOf(i)+1).join('"].["')+'"]'+" must be an object")}void 0===e[i]&&(e[i]={}),(e=e[i])instanceof Array&&(e=e[e.length-1])}return e}(this.root,a(e)),this}useArray(e){let[t,i]=c(this.root,a(e));return this.data={},void 0===t[i]&&(t[i]=[]),t[i].push(this.data),this}enter(e,t){return this.inlineScopeList.push(this.data),this.set(e,t),this.data=t,this}enterArray(e){return this.inlineScopeList.push(this.data),this.push(e),this.data=e,this}exit(){return this.data=this.inlineScopeList.pop(),this}}function f(a){"string"!=typeof a&&(a=String(a));const c=new o,f=[];e=a,t=0;let l,u,h="",d="",p=e[0],w=!0;const g=()=>{if(h=h.trimEnd(),w)h&&c.push(n(h));else{if(!h)throw s("Expected key before =");if(!d)throw s("Expected value after =");c.set(h,n(d.trimEnd()))}h="",d="",w=!0};do{switch(p){case" ":w?h&&(h+=p):d&&(d+=p);case"\t":case"\r":continue;case"#":t=e.indexOf("\n",t+1)-1,-2==t&&(t=1/0);continue;case'"':case"'":if(!w&&d){d+=p;continue}let n=e[t+1]==p&&e[t+2]==p;if(l=r(e,t,!0),w){if(h)throw s("Unexpected "+p);h+=n?e.slice(t+2,l-2):e.slice(t,l),t=l}else d=e.slice(t,l),t=l,n&&(d=d.slice(2,-2),"\n"==d[1]?d=d[0]+d.slice(2):"\r"==d[1]&&"\n"==d[2]&&(d=d[0]+d.slice(3)));if(t=i(e,t),p=e[t],p&&","!=p&&"\n"!=p&&"#"!=p&&"}"!=p&&"]"!=p&&"="!=p)throw s("Unexpected character after end of string");t--;continue;case"\n":case",":case void 0:g();continue;case"[":case"{":if(u="["==p?"]":"}",w&&!f.length){if(h)throw s("Unexpected "+p);if(l=r(e,t),"["==p&&"["==e[t+1]){if("]"!=e[l-2])throw s("Missing ]]");c.useArray(e.slice(t+2,l-2))}else c.use(e.slice(t+1,l-1));t=l}else if(w){if(h)throw s("Unexpected "+p);c.enterArray("["==p?[]:{}),f.push(u)}else{if(d)throw s("Unexpected "+p);c.enter(h.trimEnd(),"["==p?[]:{}),f.push(u),h="",w=!0}continue;case"]":case"}":if(h&&g(),f.pop()!=p)throw s("Unexpected "+p);if(c.exit(),t=i(e,t+1),p=e[t],p&&","!=p&&"\n"!=p&&"#"!=p&&"}"!=p&&"]"!=p)throw s("Unexpected character after end of scope");t--;continue;case"=":if(!w)throw s("Unexpected "+p);if(!h)throw s("Missing key before "+p);w=!1;continue;default:w?h+=p:d+=p}}while((p=e[++t])||h);if(f.length)throw s("Missing "+f.pop());return c.root}let l=null,u=null;function h(){let e="";for(let t of arguments)e+="string"==typeof t?t:t[0];return f(e)}h.parse=f,h.parseFile=async function(e){if(l||(l=require("fs")),!u){const{promisify:e}=require("util");u=e(l.readFile)}return f(await u(e))},h.parseFileSync=function(e){return l||(l=require("fs")),f(l.readFileSync(e))},module.exports=h;
{
"name": "fast-toml",
"version": "0.5.3",
"version": "0.5.4",
"description": "Fast and light parser for TOML 0.5, an alternative to JSON or YAML file formats.",

@@ -5,0 +5,0 @@ "main": "fast-toml.js",

@@ -76,3 +76,3 @@ # Fast TOML Parser for Node.js

### Using in browser
You can download the browser version of fast-toml [here](https://github.com/Lepzulnag/fast-toml/blob/master/browser/fast-toml.js).
You can download the browser version of fast-toml [here](https://github.com/Lepzulnag/fast-toml/blob/master/dist/browser/fast-toml.js).

@@ -89,4 +89,2 @@ Just add the file to your project and require it with a script tag. You can then use the globally defined `TOML` object.

*(All time values are milliseconds)*
| | fast-toml | Iarna's toml | j-toml | Bombadil |

@@ -99,6 +97,9 @@ |-----------------------------------------------------------------|------------|--------------|----------------------|----------|

| Hot round | **0.501** | 0.604 | 0.627 | 6.639 |
| Package size | **13.8 ko** | 93.1 ko | 261 ko | +3000 ko |
| Package size | **12.7 ko** | 93.1 ko | 261 ko | +3000 ko |
*(All time values are milliseconds)*
The comparison has been made in a Node 11.2.0 environment with this medium-size [sample TOML file](https://gist.github.com/robmuh/7966da29024c075349a963840e2298b2), which covers about all the different ways to use TOML.

@@ -134,2 +135,2 @@

These small tweaks make the TOML language even more comfortable to read and write, but be aware *they are not standard*.
These small tweaks make the TOML language even more comfortable to read and write, but be aware *they are not standard*.
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