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

modl-interpreter

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

modl-interpreter - npm Package Compare versions

Comparing version 0.0.14 to 0.0.15

2

dist/bundle.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MODLInterpreter=t():e.MODLInterpreter=t()}(self,(function(){return(()=>{"use strict";var e={235:function(e,t,n){var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.ParserException=t.parseModl=void 0;var i=n(957),s=n(62),l=n(666);t.parseModl=function(e){var t=s.tokeniser(e),n=u(new l.TokenStream(t));return new i.Modl(n)};var a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(Error);t.ParserException=a;var u=function(e){var t=p(e);return null!==t?t:c(e)},p=function(e){var t=null,n=e.next();switch(n.type){case s.TokenType.LPAREN:case s.TokenType.RPAREN:case s.TokenType.LBRACKET:case s.TokenType.RBRACKET:case s.TokenType.EQUALS:if(e.empty())throw new a("Unexpected token: "+n.toS());return e.pushBack(n),null;case s.TokenType.NULL:t=i.ModlBoolNull.ModlNull;break;case s.TokenType.TRUE:t=i.ModlBoolNull.ModlTrue;break;case s.TokenType.FALSE:t=i.ModlBoolNull.ModlFalse;break;case s.TokenType.QUOTED:t=new i.ModlQuoted(n.value);break;case s.TokenType.STRING:t=new i.ModlString(n.value);break;case s.TokenType.INTEGER:t=new i.ModlInteger(n.value);break;case s.TokenType.FLOAT:t=new i.ModlFloat(n.value);break;default:throw new a("Unknown token type in: "+n.toS())}if(null!==t){var o=e.peek();if(o&&o.type===s.TokenType.STRUCT_SEP)throw new a("Only one primitive is allowed at the root.");if(o&&(o.type===s.TokenType.LPAREN||o.type===s.TokenType.LBRACKET||o.type===s.TokenType.EQUALS))return e.pushBack(n),null}return t},c=function(e){for(var t=[];!e.empty();){t.push(d(e));var n=e.next();if(n&&n.type!==s.TokenType.STRUCT_SEP)throw new a("Expected ';' near "+n.toS())}return t},d=function(e){var t=e.next();if(t.type===s.TokenType.LBRACKET){for(var n=[];!e.empty();){if((u=e.peek())&&u.type===s.TokenType.RBRACKET){e.next();break}var o=d(e);if(n.push(o),!(u=e.peek()))throw new a("Expected ']' near "+t.toS());if(u.type===s.TokenType.RBRACKET){e.next();break}if(u.type===s.TokenType.STRUCT_SEP&&(e.next(),(u=e.peek())&&u.type===s.TokenType.RBRACKET))throw new a("Unexpected ; before ] at "+u)}return new i.ModlArray(n)}if(t.type===s.TokenType.LPAREN){for(var r=[];!e.empty();){if((u=e.peek())&&u.type===s.TokenType.RPAREN){e.next();break}var l=d(e);if(r.push(l),!(u=e.peek()))throw new a("Expected ')' near "+t.toS());if(u.type===s.TokenType.RPAREN){e.next();break}if(u.type===s.TokenType.STRUCT_SEP&&(e.next(),(u=e.peek())&&u.type===s.TokenType.RPAREN))throw new a("Unexpected ; before ] at "+u)}return new i.ModlMap(r)}if(t.type===s.TokenType.STRING||t.type===s.TokenType.QUOTED){var u=e.peek(),c=t.value;if(u&&u.type===s.TokenType.EQUALS)return e.next(),new i.ModlPair(c,d(e));if(u&&(u.type===s.TokenType.LBRACKET||u.type===s.TokenType.LPAREN))return new i.ModlPair(c,d(e));if(!u||u&&(u.type===s.TokenType.STRUCT_SEP||u.type===s.TokenType.RPAREN||u.type===s.TokenType.RBRACKET))return t.type===s.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===s.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===s.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===s.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===s.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===s.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var f=p(e);if(f)return f;throw new a("Unexpected token: '"+t.toS()+"'")}},62:function(e,t){var n,o=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)});Object.defineProperty(t,"__esModule",{value:!0}),t.TokenType=t.TokeniserException=t.tokeniser=t.Token=void 0;var r=function(){function e(e,t,n,o){this.type=e,this.value=t,this.from=n,this.to=o}return e.prototype.toS=function(){return"type: "+this.type.toString()+", from: "+this.from+", to: "+this.to+', value: "'+this.value+'"'},e}();t.Token=r,t.tokeniser=function(e){return new u(e).parse()};var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(Error);t.TokeniserException=i;var s,l=new RegExp(/^-?\d+$/),a=new RegExp(/^-?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?$/);!function(e){e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.STRUCT_SEP="STRUCT_SEP",e.NULL="NULL",e.TRUE="TRUE",e.FALSE="FALSE",e.EQUALS="EQUALS",e.QUOTED="QUOTED",e.STRING="STRING",e.INTEGER="INTEGER",e.FLOAT="FLOAT"}(s=t.TokenType||(t.TokenType={}));var u=function(){function e(e){this.s=e,this.tokStart=0,this.tokEnd=0,this.tokens=new Array}return e.prototype.parse=function(){for(;this.next(););return this.tokens},e.prototype.next=function(){for(var e,t=this.s.charAt(this.tokStart);""!=t&&" \t\r\n".includes(t);)this.tokStart++,t=this.s.charAt(this.tokStart);if(this.tokStart>=this.s.length)return!1;switch(this.s.charAt(this.tokStart)){case"(":e=s.LPAREN,this.tokEnd=this.tokStart+1;break;case")":e=s.RPAREN,this.tokEnd=this.tokStart+1;break;case"[":e=s.LBRACKET,this.tokEnd=this.tokStart+1;break;case"]":e=s.RBRACKET,this.tokEnd=this.tokStart+1;break;case";":e=s.STRUCT_SEP,this.tokEnd=this.tokStart+1;break;case"=":e=s.EQUALS,this.tokEnd=this.tokStart+1;break;case"`":case'"':e=s.QUOTED,this.tokEnd=this.scanToEndOfQuoted(this.s,this.tokStart,this.s.charAt(this.tokStart));break;default:e=s.STRING,this.tokEnd=this.scanToEndOfString(this.s,this.tokStart)}var n=this.s.substring(this.tokStart,this.tokEnd).trim();if(n.match(l)){var o=parseInt(n);this.tokens.push(new r(s.INTEGER,o,this.tokStart,this.tokEnd))}else n.match(a)?(o=parseFloat(n),this.tokens.push(new r(s.FLOAT,o,this.tokStart,this.tokEnd))):"null"===n?this.tokens.push(new r(s.NULL,null,this.tokStart,this.tokEnd)):"true"===n?this.tokens.push(new r(s.TRUE,!0,this.tokStart,this.tokEnd)):"false"===n?this.tokens.push(new r(s.FALSE,!1,this.tokStart,this.tokEnd)):this.tokens.push(new r(e,n,this.tokStart,this.tokEnd));return this.tokStart=this.tokEnd,this.tokEnd<this.s.length},e.prototype.scanToEndOfQuoted=function(e,t,n){for(var o=t+1;o<e.length;){var r=e.charAt(o),s=e.charAt(o-1);if(r===n&&"\\"!==s&&"~"!==s)break;o++}if(e.charAt(o)!==n)throw new i("Unclosed quote: "+n+" in "+this.s+" near "+t+":"+o);return o+1},e.prototype.scanToEndOfString=function(e,t){for(var n=t+1;n<e.length&&!'[]();"=`'.includes(e.charAt(n));)n++;return n},e}()},957:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ModlBoolNull=t.ModlString=t.ModlQuoted=t.ModlFloat=t.ModlInteger=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;t.Modl=function(e){this.s=e};t.ModlMap=function(e){this.items=e};t.ModlArray=function(e){this.items=e};t.ModlPair=function(e,t){this.key=e,this.value=t};t.ModlInteger=function(e){this.value=e};t.ModlFloat=function(e){this.value=e};t.ModlQuoted=function(e){this.value=e};var n;t.ModlString=function(e){this.value=e},(n=t.ModlBoolNull||(t.ModlBoolNull={}))[n.ModlTrue=0]="ModlTrue",n[n.ModlFalse=1]="ModlFalse",n[n.ModlNull=2]="ModlNull"},666:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TokenStream=void 0;var n=function(){function e(e){this.tokens=e}return e.prototype.next=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens.shift()),e},e.prototype.peek=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens[0]),e},e.prototype.pushBack=function(e){this.tokens.unshift(e)},e.prototype.empty=function(){return 0===this.tokens.length},e}();t.TokenStream=n},927:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parser=t.TokeniserException=t.ParserException=t.ModlBoolNull=t.ModlString=t.ModlFloat=t.ModlInteger=t.ModlQuoted=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;var o=n(957);Object.defineProperty(t,"Modl",{enumerable:!0,get:function(){return o.Modl}}),Object.defineProperty(t,"ModlArray",{enumerable:!0,get:function(){return o.ModlArray}}),Object.defineProperty(t,"ModlBoolNull",{enumerable:!0,get:function(){return o.ModlBoolNull}}),Object.defineProperty(t,"ModlFloat",{enumerable:!0,get:function(){return o.ModlFloat}}),Object.defineProperty(t,"ModlInteger",{enumerable:!0,get:function(){return o.ModlInteger}}),Object.defineProperty(t,"ModlMap",{enumerable:!0,get:function(){return o.ModlMap}}),Object.defineProperty(t,"ModlPair",{enumerable:!0,get:function(){return o.ModlPair}}),Object.defineProperty(t,"ModlQuoted",{enumerable:!0,get:function(){return o.ModlQuoted}}),Object.defineProperty(t,"ModlString",{enumerable:!0,get:function(){return o.ModlString}});var r=n(235);Object.defineProperty(t,"ParserException",{enumerable:!0,get:function(){return r.ParserException}});var i=n(62);Object.defineProperty(t,"TokeniserException",{enumerable:!0,get:function(){return i.TokeniserException}}),t.parser=r.parseModl},143:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Interpreter=void 0;const o=n(927),r=n(861);t.Interpreter=class{interpretToJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t)}interpretToPrettyJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t,void 0,4)}interpretToJsonObject(e){const t=this.interpret(e);return r.modlToJson(t)}interpret(e){return o.parser(e)}}},861:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.modlToJson=void 0;const o=n(927),r=n(200);function i(e){return e instanceof o.ModlArray?u(e):e instanceof o.ModlMap?a(e,{}):e instanceof o.ModlPair?l(e,{}):e instanceof o.ModlQuoted?s.replace(p(e.value)):e instanceof o.ModlInteger||e instanceof o.ModlFloat?e.value:e instanceof o.ModlString?s.replace(p(e.value)):e!==o.ModlBoolNull.ModlFalse&&(e===o.ModlBoolNull.ModlTrue||(e===o.ModlBoolNull.ModlNull?null:e))}t.modlToJson=function(e){if(e.s instanceof Array){if(1===e.s.length&&e.s[0]instanceof o.ModlArray)return u(e.s[0]);{const t={};return e.s.forEach((e=>{if(e instanceof o.ModlPair&&l(e,t),e instanceof o.ModlMap&&a(e,t),e instanceof o.ModlArray)throw new Error("Array cannot be stored directly in a map, it must be a pair")})),0===Object.keys(t).length?null:t}}return i(e.s)};const s=r.createStringEscapeReplacer();function l(e,t){return t[s.replace(e.key instanceof o.ModlQuoted?p(e.key.value):p(e.key))]=i(e.value),t}function a(e,t){return e.items.forEach((e=>{l(e,t)})),t}function u(e){const t=new Array;return e.items.forEach((e=>t.push(i(e)))),t}function p(e){return e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}},200:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createStringEscapeReplacer=void 0,t.createStringEscapeReplacer=()=>new n;class n{replace(e){let t=r(e);for(let e=0;e<t.length;e++)o.forEach(((n,o)=>{t.startsWith(o,e)&&(t=t.substring(0,e)+n+t.substring(e+o.length))}));return t}}const o=new Map([["\\t","\t"],["\\n","\n"],["\\b","\b"],["\\f","\f"],["\\r","\r"],["~t","\t"],["~n","\n"],["~b","\b"],["~f","\f"],["~r","\r"],["~\\","\\"],["\\\\","\\"],["~~","~"],["\\~","~"],["~(","("],["\\(","("],["~)",")"],["\\)",")"],["~[","["],["\\[","["],["~]","]"],["\\]","]"],["~;",";"],["\\;",";"],["~`","`"],["\\`","`"],['~"','"'],['\\"','"'],["~=","="],["\\=","="]]),r=e=>{let t=0,n=e;for(;t<n.length;){const e=n.indexOf("\\u",t),o=n.indexOf("~u",t);let r;if(o<0&&e<0)break;r=o<0?e:e<0?o:Math.min(e,o);const l=u(n,r+2);if(t=r+1,!i(n,r)&&l.codePoint>0){const e=String.fromCodePoint(l.codePoint);n=s(n,e,r,l.length+2)}}return n},i=(e,t)=>t>0&&("~"===e.charAt(t-1)||"\\"===e.charAt(t-1)),s=(e,t,n,o)=>{const r=e.substring(0,n),i=Math.min(e.length,n+o);return r+t+e.substring(i)},l=e=>e>=1048576&&e<=1114111||e>=65536&&e<=1048575||e>=0&&e<=55295||e>=57344&&e<=65535,a=(e,t,n)=>{let o=0;for(;o<n&&t+o<e.length;){const n=e[t+o];if(!"0123456789".includes(n)&&"abcdefABCDEF".indexOf(n)<=-1)return!1;o++}return o===n},u=(e,t)=>{if(a(e,t,6)&&"00"!==e.substring(t,t+2)){const n=p(e,t,6);if(l(n))return new c(n,6)}if(a(e,t,5)&&"00"!==e.substring(t,t+2)){const n=p(e,t,5);if(l(n))return new c(n,5)}if(a(e,t,4)){const n=p(e,t,4);if(l(n))return new c(n,4)}return new c(0,4)},p=(e,t,n)=>Number.parseInt(e.substring(t,t+n),16);class c{constructor(e,t){this.codePoint=e,this.length=t}}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.interpreter=void 0;const t=n(143);e.interpreter=new t.Interpreter})(),o})()}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MODLInterpreter=t():e.MODLInterpreter=t()}(self,(function(){return(()=>{"use strict";var e={235:function(e,t,n){var o,r=this&&this.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(t,"__esModule",{value:!0}),t.ParserException=t.parseModl=void 0;var i=n(957),s=n(62),l=n(666);t.parseModl=function(e){var t=s.tokeniser(e),n=u(new l.TokenStream(t));return new i.Modl(n)};var a=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return r(t,e),t}(Error);t.ParserException=a;var u=function(e){var t=p(e);return null!==t?t:c(e)},p=function(e){var t=null,n=e.next();switch(n.type){case s.TokenType.LPAREN:case s.TokenType.RPAREN:case s.TokenType.LBRACKET:case s.TokenType.RBRACKET:case s.TokenType.EQUALS:if(e.empty())throw new a("Unexpected token: "+n.toS());return e.pushBack(n),null;case s.TokenType.NULL:t=i.ModlBoolNull.ModlNull;break;case s.TokenType.TRUE:t=i.ModlBoolNull.ModlTrue;break;case s.TokenType.FALSE:t=i.ModlBoolNull.ModlFalse;break;case s.TokenType.QUOTED:t=new i.ModlQuoted(n.value);break;case s.TokenType.STRING:t=new i.ModlString(n.value);break;case s.TokenType.INTEGER:t=new i.ModlInteger(n.value);break;case s.TokenType.FLOAT:t=new i.ModlFloat(n.value);break;default:throw new a("Unknown token type in: "+n.toS())}if(null!==t){var o=e.peek();if(o&&o.type===s.TokenType.STRUCT_SEP)throw new a("Only one primitive is allowed at the root.");if(o&&(o.type===s.TokenType.LPAREN||o.type===s.TokenType.LBRACKET||o.type===s.TokenType.EQUALS))return e.pushBack(n),null;if(o)throw new a("Unexpected token: "+o.toS())}return t},c=function(e){for(var t=[];!e.empty();){t.push(f(e));var n=e.next();if(n&&n.type!==s.TokenType.STRUCT_SEP)throw new a("Expected ';' near "+n.toS())}return t},d=function(e){for(var t=e.next(),n=[];!e.empty();){var o=e.peek();if(o&&o.type===s.TokenType.RPAREN){e.next();break}var r=f(e);if(n.push(r),!(o=e.peek()))throw new a("Expected ')' near "+t.toS());if(o.type===s.TokenType.RPAREN){e.next();break}if(o.type===s.TokenType.STRUCT_SEP&&(e.next(),(o=e.peek())&&o.type===s.TokenType.RPAREN))throw new a("Unexpected ; before ] at "+o)}return new i.ModlMap(n)},T=function(e){for(var t=e.next(),n=[];!e.empty();){var o=e.peek();if(o&&o.type===s.TokenType.RBRACKET){e.next();break}var r=f(e);if(n.push(r),!(o=e.peek()))throw new a("Expected ']' near "+t.toS());if(o.type===s.TokenType.RBRACKET){e.next();break}if(o.type===s.TokenType.STRUCT_SEP&&(e.next(),(o=e.peek())&&o.type===s.TokenType.RBRACKET))throw new a("Unexpected ; before ] at "+o)}return new i.ModlArray(n)},f=function(e){var t=e.next();if(t.type===s.TokenType.LBRACKET)return e.pushBack(t),T(e);if(t.type===s.TokenType.LPAREN)return e.pushBack(t),d(e);if(t.type===s.TokenType.STRING||t.type===s.TokenType.QUOTED){var n=e.peek(),o=t.value;if(n&&n.type===s.TokenType.EQUALS)return e.next(),new i.ModlPair(o,y(e));if(n&&(n.type===s.TokenType.LBRACKET||n.type===s.TokenType.LPAREN))return new i.ModlPair(o,y(e));if(!n||n&&(n.type===s.TokenType.STRUCT_SEP||n.type===s.TokenType.RPAREN||n.type===s.TokenType.RBRACKET))return t.type===s.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===s.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===s.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===s.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===s.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===s.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var r=p(e);if(r)return r;throw new a("Unexpected token: '"+t.toS()+"'")},y=function(e){var t=e.next();if(t.type===s.TokenType.LBRACKET)return e.pushBack(t),T(e);if(t.type===s.TokenType.LPAREN)return e.pushBack(t),d(e);if(t.type===s.TokenType.STRING||t.type===s.TokenType.QUOTED){var n=e.peek();if(n&&n.type===s.TokenType.EQUALS)throw new a("Unexpected token: '"+t.toS()+"'");if(n&&(n.type===s.TokenType.LBRACKET||n.type===s.TokenType.LPAREN))throw new a("Unexpected token: '"+t.toS()+"'");if(!n||n&&(n.type===s.TokenType.STRUCT_SEP||n.type===s.TokenType.RPAREN||n.type===s.TokenType.RBRACKET))return t.type===s.TokenType.STRING?new i.ModlString(t.value):new i.ModlQuoted(t.value);throw new a("Unexpected token: '"+t.toS()+"'")}if(t.type===s.TokenType.INTEGER)return new i.ModlInteger(t.value);if(t.type===s.TokenType.FLOAT)return new i.ModlFloat(t.value);if(t.type===s.TokenType.NULL)return i.ModlBoolNull.ModlNull;if(t.type===s.TokenType.TRUE)return i.ModlBoolNull.ModlTrue;if(t.type===s.TokenType.FALSE)return i.ModlBoolNull.ModlFalse;e.pushBack(t);var o=p(e);if(o)return o;throw new a("Unexpected token: '"+t.toS()+"'")}},62:function(e,t){var n,o=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)});Object.defineProperty(t,"__esModule",{value:!0}),t.TokenType=t.TokeniserException=t.tokeniser=t.Token=void 0;var r=function(){function e(e,t,n,o){this.type=e,this.value=t,this.from=n,this.to=o}return e.prototype.toS=function(){return"type: "+this.type.toString()+", from: "+this.from+", to: "+this.to+', value: "'+this.value+'"'},e}();t.Token=r,t.tokeniser=function(e){return new u(e).parse()};var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(Error);t.TokeniserException=i;var s,l=new RegExp(/^-?\d+$/),a=new RegExp(/^-?([0-9]*[.])?[0-9]+([eE][-+]?\d+)?$/);!function(e){e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACKET="LBRACKET",e.RBRACKET="RBRACKET",e.STRUCT_SEP="STRUCT_SEP",e.NULL="NULL",e.TRUE="TRUE",e.FALSE="FALSE",e.EQUALS="EQUALS",e.QUOTED="QUOTED",e.STRING="STRING",e.INTEGER="INTEGER",e.FLOAT="FLOAT"}(s=t.TokenType||(t.TokenType={}));var u=function(){function e(e){this.s=e,this.tokStart=0,this.tokEnd=0,this.tokens=new Array}return e.prototype.parse=function(){for(;this.next(););return this.tokens},e.prototype.next=function(){for(var e,t=this.s.charAt(this.tokStart);""!=t&&" \t\r\n".includes(t);)this.tokStart++,t=this.s.charAt(this.tokStart);if(this.tokStart>=this.s.length)return!1;switch(this.s.charAt(this.tokStart)){case"(":e=s.LPAREN,this.tokEnd=this.tokStart+1;break;case")":e=s.RPAREN,this.tokEnd=this.tokStart+1;break;case"[":e=s.LBRACKET,this.tokEnd=this.tokStart+1;break;case"]":e=s.RBRACKET,this.tokEnd=this.tokStart+1;break;case";":e=s.STRUCT_SEP,this.tokEnd=this.tokStart+1;break;case"=":e=s.EQUALS,this.tokEnd=this.tokStart+1;break;case"`":case'"':e=s.QUOTED,this.tokEnd=this.scanToEndOfQuoted(this.s,this.tokStart,this.s.charAt(this.tokStart));break;default:e=s.STRING,this.tokEnd=this.scanToEndOfString(this.s,this.tokStart)}var n=this.s.substring(this.tokStart,this.tokEnd).trim();if(n.match(l)){var o=parseInt(n);this.tokens.push(new r(s.INTEGER,o,this.tokStart,this.tokEnd))}else n.match(a)?(o=parseFloat(n),this.tokens.push(new r(s.FLOAT,o,this.tokStart,this.tokEnd))):"null"===n?this.tokens.push(new r(s.NULL,null,this.tokStart,this.tokEnd)):"true"===n?this.tokens.push(new r(s.TRUE,!0,this.tokStart,this.tokEnd)):"false"===n?this.tokens.push(new r(s.FALSE,!1,this.tokStart,this.tokEnd)):this.tokens.push(new r(e,n,this.tokStart,this.tokEnd));return this.tokStart=this.tokEnd,this.tokEnd<this.s.length},e.prototype.scanToEndOfQuoted=function(e,t,n){for(var o=t+1;o<e.length;){var r=e.charAt(o),s=e.charAt(o-1);if(r===n&&"\\"!==s&&"~"!==s)break;o++}if(e.charAt(o)!==n)throw new i("Unclosed quote: "+n+" in "+this.s+" near "+t+":"+o);return o+1},e.prototype.scanToEndOfString=function(e,t){for(var n=t+1;n<e.length&&!'[]();"=`'.includes(e.charAt(n));)n++;return n},e}()},957:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ModlBoolNull=t.ModlString=t.ModlQuoted=t.ModlFloat=t.ModlInteger=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;t.Modl=function(e){this.s=e};t.ModlMap=function(e){this.items=e};t.ModlArray=function(e){this.items=e};t.ModlPair=function(e,t){this.key=e,this.value=t};t.ModlInteger=function(e){this.value=e};t.ModlFloat=function(e){this.value=e};t.ModlQuoted=function(e){this.value=e};var n;t.ModlString=function(e){this.value=e},(n=t.ModlBoolNull||(t.ModlBoolNull={}))[n.ModlTrue=0]="ModlTrue",n[n.ModlFalse=1]="ModlFalse",n[n.ModlNull=2]="ModlNull"},666:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.TokenStream=void 0;var n=function(){function e(e){this.tokens=e}return e.prototype.next=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens.shift()),e},e.prototype.peek=function(){var e=void 0;return this.tokens.length>0&&(e=this.tokens[0]),e},e.prototype.pushBack=function(e){this.tokens.unshift(e)},e.prototype.empty=function(){return 0===this.tokens.length},e}();t.TokenStream=n},927:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.parser=t.TokeniserException=t.ParserException=t.ModlBoolNull=t.ModlString=t.ModlFloat=t.ModlInteger=t.ModlQuoted=t.ModlPair=t.ModlArray=t.ModlMap=t.Modl=void 0;var o=n(957);Object.defineProperty(t,"Modl",{enumerable:!0,get:function(){return o.Modl}}),Object.defineProperty(t,"ModlArray",{enumerable:!0,get:function(){return o.ModlArray}}),Object.defineProperty(t,"ModlBoolNull",{enumerable:!0,get:function(){return o.ModlBoolNull}}),Object.defineProperty(t,"ModlFloat",{enumerable:!0,get:function(){return o.ModlFloat}}),Object.defineProperty(t,"ModlInteger",{enumerable:!0,get:function(){return o.ModlInteger}}),Object.defineProperty(t,"ModlMap",{enumerable:!0,get:function(){return o.ModlMap}}),Object.defineProperty(t,"ModlPair",{enumerable:!0,get:function(){return o.ModlPair}}),Object.defineProperty(t,"ModlQuoted",{enumerable:!0,get:function(){return o.ModlQuoted}}),Object.defineProperty(t,"ModlString",{enumerable:!0,get:function(){return o.ModlString}});var r=n(235);Object.defineProperty(t,"ParserException",{enumerable:!0,get:function(){return r.ParserException}});var i=n(62);Object.defineProperty(t,"TokeniserException",{enumerable:!0,get:function(){return i.TokeniserException}}),t.parser=r.parseModl},143:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Interpreter=void 0;const o=n(927),r=n(861);t.Interpreter=class{interpretToJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t)}interpretToPrettyJsonString(e){const t=this.interpretToJsonObject(e);return JSON.stringify(t,void 0,4)}interpretToJsonObject(e){const t=this.interpret(e);return r.modlToJson(t)}interpret(e){return o.parser(e)}}},861:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.modlToJson=void 0;const o=n(927),r=n(200);function i(e){return e instanceof o.ModlArray?u(e):e instanceof o.ModlMap?a(e,{}):e instanceof o.ModlPair?l(e,{}):e instanceof o.ModlQuoted?s.replace(p(e.value)):e instanceof o.ModlInteger||e instanceof o.ModlFloat?e.value:e instanceof o.ModlString?s.replace(p(e.value)):e!==o.ModlBoolNull.ModlFalse&&(e===o.ModlBoolNull.ModlTrue||(e===o.ModlBoolNull.ModlNull?null:e))}t.modlToJson=function(e){if(e.s instanceof Array){if(1===e.s.length&&e.s[0]instanceof o.ModlArray)return u(e.s[0]);{const t={};return e.s.forEach((e=>{if(e instanceof o.ModlPair&&l(e,t),e instanceof o.ModlMap&&a(e,t),e instanceof o.ModlArray)throw new Error("Array cannot be stored directly in a map, it must be a pair")})),0===Object.keys(t).length?null:t}}return i(e.s)};const s=r.createStringEscapeReplacer();function l(e,t){return t[s.replace(e.key instanceof o.ModlQuoted?p(e.key.value):p(e.key))]=i(e.value),t}function a(e,t){return e.items.forEach((e=>{l(e,t)})),t}function u(e){const t=new Array;return e.items.forEach((e=>t.push(i(e)))),t}function p(e){return e.startsWith("`")&&e.endsWith("`")||e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):e}},200:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createStringEscapeReplacer=void 0,t.createStringEscapeReplacer=()=>new n;class n{replace(e){let t=r(e);for(let e=0;e<t.length;e++)o.forEach(((n,o)=>{t.startsWith(o,e)&&(t=t.substring(0,e)+n+t.substring(e+o.length))}));return t}}const o=new Map([["\\t","\t"],["\\n","\n"],["\\b","\b"],["\\f","\f"],["\\r","\r"],["~t","\t"],["~n","\n"],["~b","\b"],["~f","\f"],["~r","\r"],["~\\","\\"],["\\\\","\\"],["~~","~"],["\\~","~"],["~(","("],["\\(","("],["~)",")"],["\\)",")"],["~[","["],["\\[","["],["~]","]"],["\\]","]"],["~;",";"],["\\;",";"],["~`","`"],["\\`","`"],['~"','"'],['\\"','"'],["~=","="],["\\=","="]]),r=e=>{let t=0,n=e;for(;t<n.length;){const e=n.indexOf("\\u",t),o=n.indexOf("~u",t);let r;if(o<0&&e<0)break;r=o<0?e:e<0?o:Math.min(e,o);const l=u(n,r+2);if(t=r+1,!i(n,r)&&l.codePoint>0){const e=String.fromCodePoint(l.codePoint);n=s(n,e,r,l.length+2)}}return n},i=(e,t)=>t>0&&("~"===e.charAt(t-1)||"\\"===e.charAt(t-1)),s=(e,t,n,o)=>{const r=e.substring(0,n),i=Math.min(e.length,n+o);return r+t+e.substring(i)},l=e=>e>=1048576&&e<=1114111||e>=65536&&e<=1048575||e>=0&&e<=55295||e>=57344&&e<=65535,a=(e,t,n)=>{let o=0;for(;o<n&&t+o<e.length;){const n=e[t+o];if(!"0123456789".includes(n)&&"abcdefABCDEF".indexOf(n)<=-1)return!1;o++}return o===n},u=(e,t)=>{if(a(e,t,6)&&"00"!==e.substring(t,t+2)){const n=p(e,t,6);if(l(n))return new c(n,6)}if(a(e,t,5)&&"00"!==e.substring(t,t+2)){const n=p(e,t,5);if(l(n))return new c(n,5)}if(a(e,t,4)){const n=p(e,t,4);if(l(n))return new c(n,4)}return new c(0,4)},p=(e,t,n)=>Number.parseInt(e.substring(t,t+n),16);class c{constructor(e,t){this.codePoint=e,this.length=t}}}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,n),i.exports}var o={};return(()=>{var e=o;Object.defineProperty(e,"__esModule",{value:!0}),e.interpreter=void 0;const t=n(143);e.interpreter=new t.Interpreter})(),o})()}));
{
"name": "modl-interpreter",
"version": "0.0.14",
"version": "0.0.15",
"description": "A MODL interpreter in TypeScript",

@@ -10,3 +10,3 @@ "main": "dist/index.js",

"loglevel-plugin-prefix": "^0.8.4",
"modl-parser": "^0.1.12"
"modl-parser": "^0.1.13"
},

@@ -13,0 +13,0 @@ "devDependencies": {

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