New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deshijs

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deshijs - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

2

dist/deshijs.js

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

let i=new class{getRef(e){return void 0===this.refs[e]?this.refs[e]:null}registerRef(e,t){this.refs[e]=t}handleSuspense(e){let t=e.getAttribute("$suspense"),r=e.querySelector("[placeholder]"),n=e.querySelector("[content]");r&&n&&(this.watch(t,()=>{$[t]?(r.style.display="none",n.style.display=""):(r.style.display="",n.style.display="none")}),$[t]?(r.style.display="none",n.style.display=""):(r.style.display="",n.style.display="none"))}filters={currency(e){return"number"==typeof e?"$"+e.toFixed(2):e},uppercase(e){return"string"==typeof e?e.toUpperCase():e},lowercase(e){return"string"==typeof e?e.toLowerCase():e},titlecase(e){return"string"==typeof e?e.toLowerCase().replace(/\b(\w)/g,e=>e.toUpperCase()):e},capitalize(e){return"string"==typeof e&&0<e.length?e.charAt(0).toUpperCase()+e.slice(1):e},date(e,t="YYYY-MM-DD"){return e instanceof Date?(t={year:"numeric",month:"2-digit",day:"2-digit",...formatOptions(t)},new Intl.DateTimeFormat("en-US",t).format(e)):e},number(e){return"number"==typeof e?e.toLocaleString():e},percent(e,t=2){return"number"==typeof e?(100*e).toFixed(t)+"%":e},json(e){try{return JSON.stringify(e,null,2)}catch{return e}},truncate(e,t=100,r="..."){return"string"==typeof e&&e.length>t?e.substring(0,t)+r:e},pluralize(e,t){return"string"!=typeof e||1===t?e:e+"s"},stripHtml(e){return"string"==typeof e?e.replace(/<\/?[^>]+>/gi,""):e},escapeHtml(e){return"string"==typeof e?e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"):e},rgbToHex(e){var t,r,n;return"string"==typeof e&&/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/.test(e)?([t,r,n]=e.match(/\d+/g).map(Number),"#"+[t,r,n].map(e=>e.toString(16).padStart(2,"0")).join("")):e},phone(e){return"string"==typeof e?e.replace(/(\d{3})(\d{3})(\d{4})/,"$1-$2-$3"):e},creditCard(e){return"string"==typeof e?e.replace(/(\d{4})(\d{4})(\d{4})(\d{4})/,"$1-$2-$3-$4"):e},bytes(e){var t,r;return"number"==typeof e?(t=["Bytes","KB","MB","GB","TB"],0===e?"0 Byte":(r=parseInt(Math.floor(Math.log(e)/Math.log(1024))),Math.round(e/Math.pow(1024,r),2)+" "+t[r])):e},timeAgo(e){var t,r;return e instanceof Date?(t=Math.floor((new Date-e)/1e3),1<(r=Math.floor(t/31536e3))?r+" years ago":1<(r=Math.floor(t/2592e3))?r+" months ago":1<(r=Math.floor(t/86400))?r+" days ago":1<(r=Math.floor(t/3600))?r+" hours ago":1<(r=Math.floor(t/60))?r+" minutes ago":Math.floor(t)+" seconds ago"):e},relativeDate(e,t=0){var r;return e instanceof Date?(r=new Date,(r=Math.floor((r-e)/864e5))<30?r+" days ago":new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(e)):e}};formatOptions(e){var t={};return e.includes("YYYY")&&(t.year="numeric"),e.includes("MM")&&(t.month="2-digit"),e.includes("DD")&&(t.day="2-digit"),t}applyFilter(e,t){e=this.filters[e];return e?e(t):t}constructor(){this.listeners={},this.refs={},this.savedKeys=new Set,this.loadState(),this.initializeDataAttributes(),this.$refs=new Proxy({},{get:(e,t)=>this.refs[t]})}components={};createComponent(e,t){this.components[e]=t}renderComponent(t,r){if(this.components[t]){let e=this.components[t];for(var[n,a]of Object.entries(r))e=e.replace(new RegExp("props\\."+n,"g"),a);return e}return""}initializeDataAttributes(){document.querySelectorAll("[\\$data]").forEach(e=>{e=e.getAttribute("$data");try{let t=JSON.parse(e);Object.keys(t).forEach(e=>{$[e]=t[e],this.makeReactive($)})}catch(e){}})}defineReactive(e,t,r){this.listeners[t]=[],Object.defineProperty(e,t,{get:()=>r,set:e=>{r=e,this.notify(t),this.savedKeys.has(t)&&this.saveState()}})}watch(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}notify(e){this.listeners[e]&&this.listeners[e].forEach(e=>e())}makeReactive(e){for(var t in e)e.hasOwnProperty(t)&&this.defineReactive(e,t,e[t])}saveState(){try{let t={};this.savedKeys.forEach(e=>{$.hasOwnProperty(e)&&(t[e]=$[e])}),localStorage.setItem("reactiveState",JSON.stringify(t))}catch(e){}}loadState(){try{var e=localStorage.getItem("reactiveState");if(e){let t=JSON.parse(e);Object.keys(t).forEach(e=>{$.hasOwnProperty(e)&&($[e]=t[e])})}}catch(e){}}};function r(){var e;i.makeReactive($),document.querySelectorAll("[createApp]").forEach(e=>{var t=e.getAttribute("createApp");i.createComponent(t,e.innerHTML),e.remove()}),document.body.innerHTML=document.body.innerHTML.replace(/<([a-z]+-[a-z]+)([^>]*)><\/\1>/g,(e,t,r)=>{r=Object.fromEntries(r.match(/\w+="[^"]*"/g)?.map(e=>{var[e,t]=e.split("=");return[e,t.slice(1,-1)]})||[]);return i.renderComponent(t,r)}),document.querySelectorAll("[\\$if]").forEach(t=>{let e=t.getAttribute("$if");var r=t.parentNode,n=document.createComment("$if placeholder"),r=(r.insertBefore(n,t),()=>{if($[e]){t.style.display="";let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE&&null!==e.getAttribute("$else")){e.style.display="none";break}e=e.nextSibling}}else{t.style.display="none";let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE&&null!==e.getAttribute("$else")){e.style.display="";break}e=e.nextSibling}}});i.watch(e,r),r()}),document.querySelectorAll("[\\$ref]").forEach(e=>{var t=e.getAttribute("$ref");i.registerRef(t,e)}),document.querySelectorAll("[\\$suspense]").forEach(e=>{i.handleSuspense(e)}),(async()=>{var t;for(t of document.querySelectorAll("[\\$fetch]")){var e=t.getAttribute("$fetch");try{var r=await fetch(e);if(!r.ok)throw new Error("Network response was not ok: "+r.statusText);let n=await r.json();0<t.querySelectorAll("[\\$fetch-data]").length?t.querySelectorAll("[\\$fetch-data]").forEach(t=>{var e=t.getAttribute("$fetch-data");try{var r=new Function("data",`return ${e};`)(n);void 0!==r&&(t.textContent=r)}catch(e){t.textContent="Error processing data."}}):t.innerHTML=`<pre>${JSON.stringify(n,null,2)}</pre>`}catch(e){t.innerHTML="<p>Error fetching data. Please try again later.</p>"}}})(),document.querySelectorAll("[\\$show]").forEach(e=>{let t=e.getAttribute("$show").replace(/{|}/g,"").trim();e.style.display=$[t]?"":"none",i.watch(t,()=>{e.style.display=$[t]?"":"none"})}),document.querySelectorAll("[\\$focus]").forEach(e=>{let t=e.getAttribute("$focus");i.watch(t,()=>{$[t]&&(e.focus(),applyFocus())}),$[t]&&(e.focus(),applyFocus())}),document.querySelectorAll("[\\$toggle]").forEach(e=>{var t=e.getAttribute("$toggle");let r=e.innerHTML;i.watch(t,()=>{e.innerHTML=$.contentVisible?r:""}),e.innerHTML=$.contentVisible?r:""}),(e=["click","input","change","mouseover","mousemove","mouseout","keydown","keyup","mousedown","mouseup","dblclick","focus","blur","contextmenu","drag","drop","scroll","resize","touchstart","touchmove","touchend","paste","copy","cut","error","load","submit","animationstart","animationend","animationiteration","transitionend","hashchange","beforeunload","fullscreenchange","message","canplay","canplaythrough","durationchange","emptied","ended","invalid","progress","ratechange","waiting","volumechange","wheel","focusin","focusout","pointerenter","pointerleave","touchcancel"]).forEach(t=>{document.querySelectorAll(`[on\\:${t}]`).forEach(e=>{let r=e.getAttribute("on:"+t);r&&e.addEventListener(t,e=>{try{var t=new Function("event, reactive","with(this) { return "+r+" }").bind(window)(e,i);"function"==typeof t&&t()}catch(e){}})})}),e.forEach(t=>{document.querySelectorAll(`[\\@${t}]`).forEach(e=>{let r=e.getAttribute("@"+t);r&&e.addEventListener(t,e=>{try{var t=new Function("event, reactive","with(this) { return "+r+" }").call(window,e,i);"function"==typeof t&&t()}catch(e){}})})}),document.querySelectorAll("[\\$text]").forEach(t=>{let r=t.getAttribute("$text"),n=()=>{var e=r.replace(/\{(.+?)\}/g,(e,t)=>{try{return new Function("with(this) { return "+t+" }").bind($)()}catch(e){return""}});t.innerText=e};n(),r.match(/\b\w+\b/g).forEach(e=>{$.hasOwnProperty(e)&&i.watch(e,n)})}),document.querySelectorAll("[src]").forEach(t=>{var r=t.getAttribute("src"),e=r.match(/\{(.+?)\}/);if(r.startsWith("{")&&r.endsWith("}")){let e=r.slice(1,-1);i.watch(e,()=>{t.src=$[e]}),t.src=$[e]}else if(e)try{var n=new Function("with(this) { return "+e[1]+" }").bind($);t.src=n()}catch(e){}}),document.querySelectorAll("[\\$delay]").forEach(e=>{let t=parseInt(e.getAttribute("$delay"),10),r=e.getAttribute("on:click");"function"==typeof window[r]&&e.addEventListener("click",()=>{setTimeout(()=>{window[r]()},t)})}),document.querySelectorAll("[\\$bind]").forEach(n=>{n.getAttribute("$bind").split(",").forEach(e=>{let[t,r]=e.split(":");i.watch(r,()=>{n.setAttribute(t,$[r])}),n.setAttribute(t,$[r])})}),document.querySelectorAll("[\\$save]").forEach(e=>{e=e.getAttribute("$save").replace(/{|}/g,"").trim();$.hasOwnProperty(e)&&(i.savedKeys.add(e),i.saveState())}),document.querySelectorAll("[\\$model]").forEach(e=>{let t=e.getAttribute("$model");e.addEventListener("input",e=>{$[t]=e.target.value}),i.watch(t,()=>{e.value=$[t]}),e.value=$[t]}),document.querySelectorAll("[\\$class]").forEach(n=>{n.getAttribute("$class").split(",").forEach(e=>{let[t,r]=e.split(":");i.watch(r,()=>{$[r]?n.classList.add(t):n.classList.remove(t)}),$[r]?n.classList.add(t):n.classList.remove(t)})}),document.querySelectorAll("[\\$style]").forEach(n=>{n.getAttribute("$style").split(",").forEach(e=>{let[t,r]=e.split(":");i.watch(r,()=>{n.style[t]=$[r]}),n.style[t]=$[r]})}),document.querySelectorAll("[\\$attr]").forEach(n=>{n.getAttribute("$attr").split(",").forEach(e=>{let[t,r]=e.split(":");i.watch(r,()=>{n.setAttribute(t,$[r])}),n.setAttribute(t,$[r])})}),document.querySelectorAll("[\\$for]").forEach(r=>{let[n,t]=r.getAttribute("$for").split(" in "),a=r.parentNode,o=document.createComment("$for placeholder");a.insertBefore(o,r),r.remove();var e=()=>{for(var e=$[t];o.nextSibling&&o.nextSibling!==r;)o.nextSibling.remove();e.forEach(e=>{var t=r.cloneNode(!0);t.innerHTML=t.innerHTML.replace(new RegExp(`{${n}}`,"g"),e),a.insertBefore(t,o.nextSibling)})};i.watch(t,e),e()}),document.querySelectorAll("[\\$format]").forEach(t=>{let r=t.getAttribute("$text"),n=t.getAttribute("$format"),a=()=>{var e=r.replace(/\{(.+?)\}/g,(e,t)=>{try{var r=new Function("with(this) { return "+t+" }").bind($)();return i.applyFilter(n,r)}catch(e){return""}});t.innerText=e};a(),r.match(/\b\w+\b/g).forEach(e=>{$.hasOwnProperty(e)&&i.watch(e,a)})}),document.querySelectorAll("[\\$html]").forEach(e=>{let t=e.getAttribute("$html");var r=()=>{e.innerHTML=$[t]};i.watch(t,r),r()})}window.$refs=i.$refs,window.$=new Proxy({},{get(e,t){return e[t]},set(e,t,r){return e[t]=r,i.notify(t),!0}}),document.addEventListener("DOMContentLoaded",()=>{var e,t;e=document.getElementById("root"),t=document.querySelector("[app]"),e.innerHTML=t.innerHTML,t.remove(),r()});
class Deshi{constructor(){this.t={},this.listeners={},this.i={},this.o=new Set,this.u=new Proxy({},{get:(t,e)=>this.i[e]}),this.filters={l:t=>`$${t.toFixed(2)}`,h:t=>t.toUpperCase(),m:t=>t.toLowerCase(),$:t=>t.toLowerCase().replace(/\b(\w)/g,(t=>t.toUpperCase())),p:t=>t.charAt(0).toUpperCase()+t.slice(1),v:(t,e="YYYY-MM-DD")=>{const n={M:"numeric",D:"2-digit",T:"2-digit",...this.H(e)};return new Intl.DateTimeFormat("en-US",n).format(t)},number:t=>t.toLocaleString(),percent:(t,e=2)=>`${(100*t).toFixed(e)}%`,json:t=>JSON.stringify(t,null,2),truncate:(t,e=100,n="...")=>t.length>e?t.substring(0,e)+n:t,L:(t,e)=>1===e?t:`${t}s`,S:t=>t.replace(/<\/?[^>]+>/gi,""),B:t=>t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;"),k:t=>{const e=t.match(/^rgb$$(\d+),\s*(\d+),\s*(\d+)$$$/);return e?`#${e.slice(1).map((t=>parseInt(t).toString(16).padStart(2,"0"))).join("")}`:t},phone:t=>t.replace(/(\d{3})(\d{3})(\d{4})/,"$1-$2-$3"),F:t=>t.replace(/(\d{4})(\d{4})(\d{4})(\d{4})/,"$1-$2-$3-$4"),R:t=>{if(0===t)return"0 Byte";const e=parseInt(Math.floor(Math.log(t)/Math.log(1024)).toString());return Math.round(t/Math.pow(1024,e))+" "+["Bytes","KB","MB","GB","TB"][e]},C:t=>{const e=Math.floor(((new Date).getTime()-t.getTime())/1e3),n=[{label:"year",I:31536e3},{label:"month",I:2592e3},{label:"day",I:86400},{label:"hour",I:3600},{label:"minute",I:60},{label:"second",I:1}];for(let t=0;t<n.length;t++){const i=Math.floor(e/n[t].I);if(i>1)return`${i} ${n[t].label}s ago`}return"just now"},Y:t=>{const e=(new Date).getTime()-t.getTime(),n=Math.floor(e/864e5);return n<30?`${n} days ago`:new Intl.DateTimeFormat("en-US",{D:"short",T:"numeric",M:"numeric"}).format(t)}},this.O()}N(t,e){this.t[t]=e}j(t,e){this.t[t]=t=>e(t)}J(t){const e={};for(const n of t.attributes)e[n.name]=n.value;return e}P(t,e){return this.t[t]?this.t[t](e):(console.warn(`Component '${t}' not found.`),"")}H(t){const e={};return t.includes("YYYY")&&(e.M="numeric"),t.includes("MM")&&(e.D="2-digit"),t.includes("DD")&&(e.T="2-digit"),e}A(t){return void 0!==this.i[t]?this.i[t]:(console.warn(`Ref '${t}' not found.`),null)}U(t,e){this.i[t]=e}q(t){const e=t.getAttribute("$suspense");if(!e)return;const n=t.querySelector("[placeholder]"),i=t.querySelector("[content]");n instanceof HTMLElement&&i instanceof HTMLElement?(this.watch(e,(()=>{window.signal[e]?(n.style.display="none",i.style.display=""):(n.style.display="",i.style.display="none")})),window.signal[e]?(n.style.display="none",i.style.display=""):(n.style.display="",i.style.display="none")):console.warn("Missing data-suspense-placeholder or data-suspense-content attribute in $suspense element.")}G(t,e){const n=this.filters[t];return n?n(e):(console.warn(`Filter '${t}' is not defined.`),e)}K(t,e,n){this.listeners[e]=[],Object.defineProperty(t,e,{get:()=>n,set:t=>{n=t,this.notify(e),this.o.has(e)&&this.V()}})}watch(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)}notify(t){this.listeners[t]&&this.listeners[t].forEach((t=>t()))}W(t){for(const e in t)t.hasOwnProperty(e)&&this.K(t,e,t[e])}V(){try{const t={};this.o.forEach((e=>{window.signal.hasOwnProperty(e)&&(t[e]=window.signal[e])})),localStorage.setItem("reactiveState",JSON.stringify(t))}catch(t){console.error("Error saving state to localStorage:",t)}}O(){try{const t=localStorage.getItem("reactiveState");if(t){const e=JSON.parse(t);Object.keys(e).forEach((t=>{window.signal.hasOwnProperty(t)&&(window.signal[t]=e[t])}))}}catch(t){console.error("Error loading state from localStorage:",t)}}X(){this.W(window.signal),this.Z(),this._(),this.tt()}Z(){this.et(),this.nt(),this.it(),this.ot(),this.st(),this.rt(),this.ct(),this.ut(),this.dt(),this.lt(),this.ht(),this.wt(),this.ft()}ft(){document.querySelectorAll("*").forEach((t=>{const e=t.tagName.toLowerCase();if(this.t[e]){const n=this.J(t);t.innerHTML=this.P(e,n)}}))}et(){document.querySelectorAll("[\\$if]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$if");if(!e)return;const n=t.parentNode,i=document.createComment("$if placeholder");n?.insertBefore(i,t);const o=()=>{if(window.signal[e]){t.style.display="";let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE&&e instanceof HTMLElement&&null!==e.getAttribute("$else")){e.style.display="none";break}e=e.nextSibling}}else{t.style.display="none";let e=t.nextSibling;for(;e;){if(e.nodeType===Node.ELEMENT_NODE&&e instanceof HTMLElement&&null!==e.getAttribute("$else")){e.style.display="";break}e=e.nextSibling}}};this.watch(e,o),o()}))}nt(){document.querySelectorAll("[\\$ref]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$ref");e&&this.U(e,t)}))}it(){document.querySelectorAll("[\\$suspense]").forEach((t=>{t instanceof HTMLElement&&this.q(t)}))}ot(){document.querySelectorAll("[\\$show]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$show");if(!e)return;const n=e.replace(/{|}/g,"").trim();t.style.display=window.signal[n]?"":"none",this.watch(n,(()=>{t.style.display=window.signal[n]?"":"none"}))}))}st(){document.querySelectorAll("[\\$focus]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$focus");e&&(this.watch(e,(()=>{window.signal[e]&&t.focus()})),window.signal[e]&&t.focus())}))}rt(){document.querySelectorAll("[\\$toggle]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$toggle");if(!e)return;const n=t.innerHTML;this.watch(e,(()=>{t.innerHTML=window.signal.contentVisible?n:""})),t.innerHTML=window.signal.contentVisible?n:""}))}ct(){document.querySelectorAll("[\\$for]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$for");if(!e)return;const[n,i]=e.split(" in "),o=t.parentNode,s=document.createComment("$for placeholder");o?.insertBefore(s,t),t.remove();const r=()=>{const e=window.signal[i];for(;s.nextSibling&&s.nextSibling!==t;)s.nextSibling.remove();e.forEach((e=>{const i=t.cloneNode(!0);i.innerHTML=i.innerHTML.replace(new RegExp(`{${n}}`,"g"),e),o?.insertBefore(i,s.nextSibling)}))};this.watch(i,r),r()}))}ut(){document.querySelectorAll("[\\$model]").forEach((t=>{if(!(t instanceof HTMLInputElement))return;const e=t.getAttribute("$model");e&&(t.addEventListener("input",(t=>{window.signal[e]=t.target.value})),this.watch(e,(()=>{t.value=window.signal[e]})),t.value=window.signal[e])}))}dt(){document.querySelectorAll("[\\$class]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$class")?.split(",");e&&e.forEach((e=>{const[n,i]=e.split(":");this.watch(i,(()=>{window.signal[i]?t.classList.add(n):t.classList.remove(n)})),window.signal[i]?t.classList.add(n):t.classList.remove(n)}))}))}lt(){document.querySelectorAll("[\\$style]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$style")?.split(",");e&&e.forEach((e=>{const[n,i]=e.split(":");this.watch(i,(()=>{t.style[n]=window.signal[i]})),t.style[n]=window.signal[i]}))}))}ht(){document.querySelectorAll("[\\$attr]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$attr")?.split(",");e&&e.forEach((e=>{const[n,i]=e.split(":");this.watch(i,(()=>{t.setAttribute(n,window.signal[i])})),t.setAttribute(n,window.signal[i])}))}))}wt(){document.querySelectorAll("[\\$html]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$html");if(!e)return;const n=()=>{t.innerHTML=window.signal[e]};this.watch(e,n),n()}))}_(){const t=["click","input","change","mouseover","mousemove","mouseout","keydown","keyup","mousedown","mouseup","dblclick","focus","blur","contextmenu","drag","drop","scroll","resize","touchstart","touchmove","touchend","paste","copy","cut","error","load","submit","animationstart","animationend","animationiteration","transitionend","hashchange","beforeunload","fullscreenchange","message","canplay","canplaythrough","durationchange","emptied","ended","invalid","progress","ratechange","waiting","volumechange","wheel","focusin","focusout","pointerenter","pointerleave","touchcancel"];t.forEach((t=>{document.querySelectorAll(`[on\\:${t}]`).forEach((e=>{const n=e.getAttribute(`on:${t}`);n&&e.addEventListener(t,(e=>{try{const t=new Function("event, reactive","with(this) { return "+n+" }").bind(window)(e,reactive);"function"==typeof t&&t()}catch(e){console.error(`Error executing handler '${n}' for event '${t}':`,e)}}))}))})),t.forEach((t=>{document.querySelectorAll(`[\\@${t}]`).forEach((e=>{if(!(e instanceof HTMLElement))return;const n=e.getAttribute(`@${t}`);n&&e.addEventListener(t,(e=>{try{let t=n.trim();t.startsWith("() =>")&&(t=t.replace(/^$$$$\s*=>\s*{?/,"").replace(/}$/,"")),new Function("event, $",`with($) { ${t} }`)(e,window.signal)}catch(e){console.error(`Error executing handler '${n}' for event '${t}':`,e)}}))}))}))}tt(){this.$t(),this.gt(),this.vt(),this.Mt(),this.yt(),this.Et()}$t(){document.querySelectorAll("[\\$text]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$text");if(!e)return;const n=()=>{const n=e.replace(/\{(.+?)\}/g,((t,e)=>{try{return new Function("with(this) { return "+e+" }").bind(window.signal)()}catch(t){return console.error("Error evaluating expression:",e,t),""}}));t.textContent=n};n();const i=e.match(/\b\w+\b/g);i?.forEach((t=>{window.signal.hasOwnProperty(t)&&this.watch(t,n)}))}))}gt(){document.querySelectorAll("[src]").forEach((t=>{if(!(t instanceof HTMLImageElement))return;const e=t.getAttribute("src");if(!e)return;const n=e.match(/\{(.+?)\}/);if(e.startsWith("{")&&e.endsWith("}")){const n=e.slice(1,-1);this.watch(n,(()=>{t.src=window.signal[n]})),t.src=window.signal[n]}else if(n)try{const e=new Function("with(this) { return "+n[1]+" }").bind(window.signal);t.src=e()}catch(t){console.error("Error evaluating expression:",n[1],t)}}))}vt(){document.querySelectorAll("[\\$delay]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=parseInt(t.getAttribute("$delay")||"0",10),n=t.getAttribute("on:click");"function"==typeof window[n]&&t.addEventListener("click",(()=>{setTimeout((()=>{window[n]()}),e)}))}))}Mt(){document.querySelectorAll("[\\$bind]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$bind")?.split(",");e&&e.forEach((e=>{const[n,i]=e.split(":");this.watch(i,(()=>{t.setAttribute(n,window.signal[i])})),t.setAttribute(n,window.signal[i])}))}))}yt(){document.querySelectorAll("[\\$save]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$save")?.replace(/{|}/g,"").trim();e&&window.signal.hasOwnProperty(e)?(this.o.add(e),this.V()):console.warn(`State key '${e}' not found.`)}))}Et(){document.querySelectorAll("[\\$format]").forEach((t=>{if(!(t instanceof HTMLElement))return;const e=t.getAttribute("$text"),n=t.getAttribute("$format");if(!e||!n)return;const i=()=>{const i=e.replace(/\{(.+?)\}/g,((t,e)=>{try{let t=new Function("with(this) { return "+e+" }").bind(window.signal)();return this.G(n,t)}catch(t){return console.error("Error evaluating expression:",e,t),""}}));t.textContent=i};i();const o=e.match(/\b\w+\b/g);o?.forEach((t=>{window.signal.hasOwnProperty(t)&&this.watch(t,i)}))}))}static init(){const t=new Deshi;return window.u=t.u,window.signal=new Proxy({},{get:(t,e)=>t[e],set:(e,n,i)=>(e[n]=i,t.notify(n),!0)}),window.j=t.j.bind(t),document.addEventListener("DOMContentLoaded",(()=>{t.Dt()})),t}Dt(){const t=document.getElementById("root"),e=document.querySelector("[app]");if(t&&e){let n=e.innerHTML;n=n.replace(/<([a-z-]+)><\/\1>/g,((t,e)=>this.P(e))),t.innerHTML=n,e.remove(),this.X()}else console.error("Root element or app template not found")}}export default Deshi;

@@ -7,7 +7,7 @@ {

],
"version": "1.0.2",
"version": "1.0.3",
"author": "Nazmul Hossain",
"dependencies": {
"deshijs": "^1.0.2"
"deshijs": "^1.0.3"
}
}
<div align="center">
<img src="https://i.postimg.cc/Pq1ZWCg3/Black-and-White-Initial-D-Creative-Studio-Logo.png" alt="DeshiJS Logo" height="150" />
<h1>DeshiJS</h1>

@@ -30,3 +29,3 @@ <p>A smooth, minimal framework for infusing JavaScript with dynamic behavior.</p>

<button
$text="{$.counter} {$.counter <= 1 ? 'time' : 'times'}"
$text="{counter} {counter <= 1 ? 'time' : 'times'}"
@click="incrementCounter"

@@ -37,9 +36,8 @@ ></button>

<script>
const $ = {
signal = {
counter: 0,
incrementCounter: function () {
this.counter++;
},
};
function incrementCounter() {
$.counter++;
}
</script>

@@ -46,0 +44,0 @@ ```

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