markuno_lib 1.2.140 → 1.2.142
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/bin/markcad.js +1 -1
- package/bin/markuno.js +1 -1
- package/package.json +1 -1
- package/types/bus_utils.d.ts +3 -3
- package/types/markcad.d.ts +14 -3
- package/types/markuno.d.ts +2 -1
package/bin/bus_utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function post_utils(e={}){let{pako:t,user:r,hash:i,bus:
|
|
1
|
+
function post_utils(e={}){let{pako:t,user:r,hash:i,bus:a,goto:n}=e;function getStorage(e,t){let r;return window?.localStorage&&(r=window.localStorage.getItem(e)),r?JSON.parse(r):t}function setStorage(e,t){window?.localStorage&&(null==t||""===t?window.localStorage.removeItem(e):window.localStorage.setItem(e,JSON.stringify(t)))}const o=new class Post{constructor(){this.baseurl="/",this.user={},this._fingerprint=""}get oggi(){return(new Date).toInt()}get oggif(){return(new Date).toFloat()}get fingerprint(){return this._fingerprint||(this._fingerprint=getStorage("__fingerprint",i(`${(new Date).toString()}-${Math.random()}`)),setStorage("__fingerprint",this._fingerprint)),this._fingerprint}isauth(e){if(null==e||""===e)return!0;if("string"!=typeof e)return!!e;let t=!1;return r.subscribe((r=>{r.level>=8?t=!0:r.abruoli&&(t=r.abruoli.split(";").includes(e.trim().toLowerCase()))})),t}fullurl(e){return e&&!/http[s]*:\/\//.test(e)&&this.baseurl?this.baseurl+e:e}fullget(e,t,i){e=this.fullurl(e),t||(t={}),i||r.subscribe((e=>{e?.token&&(t._uid=e.token)}));let a=[];for(let e in t)a.push(`${e}=${encodeURIComponent(t[e])}`);return a.length&&(e=`${e}?${a.join("&")}`),e}fetch(e,i,a,n=!1){i||(i={}),!/http[s]*:\/\//.test(e)&&this.baseurl&&(e=this.baseurl+e);let o,s={};return new Promise(((n,m)=>{if(r.subscribe((e=>{e?.token&&(s.Authorization=`Bearer ${e?.token}`)})),s["cp-fp"]=this.fingerprint,a&&a.length>0){o=new FormData;for(const[e,t]of Object.entries(i))o.append(e,t);a&&a.length&&Array.from(Array(a.length).keys()).map((e=>{o.append(a[e].name,a[e],a[e].name)}))}else{const e=JSON.stringify(i);if(e.length>1e3&&this.canzip&&t){s["Content-Type"]="application/json",s["Content-Encoding"]="gzip";const r=t.gzip(e);o=new Blob([r],{type:"application/gzip"})}else s["Content-Type"]="application/json; charset=utf-8",o=e}fetch(e,{method:"POST",headers:s,mode:"cors",cache:"no-cache",credentials:"omit",redirect:"follow",referrer:"no-referrer",body:o}).then((e=>e.json())).then((e=>{e.err&&m(e.err),n(e.data?e.data:e)})).catch((e=>{m(e.message)}))}))}post(e,t,r,i=!1){return new Promise(((a,n)=>{o.fetch(e,t,r,i).then((e=>{a(e)})).catch((e=>{n(e)}))}))}},s=o,m=o.isauth;return{post:s,PP:async(e,t,i,s)=>{try{return o.lasterr=void 0,await o.fetch(e,t,i,s)}catch(m){if("api/token"==e)return r.set({}),void n("/");if("string"!=typeof m||!m.includes("01-"))return a.errore(m?.message?m.message:m),void(o.lasterr=m?.message?m.message:m);try{let e;r.subscribe((t=>{t?.rtk&&(e=t.rtk)}));const t=await o.fetch("api/token",{rtk:e},null,!0);t.user?r.set(t.user):(r.set({}),n("/"))}catch(e){r.set({}),n("/")}try{return await o.fetch(e,t,i,s)}catch(e){return void a.errore(m?.message?m.message:m)}}},P:o,isauth:m,userguest:{id:99999,name:"guest",email:"guest@croswil.com",level:0,ruoli:"",mod:"",extra:"",annulla:0,token:"guest",rtk:"guest"},round2:function round2(e){return Math.round(100*(e||0))/100},parsetree:function parsetree(e,t){if(e)for(let r of e)t&&t(r),r.data&&parsetree(r.data,t)},getStorage:getStorage,setStorage:setStorage,readfile:function readfile(e){return new Promise(((t,r)=>{let i=new FileReader;i.readAsArrayBuffer(e),i.onerror=e=>{r(e)},i.onload=e=>{let r=e.target.result;t(r)}}))},downloadfile:function downloadfile(e){try{const t=URL.createObjectURL(e),r=document.createElement("a");r.href=t,r.download=e.name,r.click(),URL.revokeObjectURL(t)}catch(t){console.log(`errore: ${t.message}=>${e?.name}`)}}}}let e=1e3;function myuuid(){return e++,e}function getdim(e,t,r,i,a,n,o,s,m){let l,u=[];function getsingledim(e,t,r){return e||(e=t),e=Math.round(10*(e||0))/10,t?"X"==(r=(r||"_").trim().toLowerCase())&&e!=t?e+"*":"M"==r?e+"M":e:e}return l=getsingledim(e,i,o),l&&u.push(l),l=getsingledim(t,a,s),l&&u.push(l),l=getsingledim(r,n,m),l&&u.push(l),(""+o+s+m).replace(/[_XM]/gi,""),u.join("x")}function formatDate(e){const t=new Date(e),r=t.getDate().toString().padStart(2,"0"),i=(t.getMonth()+1).toString().padStart(2,"0");return`${t.getFullYear()}-${i}-${r}`}function toDateStr(e){if(!e)return"";"number"==typeof e&&(e=e.toDate());let t=e.getDate(),r=e.getMonth()+1,i=e.getFullYear(),a=e.getHours(),n=e.getMinutes();return t=t<10?"0"+t:t,r=r<10?"0"+r:r,a=a<10?"0"+a:a,n=n<10?"0"+n:n,`${t}/${r}/${i} ${a}:${n}`}const t=new class Bus{constructor(){this.buslist={}}on(e,t){return this.buslist[e]||(this.buslist[e]=[]),this.buslist[e].push(t),this.buslist[e].length-1}emit(e,...t){this.buslist[e]&&this.buslist[e].forEach((e=>e(...t)))}off(e,t){this.buslist[e]&&("number"==typeof t?t>=0&&t<this.buslist[e].length&&this.buslist[e].splice(t,1):this.buslist[e]=this.buslist[e].filter((e=>e!==t)))}$on(e,t){this.on(e,t)}$off(e,t){this.off(e,t)}$emit(e,...t){this.emit(e,...t)}};function listfromstring(e){if(Array.isArray(e))return e;let t=[],r={};if(e){let i=e.split(/[\n;,]/);for(let e of i){let i,a,n=e.search(/[:=#]/);n<0?i=a=e.trim():(i=e.slice(0,n),a=e.slice(n+1)),i=i.toLowerCase(),i&&!r[i]&&(r[i]=1,t.push({cod:i,des:a}))}}return t}t.messaggio=e=>t.emit("messaggio",e),t.warning=e=>t.emit("warning",e),t.errore=e=>t.emit("error",e),t.salvato=e=>t.emit("messaggio","dati memorizzati!"),t.wait=e=>t.emit("wait",e);const tonum=(e,t=-1)=>{if(!e)return 0;if("number"==typeof e)return e||0;let r=0;if("string"==typeof e){let t=(e=e.replaceAll(",",".")).match(/^-?[0-9.]+$/g);t&&t.length>0?r=Number(t[0]):/^\s*-?\s*[0-9]+(\.[0-9]+)?\s*$/gi.test(e)?r=parseFloat(e):/[\s\d()-+/*^.]+/gi.test(e)&&(r=0)}if(t>=0){const e=Math.pow(10,t);r=Math.round(r*e)/e}return r||0},toEuro=(e,t,r="")=>0==e?t||"":new Intl.NumberFormat("it-IT",{style:"currency",currency:"EUR"}).format(tonum(e))+r;let r={};const strDate=(e,t)=>{Date.prototype.getWeek||(Date.prototype.getWeek=function(){let e=new Date(this.getFullYear(),0,1);return Math.ceil(((this-e)/864e5+e.getDay()+1)/7)});let i="it";if("object"!=typeof e){if(!(e=parseFloat(e||0)))return"";e=e.toDate()}if("week"==t)return"w"+e.getWeek();if(!r[t])switch(t){case"giorni":{let t=e.toInt(),r=t.diffgiorni((new Date).toInt());if(0==r)return"Oggi";if(-1==r)return"Domani";if(1==r)return"Ieri";if(Math.abs(r)<6){return new Intl.DateTimeFormat(i,{weekday:"long"}).format(e).trim()}return strDate(t,"ggmmm")}case"date":case"shortdate":r[t]=new Intl.DateTimeFormat(i,{weekday:"short",day:"numeric",month:"short",year:"numeric"});break;case"ggmmaa":case"ggmmyy":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit",year:"2-digit"});break;case"datetime":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"});break;case"yyyy":case"anno":r[t]=new Intl.DateTimeFormat(i,{year:"numeric"});break;case"ggmmaaaa":case"ggmmyyyy":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit",year:"numeric"});break;case"ggmm":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"2-digit"});break;case"giorno":case"gg":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit"});break;case"ggmmmaaaa":case"ggmmmyyyy":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"short",year:"numeric"});break;case"ggmmmaa":case"ggmmmyy":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"short",year:"2-digit"});break;case"ggmmm":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"short"});break;case"ggmmmm":r[t]=new Intl.DateTimeFormat(i,{day:"2-digit",month:"long"});break;case"mmmyy":case"mmmaa":case"mmmyyyy":case"mmmaaaa":r[t]=new Intl.DateTimeFormat(i,{month:"short",year:"numeric"});break;case"weekday":r[t]=new Intl.DateTimeFormat(i,{weekday:"long"});break;case"hhmm":r[t]=new Intl.DateTimeFormat(i,{hour12:!1,hour:"numeric",minute:"2-digit"});break;case"hhmmss":r[t]=new Intl.DateTimeFormat(i,{hour12:!1,hour:"numeric",minute:"2-digit",second:"2-digit"});break;case"mese":r[t]=new Intl.DateTimeFormat(i,{month:"long"});break;default:r[t="."]||(r[t]=new Intl.DateTimeFormat(i,{weekday:"long",day:"numeric",month:"long",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"}))}return r[t].format(e).trim()};export{t as bus,formatDate,getdim,listfromstring,myuuid,post_utils,strDate,toDateStr,toEuro,tonum};
|