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

@uking/marmot

Package Overview
Dependencies
Maintainers
1
Versions
23
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.0 to 1.1.1

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.0.9
* @version 1.1.0
* @author uking [ptvile@live.com]
* @copyright uking 2024
* @license MIT
*/const t=["Template","Slot"];const n=/<([A-Z]\w*)/g,s=(e,t,n)=>{let{strings:s,values:r}=e;return s?o(s,r,t,n):""};function o(e,t,s,c){let u=e.slice(0),f="";for(c=c||{};u.length;){let e=u[0].match(n);if(e)for(let n=0;n<e.length;n++){if(u[0]=u[0].replace(/\n\s+/g,""),!u[0])continue;let a=e[n].replace("<",""),p=u[0].indexOf(e[n]);f+=u[0].substring(0,p),u[0]=u[0].substring(p+e[n].length);let d=-1,{props:g,currentIndex:m,endTagPosition:h,isCloseTag:x}=i(u,t);if(x){d=h+2,"Slot"===a?g.name?(f+=c[g.name]||"",c[g.name]=""):(f+=c.default||"",c.default=""):f+=r(a,s,g,c)}else{u[m]=u[m].substring(h+1),u.splice(0,m),t.splice(0,m);let e=`</${a}>`,{index:i,offset:p,length:x}=l(e,u),b=u.slice(0,i+1),w=t.slice(0,i);b[i]=b[i].substring(0,p),m=i,d=p+e.length,c[g.slot||"default"]=o(b,w,s,c),"Template"!==a&&(f+=r(a,s,g,c)),n+=x}u[m]=u[m].substring(d),u.splice(0,m),t.splice(0,m)}else u[0]=u[0].replace(/\n\s+/g,""),f+=u[0],u.splice(0,1),t[0]&&(Array.isArray(t[0])?f+=t[0].join(""):f+=t[0],t.splice(0,1))}return f}function r(e,t,n,o){let r=t[e];if(!r)throw new Error(`Component ${e} not found.`);let l=new r;return s(l.render(n),l.components(),o)}function l(e,t){let s=t.length,o="</Template>"===e,r=[],l=-1,i=0,c=-1;for(let u=0;u<s;u++){let s=t[u];l=s.indexOf(e);let f=l>-1,a=s;if(f&&(c=u,a=s.substring(0,l)),o){let e=a.match(n);e&&(r.push(...e),i=r.length)}if(f)break}return{index:c,offset:l,length:i}}function i(e,t){const n=e.length;let s={},o=-1,r=-1,l=!1;for(let i=0;i<n;i++){let n=e[i].replace(/\n\s+/g,""),a=new RegExp("(/)?>","g").exec(n);if(a){l="/>"===a[0];let e=a.index;n=n.substring(0,e),s=f(n,s),s=c(n,s),o=i,r=a.index;break}{s=f(n,s),s=c(n,s);let e=u(n);e&&!s[e]&&(s[e]=t[i])}}return{props:s,currentIndex:o,endTagPosition:r,isCloseTag:l}}function c(e,t={}){const n=/([\w-]+)\s*=\s*(['"])(.*?)\2/g;let s;for(;s=n.exec(e);){const[,e,,n]=s;t[e]=n}return t}function u(e){let t=/([\w-]+)\s*=['"]$/g.exec(e);return t?t[1]:null}function f(e,t={}){const n=/(^|\s)(\w+)(?=\s|$)/g;let s;for(;s=n.exec(e);){const[,,e]=s;t[e]=!0}return t}return e({render:s,Component:class{constructor(e){this.props=e;let n=this.constructor.name;if(t.includes(n))throw new Error(`Component ${n} is a reserved keyword and cannot be used as a component name.`)}components(){}render(e={}){}},html:(e,...t)=>({strings:e,values:t})})}));
*/const t=/<([A-Z]\w*)/g,n=(e,t,n)=>{let{strings:s,values:l}=e;return s?r(s,l,t,n):""};function r(e,n,i,c){let u=e.slice(0);e=[];let f="";for(i=i||{},c=c||{};u.length;){let e=u[0].match(t);if(e)for(let t=0;t<e.length;t++){if(u[0]=u[0].replace(/\n\s+/g,""),!u[0])continue;let a=e[t].replace("<",""),p=u[0].indexOf(e[t]);f+=u[0].substring(0,p),u[0]=u[0].substring(p+e[t].length);let d=-1,{props:g,currentIndex:h,endTagPosition:m,isCloseTag:x}=o(u,n);if(x)d=m+2,"Slot"===a?g.name?(f+=c[g.name]||"",c[g.name]=""):(f+=c.default||"",c.default=""):f+=s(a,i,g,c);else{u[h]=u[h].substring(m+1),u.splice(0,h),n.splice(0,h);let e=`</${a}>`,{index:o,offset:p,length:x}=l(e,u),b=u.slice(0,o+1),w=n.slice(0,o);b[o]=b[o].substring(0,p),h=o,d=p+e.length,c[g.slot||"default"]=r(b,w,i,c),"Template"!==a&&(f+=s(a,i,g,c)),t+=x}u[h]=u[h].substring(d),u.splice(0,h),n.splice(0,h)}else u[0]=u[0].replace(/\n\s+/g,""),f+=u[0],n[0]&&(Array.isArray(n[0])?f+=n[0].join(""):f+=n[0]),u.splice(0,1),n.splice(0,1)}return f}function s(e,t,r,s){let l=t[e];if(!l)throw new Error(`Component ${e} not found.`);let o=new l;return n(o.render(r),o.components(),s)}function l(e,n){let r=n.length,s="</Template>"===e,l=[],o=-1,i=0,c=-1;for(let u=0;u<r;u++){let r=n[u];o=r.indexOf(e);let f=o>-1,a=r;if(f&&(c=u,a=r.substring(0,o)),s){let e=a.match(t);e&&(l.push(...e),i=l.length)}if(f)break}return{index:c,offset:o,length:i}}function o(e,t){const n=e.length;let r={},s=-1,l=-1,o=!1;for(let f=0;f<n;f++){let n=e[f].replace(/\n\s+/g,""),a=new RegExp("(/)?>","g").exec(n);if(a){o="/>"===a[0];let e=a.index;n=n.substring(0,e),r=u(n,r),r=i(n,r),s=f,l=a.index;break}{r=u(n,r),r=i(n,r);let e=c(n);e&&!r[e]&&(r[e]=t[f])}}return{props:r,currentIndex:s,endTagPosition:l,isCloseTag:o}}function i(e,t={}){const n=/([\w-]+)\s*=\s*(['"])(.*?)\2/g;let r;for(;r=n.exec(e);){const[,e,,n]=r;t[e]=n}return t}function c(e){let t=/([\w-]+)\s*=['"]$/g.exec(e);return t?t[1]:null}function u(e,t={}){const n=/(^|\s)(\w+)(?=\s|$)/g;let r;for(;r=n.exec(e);){const[,,e]=r;t[e]=!0}return t}return e({render:n,Component:class{constructor(e){this.props=e;let t=this.constructor.name;if(["Template","Slot"].includes(t))throw new Error(`Component ${t} is a reserved keyword.`)}components(){}render(e={}){}},html:(e,...t)=>({strings:e,values:t})})}));
{
"name": "@uking/marmot",
"version": "1.1.0",
"version": "1.1.1",
"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",

@@ -5,3 +5,3 @@ /**

* @namespace marmot
* @version 1.1.0
* @version 1.1.1
* @author uking [ptvile@live.com]

@@ -12,3 +12,3 @@ * @copyright uking 2024

const html = (strings, ...values) => ({ strings, values })
const reservedKeys = ['Template', 'Slot']
// const reservedKeys = ['Template', 'Slot']

@@ -19,4 +19,4 @@ class Component {

let name = this.constructor.name
if (reservedKeys.includes(name)) {
throw new Error(`Component ${name} is a reserved keyword and cannot be used as a component name.`)
if (['Template', 'Slot'].includes(name)) {
throw new Error(`Component ${name} is a reserved keyword.`)
}

@@ -43,3 +43,5 @@

let strings = arr.slice(0)
arr = []
let html = ''
components = components || {}
slots = slots || {}

@@ -57,9 +59,17 @@ while (strings.length) {

let endTagOffset = -1
let {
props,
currentIndex,
endTagPosition,
isCloseTag
} = findComponentAttributes(strings, values)
if (!isCloseTag) {
let { props, currentIndex, endTagPosition, isCloseTag } = findComponentAttributes(strings, values)
if (isCloseTag) {
endTagOffset = endTagPosition + 2
if (componentName === 'Slot') {
if (props.name) {
html += slots[props.name] || ''
slots[props.name] = ''
} else {
html += slots.default || ''
slots['default'] = ''
}
} else
html += _renderComponent(componentName, components, props, slots)
} else {
strings[currentIndex] = strings[currentIndex].substring(endTagPosition + 1)

@@ -79,16 +89,2 @@ strings.splice(0, currentIndex)

j += length
} else {
endTagOffset = endTagPosition + 2
let isSlot = componentName === 'Slot'
if (isSlot) {
if (props.name) {
html += slots[props.name] || ''
slots[props.name] = ''
} else {
html += slots.default || ''
slots['default'] = ''
}
} else
html += _renderComponent(componentName, components, props, slots)
}

@@ -103,3 +99,2 @@ strings[currentIndex] = strings[currentIndex].substring(endTagOffset)

html += strings[0]
strings.splice(0, 1)
if (values[0]) {

@@ -111,4 +106,5 @@ if (Array.isArray(values[0])) {

}
values.splice(0, 1)
}
strings.splice(0, 1)
values.splice(0, 1)
}

@@ -136,3 +132,2 @@ }

offset = line.indexOf(componentName)
// index = i
let flag = offset > -1

@@ -139,0 +134,0 @@ let str = line

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