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.2 to 0.5.3

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=()=>{if(i)d&&b.push(trueValue(d.trimEnd()));else{if(!e)throw error("Expecting value after =");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 HUML.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 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
{
"name": "fast-toml",
"version": "0.5.2",
"version": "0.5.3",
"description": "Fast and light parser for TOML 0.5, an alternative to JSON or YAML file formats.",

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

"repository": {
"type" : "git",
"url" : "https://github.com/Lepzulnag/fast-toml.git"
"type": "git",
"url": "https://github.com/Lepzulnag/fast-toml.git"
}
}
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