Socket
Socket
Sign inDemoInstall

@uking/marmot

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uking/marmot - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8

4

dist/index.js

@@ -6,6 +6,6 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).marmot=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}

* @namespace marmot
* @version 1.1.7
* @version 1.1.8
* @author uking [ptvile@live.com]
* @copyright uking 2024
* @license MIT
*/const t={V_IF:"v-if",V_ELSE_IF:"v-else-if",V_ELSE:"v-else",V_FOR:"v-for"},n={script:1,style:1,template:1,textarea:1,pre:1,code:1,noscript:1,noframes:1,iframe:1},s={area:1,base:1,br:1,col:1,embed:1,hr:1,img:1,input:1,link:1,meta:1,param:1,command:1,keygen:1,source:1,track:1,wbr:1,menuitem:1,frame:1},r=/\{\{(.*?)}}/g,l=["Template","Slot"],i=new Error("v-for must have source and value.");const o=(e,t,n,s,r)=>{let{s:l,v:i}=e;if(i.length)throw Error("not support dynamic value in template");return a(l[0].replace(/\s{2,}/g," ").replace(/[\r\t\n]/g,"").replace(/>(\s*)</g,"><"),t,n,s,r)};function a(e,t,r,l,o){let f="";o=o||{},l=l||{},t=t||{},r=r||{};let w=/<([A-Za-z!][A-Za-z0-9-]*)/g,$=/<([A-Z]\w*)/g,O=w.exec(e),j=null;if(O)for(;O;){if(O.index>0){f+=a(e.substring(0,O.index),t,r,l,o),e=e.substring(O.index),w.lastIndex=0,O=w.exec(e);continue}let y=O[1],_=-1,I="",S="",V=!1,F=!1;if("!--"===y){I="--\x3e",_=e.indexOf(I)+I.length,f+=e.substring(0,_),e=e.substring(_),w.lastIndex=0,O=w.exec(e);continue}"!DOCTYPE"===y?(F=!1,I=">",_=e.indexOf(I)+I.length,S=e.substring(0,_),V=!0):(_=E(e),F=/^[A-Z]/.test(y),S=e.substring(0,_),V=!!s[y]||S.endsWith("/>"),I=V?"/>":">");let k=m(S),C=c(k.if,j,r,l);if(j=C.ifCondition,C.condition){if(V)if("Slot"===y){let e=k.attrs.name?k.attrs.name.value:"default";f+=o[e]||"",o[e]=""}else if(k.for){let e=p(k.for);if(!e.sourceExp||!e.valueExp)throw i;let n=r[e.sourceExp]||x(e.sourceExp);for(let s in n){let i={};e.indexExp&&(i[e.indexExp]=d(s)),i[e.valueExp]=n[s];let a=b(k.attrs,i,l);i=Object.assign(i,a),f+=F?h(y,t,i,l,o):v(y,k.attrs,I,Object.assign(i,r),l)}}else if(F){let e=b(k.attrs,r,l);f+=h(y,t,Object.assign({},r,e),l,o)}else f+=v(y,k.attrs,I,r,l);else{let s="Template"===y,c=`</${y}>`,E=g(e.substring(_),y);if(-1===E)throw new Error(`End tag ${c} not found.`);E+=_;let m=e.substring(_,E);if(F){let e=k.attrs.slot?k.attrs.slot.value:"default",n="";if(k.for){let e=p(k.for);if(!e.sourceExp||!e.valueExp)throw i;let s=r[e.sourceExp]||x(e.sourceExp);for(let i in s){let u={};e.indexExp&&(u[e.indexExp]=d(i)),u[e.valueExp]=s[i];let f=b(k.attrs,u,l);u=Object.assign(u,f,r),n+=a(m,t,u,l,o)}}else n=a(m,t,r,l,o);if(o[e]=n,!s){let e=b(k.attrs,r,l);f+=h(y,t,Object.assign({},r,e),l,o)}}else if(1===n[y])f+=v(y,k.attrs,I,r,l),f+=u(m,r,l),f+=`</${y}>`;else if(k.for){let e=p(k.for);if(!e.sourceExp||!e.valueExp)throw i;let n=r[e.sourceExp]||x(e.sourceExp);for(let s in n){let r={};e.indexExp&&(r[e.indexExp]=d(s)),r[e.valueExp]=n[s];let i=b(k.attrs,r,l);r=Object.assign(r,i),f+=v(y,k.attrs,I,r,l),f+=a(m,t,r,l,o),f+=`</${y}>`}}else f+=v(y,k.attrs,I,r,l),f+=a(m,t,r,l,o),f+=`</${y}>`;_=E+c.length}e=e.substring(_),w.lastIndex=0,$.lastIndex=0,O=w.exec(e),!O&&e&&(f+=a(e,t,r,l,o))}else e=e.substring(_),w.lastIndex=0,O=w.exec(e)}else f+=u(e,r,l);return f}function u(e,t,n){return e.replace(r,((e,s)=>{try{return f(s,t,n)}catch(t){return e}}))}function f(e,t,n){let s={__c:n};s=Object.assign(s,t);let r=Object.keys(s),l=Object.values(s);return new Function(...r,`return ${e}`)(...l)}function c(e,n,s,r){let l=!0;if(e)if(e.name===t.V_IF)l=n=f(e.value,s,r);else if(e.name===t.V_ELSE_IF){if(null===n)throw new Error("previous node missing v-if");l=n?!n:n=f(e.value,s,r)}else{if(null===n)throw new Error("previous node missing v-if or v-else-if");l=!n}else n=null;return{ifCondition:n,condition:l}}function p(e){let t=/^\(|\)$/g,n=/,([^,}\]]*)(?:,([^,}\]]*))?$/,s=e.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/),r=null,l=null,i=null;if(s){r=s[2].trim(),l=s[1].trim().replace(t,"").trim();let e=l.match(n);e&&(l=l.replace(n,"").trim(),i=e[1].trim())}return{sourceExp:r,valueExp:l,indexExp:i}}function x(e){let t=parseInt(e);return isNaN(t)||t<1?[]:Array.from({length:t},((e,t)=>t+1))}function d(e){let t=parseInt(e);return isNaN(t)?e:t}function h(e,t,n,s,r){let l=t[e];if(!l)throw new Error(`Component ${e} not found.`);let i=new l(s),a=Object.assign({},n,i.data);return o(i.render(),i.components(),a,i.context,r)}function g(e,t){let n=new RegExp(`<${t}(?!-)`,"g"),s=new RegExp(`</${t}>`,"g"),r=new RegExp(`</${t}>`,"g"),l=s.exec(e);if(!l)return-1;for(;l;){let t=e.slice(0,l.index),i=t.match(n),o=t.match(r);if(!i&&(i=[]),!o&&(o=[]),i.length===o.length)return l.index;l=s.exec(e)}return-1}function E(e){let t=-1,n=/(\/)?>/g,s=/(")/g,r=/(')/g,l=n.exec(e);for(;l;){let i=e.substring(0,l.index+l[0].length),o=i.match(s),a=i.match(r);if(!o&&(o=[]),!a&&(a=[]),o.length%2==0&&a.length%2==0){t=l.index+l[0].length;break}l=n.exec(e)}if(-1===t)throw new Error("Invalid HTML");return t}function m(e){let n={hasExp:!1,if:null,for:null,attrs:{}},s=e.match(/([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g);for(let e=1;e<s.length;e++){let r=s[e],l=[],i=r.indexOf("=");-1===i?l.push(r):(l.push(r.substring(0,i)),l.push(r.substring(i+1)));let o=l[0],a=o===t.V_ELSE?null:!(l.length>1)||l[1].slice(1,-1);o.startsWith(":")?(!n.hasExp&&(n.hasExp=!0),n.attrs[o]={value:a,isExp:!0}):o.startsWith("v-")?o===t.V_FOR?n.for=a:n.if={name:o,value:a}:n.attrs[o]={value:a,isExp:!1}}return n}function v(e,t,n,s,r){let l=[],i=[];l.push(`<${e}`);for(let e in t)if(e.includes("class"))if(e.includes(":")){let n=t[e].value,l="class"===n?"":f(n,s,r);if("object"===typeof l)for(let e in l)l[e]&&i.push(e);else{let e=l.replace(/^\s+|\s+$/g,"").split(/\s+/g);i.push(...e)}}else{let n=t[e].value.replace(/^\s+|\s+$/g,"").split(/\s+/g);i.push(...n)}else if(e.includes(":")){let n=t[e].value;e=e.slice(1);let i=f(n,s,r);"boolean"===typeof i?i&&l.push(e):l.push(`${e}="${i}"`)}else{let n=t[e].value;"boolean"===typeof n?n&&l.push(e):l.push(`${e}="${n}"`)}return i.length&&l.push(`class="${i.join(" ")}"`),l.join(" ")+n}function b(e,t,n){let s={};for(let r in e){let l=e[r].value;r.startsWith(":")?s[r.slice(1)]=f(l,t,n):s[r]=l}return s}return e({render:o,Component:class{constructor(e={}){this.context=e||{};let t=this.constructor.name;if(l.includes(t))throw new Error(`Component ${t} is a reserved keyword.`);this.data=this.data()||{},this.data=Object.assign(this.data,this.functions()||{})}functions(){}data(){}components(){}render(){}},html:(e,...t)=>({s:e,v:t})})}));
*/const t={V_IF:"v-if",V_ELSE_IF:"v-else-if",V_ELSE:"v-else",V_FOR:"v-for"},n={script:1,style:1,template:1,textarea:1,pre:1,code:1,noscript:1,noframes:1,iframe:1},s={area:1,base:1,br:1,col:1,embed:1,hr:1,img:1,input:1,link:1,meta:1,param:1,command:1,keygen:1,source:1,track:1,wbr:1,menuitem:1,frame:1},r=/\{\{(.*?)}}/g,l=["Template","Slot"],i=new Error("v-for must have source and value.");const o=(e,t,n,s,r)=>{let{s:l,v:i}=e;if(i.length)throw Error("not support dynamic value in template");return a(l[0].replace(/\s{2,}/g," ").replace(/[\r\t\n]/g,"").replace(/>(\s*)</g,"><"),t,n,s,r)};function a(e,t,r,l,o){let f="";o=o||{},l=l||{},t=t||{},r=r||{};let w=/<([A-Za-z!][A-Za-z0-9-]*)/g,$=/<([A-Z]\w*)/g,O=w.exec(e),j=null;if(O)for(;O;){if(O.index>0){f+=a(e.substring(0,O.index),t,r,l,o),e=e.substring(O.index),w.lastIndex=0,O=w.exec(e);continue}let y=O[1],_=-1,I="",S="",V=!1,F=!1;if("!--"===y){I="--\x3e",_=e.indexOf(I)+I.length,f+=e.substring(0,_),e=e.substring(_),w.lastIndex=0,O=w.exec(e);continue}"!DOCTYPE"===y?(F=!1,I=">",_=e.indexOf(I)+I.length,S=e.substring(0,_),V=!0):(_=E(e),F=/^[A-Z]/.test(y),S=e.substring(0,_),V=!!s[y]||S.endsWith("/>"),I=V?"/>":">");let k=m(S),A=c(k.if,j,r,l);if(j=A.ifCondition,A.condition){if(V)if("Slot"===y){let e=k.attrs.name?k.attrs.name.value:"default";f+=o[e]||"",o[e]=""}else if(k.for){let e=p(k.for);if(!e.sourceExp||!e.valueExp)throw i;let n=r[e.sourceExp]||x(e.sourceExp);for(let s in n){let i={};e.indexExp&&(i[e.indexExp]=d(s)),i[e.valueExp]=n[s];let a=b(k.attrs,i,l);i=Object.assign(i,a),f+=F?h(y,t,i,l,o):v(y,k.attrs,I,Object.assign(i,r),l)}}else if(F){let e=b(k.attrs,r,l);f+=h(y,t,Object.assign({},r,e),l,o)}else f+=v(y,k.attrs,I,r,l);else{let s="Template"===y,c=`</${y}>`,E=g(e.substring(_),y);if(-1===E)throw new Error(`End tag ${c} not found.`);E+=_;let m=e.substring(_,E);if(F){let e=k.attrs.slot?k.attrs.slot.value:"default",n="";if(k.for){let e=p(k.for);if(!e.sourceExp||!e.valueExp)throw i;let s=r[e.sourceExp]||x(e.sourceExp);for(let i in s){let u={};e.indexExp&&(u[e.indexExp]=d(i)),u[e.valueExp]=s[i];let f=b(k.attrs,u,l);u=Object.assign(u,f,r),n+=a(m,t,u,l,o)}}else n=a(m,t,r,l,o);if(o[e]=n,!s){let e=b(k.attrs,r,l);f+=h(y,t,Object.assign({},r,e),l,o)}}else if(1===n[y])f+=v(y,k.attrs,I,r,l),f+=u(m,r,l),f+=`</${y}>`;else if(k.for){let e=p(k.for);if(!e.sourceExp||!e.valueExp)throw i;let n=r[e.sourceExp]||x(e.sourceExp);for(let s in n){let r={};e.indexExp&&(r[e.indexExp]=d(s)),r[e.valueExp]=n[s];let i=b(k.attrs,r,l);r=Object.assign(r,i),f+=v(y,k.attrs,I,r,l),f+=a(m,t,r,l,o),f+=`</${y}>`}}else f+=v(y,k.attrs,I,r,l),f+=a(m,t,r,l,o),f+=`</${y}>`;_=E+c.length}e=e.substring(_),w.lastIndex=0,$.lastIndex=0,O=w.exec(e),!O&&e&&(f+=a(e,t,r,l,o))}else e=e.substring(_),w.lastIndex=0,O=w.exec(e)}else f+=u(e,r,l);return f}function u(e,t,n){return e.replace(r,((e,s)=>{try{return f(s,t,n)}catch(t){return e}}))}function f(e,t,n){let s={__c:n};s=Object.assign(s,t);let r=Object.keys(s),l=Object.values(s);return new Function(...r,`return ${e}`)(...l)}function c(e,n,s,r){let l=!0;if(e)if(e.name===t.V_IF)l=n=f(e.value,s,r);else if(e.name===t.V_ELSE_IF){if(null===n)throw new Error("previous node missing v-if");l=n?!n:n=f(e.value,s,r)}else{if(null===n)throw new Error("previous node missing v-if or v-else-if");l=!n}else n=null;return{ifCondition:n,condition:l}}function p(e){let t=/^\(|\)$/g,n=/,([^,}\]]*)(?:,([^,}\]]*))?$/,s=e.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/),r=null,l=null,i=null;if(s){r=s[2].trim(),l=s[1].trim().replace(t,"").trim();let e=l.match(n);e&&(l=l.replace(n,"").trim(),i=e[1].trim())}return{sourceExp:r,valueExp:l,indexExp:i}}function x(e){let t=parseInt(e);return isNaN(t)||t<1?[]:Array.from({length:t},((e,t)=>t+1))}function d(e){let t=parseInt(e);return isNaN(t)?e:t}function h(e,t,n,s,r){let l=t[e];if(!l)throw new Error(`Component ${e} not found.`);let i=new l(s),a=Object.assign({},n,i.data);return o(i.render(),i.components(),a,i.context,r)}function g(e,t){let n=new RegExp(`<${t}(?!A-Za-z0-9-)`,"g"),s=new RegExp(`</${t}>`,"g"),r=new RegExp(`</${t}>`,"g"),l=s.exec(e);if(!l)return-1;for(;l;){let t=e.slice(0,l.index),i=t.match(n),o=t.match(r);if(!i&&(i=[]),!o&&(o=[]),i.length===o.length)return l.index;l=s.exec(e)}return-1}function E(e){let t=-1,n=/(\/)?>/g,s=/(")/g,r=/(')/g,l=n.exec(e);for(;l;){let i=e.substring(0,l.index+l[0].length),o=i.match(s),a=i.match(r);if(!o&&(o=[]),!a&&(a=[]),o.length%2==0&&a.length%2==0){t=l.index+l[0].length;break}l=n.exec(e)}if(-1===t)throw new Error("Invalid HTML");return t}function m(e){let n={hasExp:!1,if:null,for:null,attrs:{}},s=e.match(/([^\s"'<>\/=]+)(?:\s*(=)\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g);for(let e=1;e<s.length;e++){let r=s[e],l=[],i=r.indexOf("=");-1===i?l.push(r):(l.push(r.substring(0,i)),l.push(r.substring(i+1)));let o=l[0],a=o===t.V_ELSE?null:!(l.length>1)||l[1].slice(1,-1);o.startsWith(":")?(!n.hasExp&&(n.hasExp=!0),n.attrs[o]={value:a,isExp:!0}):o.startsWith("v-")?o===t.V_FOR?n.for=a:n.if={name:o,value:a}:n.attrs[o]={value:a,isExp:!1}}return n}function v(e,t,n,s,r){let l=[],i=[];l.push(`<${e}`);for(let e in t)if(e.includes("class"))if(e.includes(":")){let n=t[e].value,l="class"===n?"":f(n,s,r);if("object"===typeof l)for(let e in l)l[e]&&i.push(e);else{let e=l.replace(/^\s+|\s+$/g,"").split(/\s+/g);i.push(...e)}}else{let n=t[e].value.replace(/^\s+|\s+$/g,"").split(/\s+/g);i.push(...n)}else if(e.includes(":")){let n=t[e].value;e=e.slice(1);let i=f(n,s,r);"boolean"===typeof i?i&&l.push(e):l.push(`${e}="${i}"`)}else{let n=t[e].value;"boolean"===typeof n?n&&l.push(e):l.push(`${e}="${n}"`)}return i.length&&l.push(`class="${i.join(" ")}"`),l.join(" ")+n}function b(e,t,n){let s={};for(let r in e){let l=e[r].value;r.startsWith(":")?s[r.slice(1)]=f(l,t,n):s[r]=l}return s}return e({render:o,Component:class{constructor(e={}){this.context=e||{};let t=this.constructor.name;if(l.includes(t))throw new Error(`Component ${t} is a reserved keyword.`);this.data=this.data()||{},this.data=Object.assign(this.data,this.functions()||{})}functions(){}data(){}components(){}render(){}},html:(e,...t)=>({s:e,v:t})})}));
{
"name": "@uking/marmot",
"version": "1.1.7",
"version": "1.1.8",
"description": "A lightweight and fast javascript native template rendering engine that supports browsers, FibJS and NodeJS.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/An-uking/marmot.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