markuno_lib 1.2.82 → 1.2.84
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 -76
- package/bin/markcad.js +1 -1121
- package/bin/marked.js +1 -21
- package/bin/markuno.js +1 -268
- package/bin/proto.js +1 -184
- package/package.json +1 -1
- package/types/bus_utils.d.ts +15 -45
- package/types/markcad.d.ts +2151 -484
- package/types/marked.d.ts +43 -43
- package/types/markuno.d.ts +169 -363
package/bin/bus_utils.js
CHANGED
|
@@ -1,76 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Genera un ID univoco incrementale
|
|
3
|
-
* @returns {number} Un numero intero univoco
|
|
4
|
-
*/
|
|
5
|
-
let uniqid=1e3;function myuuid(){return uniqid++,uniqid}function getdim(l,a,p,al,aa,ap,fmodl,fmoda,fmodp){let x,cl=[];function getsingledim(x,ax,fx){return x||(x=ax),ax?"X"==(fx=(fx||"_").trim().toLowerCase())&&x!=ax?x+"*":"M"==fx?x+"M":x:x}return x=getsingledim(l,al,fmodl),x&&cl.push(x),x=getsingledim(a,aa,fmoda),x&&cl.push(x),x=getsingledim(p,ap,fmodp),x&&cl.push(x),(""+fmodl+fmoda+fmodp).replace(/[_XM]/gi,""),cl.join("x")}
|
|
6
|
-
/**
|
|
7
|
-
* Formatta una data nel formato YYYY-MM-DD
|
|
8
|
-
* @param {string|Date} dateString - La data da formattare
|
|
9
|
-
* @returns {string} La data formattata come YYYY-MM-DD
|
|
10
|
-
*/function formatDate(dateString){const date=new Date(dateString),day=date.getDate().toString().padStart(2,"0"),month=(date.getMonth()+1).toString().padStart(2,"0");return`${date.getFullYear()}-${month}-${day}`}
|
|
11
|
-
/**
|
|
12
|
-
* Converte una data nel formato DD/MM/YYYY HH:mm
|
|
13
|
-
* @param {Date|number} date - La data da convertire
|
|
14
|
-
* @returns {string} La data formattata come DD/MM/YYYY HH:mm
|
|
15
|
-
*/function toDateStr(date){if(!date)return"";"number"==typeof date&&(date=date.toDate());let day=date.getDate(),month=date.getMonth()+1,year=date.getFullYear(),hours=date.getHours(),minutes=date.getMinutes();return day=day<10?"0"+day:day,month=month<10?"0"+month:month,hours=hours<10?"0"+hours:hours,minutes=minutes<10?"0"+minutes:minutes,`${day}/${month}/${year} ${hours}:${minutes}`}
|
|
16
|
-
/**
|
|
17
|
-
* Implementa un sistema di eventi publish/subscribe
|
|
18
|
-
*/const bus=new class Bus{constructor(){this.buslist={}}
|
|
19
|
-
/**
|
|
20
|
-
* Registra un handler per un evento
|
|
21
|
-
* @param {string} des - Nome dell'evento
|
|
22
|
-
* @param {Function} func - Handler da eseguire
|
|
23
|
-
* @returns {number} Indice dell'handler nella lista
|
|
24
|
-
*/on(des,func){return this.buslist[des]||(this.buslist[des]=[]),this.buslist[des].push(func),this.buslist[des].length-1}
|
|
25
|
-
/**
|
|
26
|
-
* Emette un evento con i relativi parametri
|
|
27
|
-
* @param {string} des - Nome dell'evento
|
|
28
|
-
* @param {...any} args - Parametri da passare agli handler
|
|
29
|
-
*/emit(des,...args){this.buslist[des]&&this.buslist[des].forEach((f=>f(...args)))}
|
|
30
|
-
/**
|
|
31
|
-
* Rimuove un handler per un evento
|
|
32
|
-
* @param {string} des - Nome dell'evento
|
|
33
|
-
* @param {Function|number} func - Handler da rimuovere o suo indice
|
|
34
|
-
*/off(des,func){this.buslist[des]&&("number"==typeof func?func>=0&&func<this.buslist[des].length&&this.buslist[des].splice(func,1):this.buslist[des]=this.buslist[des].filter((x=>x!==func)))}$on(des,func){this.on(des,func)}$off(des,func){this.off(des,func)}$emit(des,...args){this.emit(des,...args)}};
|
|
35
|
-
/**
|
|
36
|
-
* Converte una stringa delimitata in array di oggetti {cod, des}
|
|
37
|
-
* @param {string|Array} x - Stringa con valori delimitati da \n ; o ,
|
|
38
|
-
* @returns {Array<{cod: string, des: string}>} Array di oggetti con codice e descrizione
|
|
39
|
-
*/
|
|
40
|
-
function listfromstring(x){if(Array.isArray(x))return x;let cl=[],fl={};if(x){let vv=x.split(/[\n;,]/);for(let v of vv){let c,d,i=v.search(/[:=#]/);i<0?c=d=v.trim():(c=v.slice(0,i),d=v.slice(i+1)),c=c.toLowerCase(),c&&!fl[c]&&(fl[c]=1,cl.push({cod:c,des:d}))}}return cl}
|
|
41
|
-
/**
|
|
42
|
-
* Converte una stringa in numero con opzionale arrotondamento decimale
|
|
43
|
-
* @param {string|number} s - Valore da convertire
|
|
44
|
-
* @param {number} dec - Numero di decimali (-1 per nessun arrotondamento)
|
|
45
|
-
* @returns {number} Il numero convertito
|
|
46
|
-
*/bus.messaggio=msg=>bus.emit("messaggio",msg),bus.warning=msg=>bus.emit("warning",msg),bus.errore=msg=>bus.emit("error",msg),bus.salvato=msg=>bus.emit("messaggio","dati memorizzati!"),bus.wait=modo=>bus.emit("wait",modo);const tonum=(s,dec=-1)=>{if(!s)return 0;if("number"==typeof s)return s||0;let n=0;if("string"==typeof s){let x=(s=s.replaceAll(",",".")).match(/^-?[0-9.]+$/g);x&&x.length>0?n=Number(x[0]):/^\s*-?\s*[0-9]+(\.[0-9]+)?\s*$/gi.test(s)?n=parseFloat(s):/[\s\d()-+/*^.]+/gi.test(s)&&(n=0)}if(dec>=0){const factor=Math.pow(10,dec);n=Math.round(n*factor)/factor}return n||0},toEuro=(n,gratis,des="")=>0==n?gratis||"":new Intl.NumberFormat("it-IT",{style:"currency",currency:"EUR"}).format(tonum(n))+des;
|
|
47
|
-
/**
|
|
48
|
-
* Formatta un numero in valuta Euro
|
|
49
|
-
* @param {number} n - Numero da formattare
|
|
50
|
-
* @param {string} gratis - Testo da mostrare se n=0
|
|
51
|
-
* @param {string} des - Testo da aggiungere dopo l'importo
|
|
52
|
-
* @returns {string} Importo formattato in Euro
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
* Formatta una data secondo il formato specificato
|
|
56
|
-
* @param {Date|number} date - Data da formattare. Se number viene convertito in Date
|
|
57
|
-
* @param {string} formato - Formato desiderato. Valori possibili:
|
|
58
|
-
* - 'week': numero settimana (es. 'w23')
|
|
59
|
-
* - 'giorni': testo relativo ('Oggi', 'Ieri', 'Domani', giorno settimana o data breve)
|
|
60
|
-
* - 'date'/'shortdate': data breve con giorno settimana
|
|
61
|
-
* - 'ggmmaa'/'ggmmyy': data in formato DD/MM/YY
|
|
62
|
-
* - 'datetime': data e ora (DD/MM/YYYY HH:mm)
|
|
63
|
-
* - 'yyyy'/'anno': solo anno
|
|
64
|
-
* - 'ggmmaaaa'/'ggmmyyyy': data in formato DD/MM/YYYY
|
|
65
|
-
* - 'ggmm': solo giorno e mese
|
|
66
|
-
* - 'giorno'/'gg': solo giorno
|
|
67
|
-
* - 'ggmmm': giorno e mese abbreviato
|
|
68
|
-
* - 'ggmmmm': giorno e mese esteso
|
|
69
|
-
* - 'mmmyy'/'mmmaa': mese abbreviato e anno
|
|
70
|
-
* - 'weekday': nome giorno settimana
|
|
71
|
-
* - 'hhmm': ora e minuti
|
|
72
|
-
* - 'hhmmss': ora, minuti e secondi
|
|
73
|
-
* - 'mese': nome mese
|
|
74
|
-
* @returns {string} Data formattata secondo il formato richiesto
|
|
75
|
-
*/
|
|
76
|
-
let __formati={};const strDate=(date,formato)=>{Date.prototype.getWeek||(Date.prototype.getWeek=function(){let onejan=new Date(this.getFullYear(),0,1);return Math.ceil(((this-onejan)/864e5+onejan.getDay()+1)/7)});if("object"!=typeof date){if(!(date=parseFloat(date||0)))return"";date=date.toDate()}if("week"==formato)return"w"+date.getWeek();if(!__formati[formato])switch(formato){case"giorni":{let x=date.toInt(),gg=x.diffgiorni((new Date).toInt());if(0==gg)return"Oggi";if(-1==gg)return"Domani";if(1==gg)return"Ieri";if(Math.abs(gg)<6){return new Intl.DateTimeFormat("it",{weekday:"long"}).format(date).trim()}return strDate(x,"ggmmm")}case"date":case"shortdate":__formati[formato]=new Intl.DateTimeFormat("it",{weekday:"short",day:"numeric",month:"short",year:"numeric"});break;case"ggmmaa":case"ggmmyy":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"2-digit",year:"2-digit"});break;case"datetime":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"2-digit",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"});break;case"yyyy":case"anno":__formati[formato]=new Intl.DateTimeFormat("it",{year:"numeric"});break;case"ggmmaaaa":case"ggmmyyyy":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"2-digit",year:"numeric"});break;case"ggmm":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"2-digit"});break;case"giorno":case"gg":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit"});break;case"ggmmmaaaa":case"ggmmmyyyy":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"short",year:"numeric"});break;case"ggmmmaa":case"ggmmmyy":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"short",year:"2-digit"});break;case"ggmmm":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"short"});break;case"ggmmmm":__formati[formato]=new Intl.DateTimeFormat("it",{day:"2-digit",month:"long"});break;case"mmmyy":case"mmmaa":case"mmmyyyy":case"mmmaaaa":__formati[formato]=new Intl.DateTimeFormat("it",{month:"short",year:"numeric"});break;case"weekday":__formati[formato]=new Intl.DateTimeFormat("it",{weekday:"long"});break;case"hhmm":__formati[formato]=new Intl.DateTimeFormat("it",{hour12:!1,hour:"numeric",minute:"2-digit"});break;case"hhmmss":__formati[formato]=new Intl.DateTimeFormat("it",{hour12:!1,hour:"numeric",minute:"2-digit",second:"2-digit"});break;case"mese":__formati[formato]=new Intl.DateTimeFormat("it",{month:"long"});break;default:__formati[formato="."]||(__formati[formato]=new Intl.DateTimeFormat("it",{weekday:"long",day:"numeric",month:"long",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"}))}return __formati[formato].format(date).trim()};export{bus,formatDate,getdim,listfromstring,myuuid,strDate,toDateStr,toEuro,tonum};
|
|
1
|
+
let t=1e3;function myuuid(){return t++,t}function getdim(t,e,i,a,r,n,m,s,o){let g,u=[];function getsingledim(t,e,i){return t||(t=e),e?"X"==(i=(i||"_").trim().toLowerCase())&&t!=e?t+"*":"M"==i?t+"M":t:t}return g=getsingledim(t,a,m),g&&u.push(g),g=getsingledim(e,r,s),g&&u.push(g),g=getsingledim(i,n,o),g&&u.push(g),(""+m+s+o).replace(/[_XM]/gi,""),u.join("x")}function formatDate(t){const e=new Date(t),i=e.getDate().toString().padStart(2,"0"),a=(e.getMonth()+1).toString().padStart(2,"0");return`${e.getFullYear()}-${a}-${i}`}function toDateStr(t){if(!t)return"";"number"==typeof t&&(t=t.toDate());let e=t.getDate(),i=t.getMonth()+1,a=t.getFullYear(),r=t.getHours(),n=t.getMinutes();return e=e<10?"0"+e:e,i=i<10?"0"+i:i,r=r<10?"0"+r:r,n=n<10?"0"+n:n,`${e}/${i}/${a} ${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;let e=[],i={};if(t){let a=t.split(/[\n;,]/);for(let t of a){let a,r,n=t.search(/[:=#]/);n<0?a=r=t.trim():(a=t.slice(0,n),r=t.slice(n+1)),a=a.toLowerCase(),a&&!i[a]&&(i[a]=1,e.push({cod:a,des:r}))}}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);const tonum=(t,e=-1)=>{if(!t)return 0;if("number"==typeof t)return t||0;let i=0;if("string"==typeof t){let e=(t=t.replaceAll(",",".")).match(/^-?[0-9.]+$/g);e&&e.length>0?i=Number(e[0]):/^\s*-?\s*[0-9]+(\.[0-9]+)?\s*$/gi.test(t)?i=parseFloat(t):/[\s\d()-+/*^.]+/gi.test(t)&&(i=0)}if(e>=0){const t=Math.pow(10,e);i=Math.round(i*t)/t}return i||0},toEuro=(t,e,i="")=>0==t?e||"":new Intl.NumberFormat("it-IT",{style:"currency",currency:"EUR"}).format(tonum(t))+i;let i={};const strDate=(t,e)=>{Date.prototype.getWeek||(Date.prototype.getWeek=function(){let t=new Date(this.getFullYear(),0,1);return Math.ceil(((this-t)/864e5+t.getDay()+1)/7)});let a="it";if("object"!=typeof t){if(!(t=parseFloat(t||0)))return"";t=t.toDate()}if("week"==e)return"w"+t.getWeek();if(!i[e])switch(e){case"giorni":{let e=t.toInt(),i=e.diffgiorni((new Date).toInt());if(0==i)return"Oggi";if(-1==i)return"Domani";if(1==i)return"Ieri";if(Math.abs(i)<6){return new Intl.DateTimeFormat(a,{weekday:"long"}).format(t).trim()}return strDate(e,"ggmmm")}case"date":case"shortdate":i[e]=new Intl.DateTimeFormat(a,{weekday:"short",day:"numeric",month:"short",year:"numeric"});break;case"ggmmaa":case"ggmmyy":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"2-digit",year:"2-digit"});break;case"datetime":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"2-digit",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"});break;case"yyyy":case"anno":i[e]=new Intl.DateTimeFormat(a,{year:"numeric"});break;case"ggmmaaaa":case"ggmmyyyy":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"2-digit",year:"numeric"});break;case"ggmm":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"2-digit"});break;case"giorno":case"gg":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit"});break;case"ggmmmaaaa":case"ggmmmyyyy":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"short",year:"numeric"});break;case"ggmmmaa":case"ggmmmyy":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"short",year:"2-digit"});break;case"ggmmm":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"short"});break;case"ggmmmm":i[e]=new Intl.DateTimeFormat(a,{day:"2-digit",month:"long"});break;case"mmmyy":case"mmmaa":case"mmmyyyy":case"mmmaaaa":i[e]=new Intl.DateTimeFormat(a,{month:"short",year:"numeric"});break;case"weekday":i[e]=new Intl.DateTimeFormat(a,{weekday:"long"});break;case"hhmm":i[e]=new Intl.DateTimeFormat(a,{hour12:!1,hour:"numeric",minute:"2-digit"});break;case"hhmmss":i[e]=new Intl.DateTimeFormat(a,{hour12:!1,hour:"numeric",minute:"2-digit",second:"2-digit"});break;case"mese":i[e]=new Intl.DateTimeFormat(a,{month:"long"});break;default:i[e="."]||(i[e]=new Intl.DateTimeFormat(a,{weekday:"long",day:"numeric",month:"long",year:"numeric",hour12:!1,hour:"numeric",minute:"2-digit"}))}return i[e].format(t).trim()};export{e as bus,formatDate,getdim,listfromstring,myuuid,strDate,toDateStr,toEuro,tonum};
|