markuno_lib 1.1.9 → 1.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/bus_utils.js +1 -1
- package/package.json +1 -1
package/bin/bus_utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let t=1e3;function myuuid(){return t++,t}function getdim(t,e,a,i,r,n,m,o,s){let g,u=[];function getsingledim(t,e,a){return t||(t=e),e?"X"==(a=(a||"_").trim().toLowerCase())&&t!=e?t+"*":"M"==a?t+"M":t:t}return g=getsingledim(t,i,m),g&&u.push(g),g=getsingledim(e,r,o),g&&u.push(g),g=getsingledim(a,n,s),g&&u.push(g),(""+m+o+s).replace(/[_XM]/gi,""),u.join("x")}function formatDate(t){const e=new Date(t),a=e.getDate().toString().padStart(2,"0"),i=(e.getMonth()+1).toString().padStart(2,"0");return`${e.getFullYear()}-${i}-${a}`}function toDateStr(t){if(!t)return"";"number"==typeof t&&(t=t.toDate());let e=t.getDate(),a=t.getMonth()+1,i=t.getFullYear(),r=t.getHours(),n=t.getMinutes();return e=e<10?"0"+e:e,a=a<10?"0"+a:a,r=r<10?"0"+r:r,n=n<10?"0"+n:n,`${e}/${a}/${i} ${r}:${n}`}const e=new class Bus{constructor(){this.buslist={}}on(t,e){return this.buslist[t]||(this.buslist[t]=[]),this.buslist[t].push(e),this.buslist[t].length-1}emit(t,...e){this.buslist[t]&&this.buslist[t].forEach((t=>t(...e)))}off(t,e){this.buslist[t]&&("number"==typeof e?e>=0&&e<this.buslist[t].length&&this.buslist[t].splice(e,1):this.buslist[t]=this.buslist[t].filter((t=>t!==e)))}$on(t,e){this.on(t,e)}$off(t,e){this.off(t,e)}$emit(t,...e){this.emit(t,...e)}};function listfromstring(t){if(Array.isArray(t))return t;var e=[],a={};if(t){var i=t.split(/[\n;\,]/);for(var r of i){var n,m,o=r.search(/[\:=#]/);o<0?n=m=r.trim():(n=r.slice(0,o),m=r.slice(o+1)),(n=n.toLowerCase())&&!a[n]&&(a[n]=1,e.push({cod:n,des:m}))}}return e}e.messaggio=t=>e.emit("messaggio",t),e.warning=t=>e.emit("warning",t),e.errore=t=>e.emit("error",t),e.salvato=t=>e.emit("messaggio","dati memorizzati!"),e.wait=t=>e.emit("wait",t);var tonum=(t,e=-1)=>{if(!t)return 0;if("number"==typeof t)return t||0;let a=0;if("string"==typeof t){let e=(t=t.replaceAll(",",".")).match(/^-?[0-9.]+$/g);if(e&&e.length>0)a=Number(e[0]);else if(/^\s*\-?\s*[0-9]+(\.[0-9]+)?\s*$/gi.test(t))a=parseFloat(t);else if(/[\s\d\(\)\-\+\/\*\^\.]+/gi.test(t))try{a=new Function(`${baseeval} (${t})`)()}catch{a=0}}if(e>=0){const t=Math.pow(10,e);a=Math.round(a*t)/t}return a||0},toEuro=(t,e,a="")=>0==t?e||"":new Intl.NumberFormat("it-IT",{style:"currency",currency:"EUR"}).format(tonum(t))+a;
|
|
1
|
+
let t=1e3;function myuuid(){return t++,t}function getdim(t,e,a,i,r,n,m,o,s){let g,u=[];function getsingledim(t,e,a){return t||(t=e),e?"X"==(a=(a||"_").trim().toLowerCase())&&t!=e?t+"*":"M"==a?t+"M":t:t}return g=getsingledim(t,i,m),g&&u.push(g),g=getsingledim(e,r,o),g&&u.push(g),g=getsingledim(a,n,s),g&&u.push(g),(""+m+o+s).replace(/[_XM]/gi,""),u.join("x")}function formatDate(t){const e=new Date(t),a=e.getDate().toString().padStart(2,"0"),i=(e.getMonth()+1).toString().padStart(2,"0");return`${e.getFullYear()}-${i}-${a}`}function toDateStr(t){if(!t)return"";"number"==typeof t&&(t=t.toDate());let e=t.getDate(),a=t.getMonth()+1,i=t.getFullYear(),r=t.getHours(),n=t.getMinutes();return e=e<10?"0"+e:e,a=a<10?"0"+a:a,r=r<10?"0"+r:r,n=n<10?"0"+n:n,`${e}/${a}/${i} ${r}:${n}`}const e=new class Bus{constructor(){this.buslist={}}on(t,e){return this.buslist[t]||(this.buslist[t]=[]),this.buslist[t].push(e),this.buslist[t].length-1}emit(t,...e){this.buslist[t]&&this.buslist[t].forEach((t=>t(...e)))}off(t,e){this.buslist[t]&&("number"==typeof e?e>=0&&e<this.buslist[t].length&&this.buslist[t].splice(e,1):this.buslist[t]=this.buslist[t].filter((t=>t!==e)))}$on(t,e){this.on(t,e)}$off(t,e){this.off(t,e)}$emit(t,...e){this.emit(t,...e)}};function listfromstring(t){if(Array.isArray(t))return t;var e=[],a={};if(t){var i=t.split(/[\n;\,]/);for(var r of i){var n,m,o=r.search(/[\:=#]/);o<0?n=m=r.trim():(n=r.slice(0,o),m=r.slice(o+1)),(n=n.toLowerCase())&&!a[n]&&(a[n]=1,e.push({cod:n,des:m}))}}return e}e.messaggio=t=>e.emit("messaggio",t),e.warning=t=>e.emit("warning",t),e.errore=t=>e.emit("error",t),e.salvato=t=>e.emit("messaggio","dati memorizzati!"),e.wait=t=>e.emit("wait",t);var tonum=(t,e=-1)=>{if(!t)return 0;if("number"==typeof t)return t||0;let a=0;if("string"==typeof t){let e=(t=t.replaceAll(",",".")).match(/^-?[0-9.]+$/g);if(e&&e.length>0)a=Number(e[0]);else if(/^\s*\-?\s*[0-9]+(\.[0-9]+)?\s*$/gi.test(t))a=parseFloat(t);else if(/[\s\d\(\)\-\+\/\*\^\.]+/gi.test(t))try{a=new Function(`${baseeval} (${t})`)()}catch{a=0}}if(e>=0){const t=Math.pow(10,e);a=Math.round(a*t)/t}return a||0},toEuro=(t,e,a="")=>0==t?e||"":new Intl.NumberFormat("it-IT",{style:"currency",currency:"EUR"}).format(tonum(t))+a;let a={};var strDate=(t,e)=>{Date.prototype.getWeek||(Date.prototype.getWeek=function(){var t=new Date(this.getFullYear(),0,1);return Math.ceil(((this-t)/864e5+t.getDay()+1)/7)});var i="it";if("object"!=typeof t){if(!(t=parseFloat(t||0)))return"";t=t.toDate()}if("week"==e)return"w"+t.getWeek();if(!a[e])switch(e){case"giorni":if(!x)return"";var r=x.diffgiorni((new Date).toInt());return 0==r?"Oggi":-1==r?"Domani":1==r?"Ieri":Math.abs(r)<6?new Intl.DateTimeFormat(i,{weekday:"long"}).format(t).trim():strDate(x,"ggmmm");case"date":case"shortdate":a[e]=new Intl.DateTimeFormat(i,{weekday:"short",day:"numeric",month:"short",year:"numeric"});break;case"ggmmaa":case"ggmmyy":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit",year:"2-digit"});break;case"datetime":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"});break;case"yyyy":case"anno":a[e]=new Intl.DateTimeFormat(i,{year:"numeric"});break;case"ggmmaaaa":case"ggmmyyyy":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit",year:"numeric"});break;case"ggmm":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit"});break;case"giorno":case"gg":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit"});break;case"ggmmmaaaa":case"ggmmmyyyy":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"short",year:"numeric"});break;case"ggmmmaa":case"ggmmmyy":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"short",year:"2-digit"});break;case"ggmmm":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"short"});break;case"ggmmmm":a[e]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"long"});break;case"mmmyy":case"mmmaa":case"mmmyyyy":case"mmmaaaa":a[e]=new Intl.DateTimeFormat(i,{month:"short",year:"numeric"});break;case"weekday":a[e]=new Intl.DateTimeFormat(i,{weekday:"long"});break;case"hhmm":a[e]=new Intl.DateTimeFormat(i,{hour12:!1,hour:"numeric",minute:"2-digit"});break;case"hhmmss":a[e]=new Intl.DateTimeFormat(i,{hour12:!1,hour:"numeric",minute:"2-digit",second:"2-digit"});break;case"mese":a[e]=new Intl.DateTimeFormat(i,{month:"long"});break;default:a[e="."]||(a[e]=new Intl.DateTimeFormat(i,{weekday:"long",day:"numeric",month:"long",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"}))}return a[e].format(t).trim()};async function evalcustomfunction(t,e,a,i){try{let r={};for(let e of a)r[e]=await t.vari.var(e);i||(i={});let n={A:t,V:t.vari,log:console.log,Math:Math,...i},m=[...a,...Object.keys(n)];const o=new Function(...m,e),s=await o(...a.map((t=>r[t])),...Object.values(n));if(s&&"object"==typeof s&&Object.keys(s).length>0)for(let e of Object.keys(s))t.vari.add(e,s[e]);return s}catch(t){throw console.error("Errore durante l'esecuzione:",t),t}}export{e as bus,evalcustomfunction,formatDate,getdim,listfromstring,myuuid,strDate,toDateStr,toEuro,tonum};
|