dphelper 4.5.2 → 4.6.1
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/README.md +20 -0
- package/index.cjs +2 -2
- package/index.js +2 -2
- package/modules/ai.cjs +1 -1
- package/modules/ai.js +1 -1
- package/modules/anchor.cjs +1 -1
- package/modules/anchor.js +1 -1
- package/modules/array.cjs +1 -1
- package/modules/array.js +1 -1
- package/modules/audio.cjs +1 -1
- package/modules/audio.js +1 -1
- package/modules/avoid.cjs +1 -1
- package/modules/avoid.js +1 -1
- package/modules/biometric.cjs +1 -1
- package/modules/biometric.js +1 -1
- package/modules/browser.cjs +1 -1
- package/modules/browser.js +1 -1
- package/modules/check.cjs +1 -1
- package/modules/check.js +1 -1
- package/modules/color.cjs +1 -1
- package/modules/color.js +1 -1
- package/modules/compress.cjs +1 -1
- package/modules/compress.js +1 -1
- package/modules/cookie.cjs +1 -1
- package/modules/cookie.js +1 -1
- package/modules/coords.cjs +1 -1
- package/modules/coords.js +1 -1
- package/modules/credits.cjs +1 -1
- package/modules/credits.js +1 -1
- package/modules/date.cjs +1 -1
- package/modules/date.js +1 -1
- package/modules/disable.cjs +1 -1
- package/modules/disable.js +1 -1
- package/modules/dispatch.cjs +1 -1
- package/modules/dispatch.js +1 -1
- package/modules/elements.cjs +1 -1
- package/modules/elements.js +1 -1
- package/modules/events.cjs +1 -1
- package/modules/events.js +1 -1
- package/modules/fetch.cjs +1 -1
- package/modules/fetch.js +1 -1
- package/modules/form.cjs +1 -1
- package/modules/form.js +1 -1
- package/modules/format.cjs +1 -1
- package/modules/format.js +1 -1
- package/modules/i18n.cjs +1 -1
- package/modules/i18n.js +1 -1
- package/modules/image.cjs +1 -1
- package/modules/image.js +1 -1
- package/modules/json.cjs +1 -1
- package/modules/json.js +1 -1
- package/modules/load.cjs +1 -1
- package/modules/load.js +1 -1
- package/modules/logging.cjs +1 -1
- package/modules/logging.js +1 -1
- package/modules/math.cjs +1 -1
- package/modules/math.js +1 -1
- package/modules/memory.cjs +1 -1
- package/modules/memory.js +1 -1
- package/modules/navigation.cjs +1 -1
- package/modules/navigation.js +1 -1
- package/modules/net.cjs +1 -1
- package/modules/net.js +1 -1
- package/modules/objects.cjs +1 -1
- package/modules/objects.js +1 -1
- package/modules/path.cjs +1 -1
- package/modules/path.js +1 -1
- package/modules/promise.cjs +1 -1
- package/modules/promise.js +1 -1
- package/modules/sanitize.cjs +1 -1
- package/modules/sanitize.js +1 -1
- package/modules/screen.cjs +1 -1
- package/modules/screen.js +1 -1
- package/modules/scrollbar.cjs +1 -1
- package/modules/scrollbar.js +1 -1
- package/modules/security.cjs +1 -1
- package/modules/security.js +1 -1
- package/modules/shortcut.cjs +1 -1
- package/modules/shortcut.js +1 -1
- package/modules/socket.cjs +1 -1
- package/modules/socket.js +1 -1
- package/modules/sse.cjs +1 -1
- package/modules/sse.js +1 -1
- package/modules/svg.cjs +1 -1
- package/modules/svg.js +1 -1
- package/modules/sync.cjs +1 -1
- package/modules/sync.js +1 -1
- package/modules/system.cjs +1 -1
- package/modules/system.js +1 -1
- package/modules/text.cjs +2 -2
- package/modules/text.d.ts +1 -0
- package/modules/text.js +2 -2
- package/modules/timer.cjs +1 -1
- package/modules/timer.js +1 -1
- package/modules/tools.cjs +1 -1
- package/modules/tools.js +1 -1
- package/modules/translators.cjs +1 -1
- package/modules/translators.js +1 -1
- package/modules/triggers.cjs +1 -1
- package/modules/triggers.js +1 -1
- package/modules/types.cjs +1 -1
- package/modules/types.js +1 -1
- package/modules/ui.cjs +1 -1
- package/modules/ui.js +1 -1
- package/modules/window.cjs +1 -1
- package/modules/window.js +1 -1
- package/modules/worker.cjs +1 -1
- package/modules/worker.js +1 -1
- package/package.json +2 -2
- package/sbom.json +6 -6
- package/types/dphelper.d.ts +1 -0
package/README.md
CHANGED
|
@@ -361,6 +361,26 @@ await dphelper.fetch.get(safeUrl);
|
|
|
361
361
|
await dphelper.fetch.get(userInput); // ❌ Unvalidated
|
|
362
362
|
```
|
|
363
363
|
|
|
364
|
+
### Web Workers
|
|
365
|
+
|
|
366
|
+
Il modulo `dphelper.worker` permette di creare Web Worker, worker inline, pool e SharedWorker, e può eseguire codice fornito al momento della creazione. Per la natura stessa di queste API, **il codice e gli script caricati vengono eseguiti nel Worker** e quindi devono essere considerati attendibili:
|
|
367
|
+
|
|
368
|
+
- `dphelper.worker.createInline(code)` e `dphelper.worker.create(src)` (quando `src` è codice JavaScript) eseguono **il codice fornito**. Non passare mai input esterni non validati o non fidati: farebbe eseguire codice potenzialmente malevolo nel Worker (e quindi nel contesto del browser dell'utente).
|
|
369
|
+
- `dphelper.worker.importScripts(worker, scripts)` genera un wrapper `importScripts(...)` interno. La libreria **filtra i protocolli** (solo `http:`, `https:`, `blob:`, `data:` o percorsi relativi) e **escape dei caratteri `'` e `\`** per ridurre il rischio di injection, ma comunque affidabilità il contenuto e le URL alle pagine chiamanti.
|
|
370
|
+
- `dphelper.worker.shared(src)` crea un `SharedWorker`; `src` deve puntare a uno script fidato servito con `http:`/`https:` o percorso relativo.
|
|
371
|
+
|
|
372
|
+
> [!IMPORTANT]
|
|
373
|
+
> **Per gli utenti della libreria:** tutte le funzioni del modulo `worker` assumono che **inputs, script e codice siano sotto il controllo del chiamante**. Validare e sanitizzare sempre prima di passare dati a `createInline`, `create`, `pool` o `importScripts`. Non caricare script da URL controllati dall'utente finale.
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
// Corretto: codice statico e URL fidati
|
|
377
|
+
dphelper.worker.create("./my-trusted-worker.js");
|
|
378
|
+
dphelper.worker.importScripts(w, ["https://cdn.example.com/lib.js"]);
|
|
379
|
+
|
|
380
|
+
// Mai così: input utente direttamente
|
|
381
|
+
dphelper.worker.createInline(userSuppliedCode); // ❌ rischio esecuzione arbitraria
|
|
382
|
+
```
|
|
383
|
+
|
|
364
384
|
### Compliance
|
|
365
385
|
- 100% NIST/NSA compliant
|
|
366
386
|
- No known vulnerabilities
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var V={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var x={codeName:"dphelper",version:"4.
|
|
1
|
+
'use strict';var V={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var x={codeName:"dphelper",version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...V},configurable:true,writable:true},version:{value:x.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var P=dphelper;Object.defineProperty(P,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(P,"setDescription",{value:(e,t)=>{Object.defineProperties(P,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(P[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),P.setProps(P,e,{writable:false,configurable:false,enumerable:false}),P._list.scripts.push(e);}});var ue={name:"ai",active:true,subCommand:[{name:"tokenCount",version:"0.0.3",example:"dphelper.ai.tokenCount({ users: [1,2,3] })",author:"Dario Passariello",creationDate:"20260220",lastMod:"20260221",type:"function",active:true,description:"Estimate token count for LLMs. If an object is passed, it uses TOON format for calculation.",env:"both",subCommand:[]},{name:"smartSanitize",version:"0.0.2",example:"dphelper.ai.smartSanitize('My email is test@example.com')",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Remove PII (emails, phones, etc) from text for AI privacy",subCommand:[]},{name:"toon",version:"0.0.1",example:"dphelper.ai.toon({ users: [{id: 1, name: 'Ada'}] })",author:"TOON + Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert JSON to TOON format (Token-Oriented Object Notation)",subCommand:[]},{name:"toonToJson",version:"0.0.1",example:"dphelper.ai.toonToJson('users[1]{id,name}:\\n 1,Ada')",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert TOON format back to JSON/Object",subCommand:[]},{name:"chunker",version:"0.0.1",example:"dphelper.ai.chunker(text, { size: 1000, overlap: 200 })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Split long text into chunks for RAG or AI processing.",subCommand:[]},{name:"similarity",version:"0.0.1",example:"dphelper.ai.similarity(vecA, vecB)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Calculate cosine similarity between two embedding vectors.",subCommand:[]},{name:"extractReasoning",version:"0.0.1",example:"dphelper.ai.extractReasoning(aiResponse)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Extract <think> tags or internal reasoning from AI responses.",subCommand:[]},{name:"prompt",version:"0.0.1",example:"dphelper.ai.prompt('Hello {{name}}', { name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Simple prompt template engine with variable injection.",subCommand:[]},{name:"schema",version:"0.0.1",example:"dphelper.ai.schema({ id: 1, name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Generate a TOON-style schema definition for AI instructions.",subCommand:[]},{name:"snapshot",version:"0.0.1",example:"dphelper.ai.snapshot()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Capture a 'mental snapshot' of the app state (logs/globals) in TOON format for AI debugging.",env:"both",subCommand:[]}]},B=e=>e===null||typeof e!="object",H=e=>e===null?"null":typeof e=="string"?e.includes(",")||e.includes(":")||e.includes('"')||e.includes(`
|
|
2
2
|
`)||e.trim()!==e?`"${e.replace(/"/g,'\\"')}"`:e||'""':String(e),N=(e,t=0)=>{let r=" ".repeat(t);if(B(e))return H(e);if(Array.isArray(e)){if(e.length===0)return "[0]:";let n=e[0];if(!B(n)&&!Array.isArray(n)){let o=Object.keys(n),a=`[${e.length}]{${o.join(",")}}:`;for(let i of e){let s=o.map(l=>H(i[l])).join(",");a+=`
|
|
3
3
|
${r} ${s}`;}return a}else return `[${e.length}]: `+e.map(H).join(",")}else return Object.entries(e).map(([n,o])=>{let a=n.includes(" ")||n.includes(":")?`"${n}"`:n;if(!B(o)){let i=N(o,t+1);return i.startsWith("[")?`${a}${i}`:`${a}:
|
|
4
4
|
${r}${i}`}return `${a}: ${H(o)}`}).join(`
|
|
@@ -143,7 +143,7 @@ ${t(i,`${n} `)}${n}</${a}>
|
|
|
143
143
|
)
|
|
144
144
|
|
|
145
145
|
Copyright text (c) became an html symbol
|
|
146
|
-
`,env:"both",subCommand:[],author:"Dario Passariello",creationDate:"20250612",lastMod:"20250612"}]},Xr={trim:(e,t,r,n)=>e.charAt(0)===t?e.substring(r,n):e,capitalize:e=>e.toLowerCase().replace(/\b\w/g,t=>t.toUpperCase()),lower:e=>e.toLowerCase(),upper:e=>e.toUpperCase(),nl2br:e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/(?:\r\n|\r|\n)/g,"<br>"),sanitize:e=>e.replace(/<(|\/|[^>\bi]|\/[^>bi]|[^/>][^>]+|\/[^>][^>]+)>/g,""),camelCase:{toSpace:e=>e.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()),toUnderscore:e=>e.replace(/\.?([A-Z])/g,(t,r)=>`_${r.toLowerCase()}`).replace(/^_/,"")},fitContainer:e=>{if(!e)return;function t(r){let n=document.querySelectorAll(r),o=n.length;if(!(o<=0))for(let a=0;a<o;a++){let i=n[a].offsetWidth*.05;n[a].style.fontSize=`${i}px`;}}dphelper.addListenerMulti(window,"load resize",()=>t(e));},keywords:e=>{let t=/\b[A-Z][a-z]+\b/g,r=e.match(t)?.filter(n=>n.length>3)||[];return [...new Set(r.map(n=>n.toLowerCase()))]},replaceText:(e,t)=>{let r=e;for(let n in t)Object.hasOwn(t,n)&&(r=r.replaceAll(n,t[n]||""));return r}};dphelper?.setDescription(Zr,Xr);var Qr={name:"timer",active:true,subCommand:[{name:"sleep",version:"0.0.2",example:"dphelper.timer.sleep([ms]) ",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Pauses execution for a specified number of milliseconds.",env:"both",subCommand:[]},{name:"percentage",version:"0.0.2",example:"dphelper.timer.percentage([start], [end])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Calculates the percentage of time elapsed between two time strings.",env:"both",subCommand:[]}]},en={sleep:e=>new Promise(t=>setTimeout(t,e)),percentage:(e,t)=>{function r(n){let o=n.split(":");return Number.parseInt(o[0]||"",10)*3600+Number.parseInt(o[1]||"",10)*60+Number.parseInt(o[2]||"",10)}return (100*r(e)/r(t)).toFixed(2)}};dphelper?.setDescription(Qr,en);var tn={name:"tools",active:true,subCommand:[{name:"byteSize",description:"Give you the total in 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb' starting from bytes",example:"dphelper.tools.byteSize(bytes)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"hashPass",description:"Hashes a password using a specified number and total.",example:"dphelper.tools.hashPass(number, total)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"zIndex",description:"Finds the highest z-index value in the document.",example:"dphelper.tools.zIndex()",version:"0.0.2",author:"Dario Passariello",creationDate:"20240807",lastMod:"20240807",type:"function",active:true,env:"both",subCommand:[]},{name:"zeroToFalse",description:"Converts zero to false, otherwise returns the value.",example:"dphelper.tools.zeroToFalse(num)",version:"0.0.2",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:true,env:"both",subCommand:[]}]},rn={byteSize:e=>{if(Math.abs(e)<1024)return `${e}b`;let r=["Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],n=-1,o=e;do o/=1024,++n;while(Math.abs(o)>=1024&&n<r.length-1);return o.toFixed(1)+r[n]},zIndex:()=>Array.from(document.querySelectorAll("body *")).map(e=>Number.parseFloat(getComputedStyle(e).zIndex)).reduce((e,t)=>t>e?t:e,1),zeroToFalse:e=>e===0?false:e};dphelper?.setDescription(tn,rn);var nn={name:"translators",active:true,subCommand:[{name:"convertMatrixToScale",version:"0.0.2",example:"dphelper.translators.convertMatrixToScale({value})",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Converts a transformation matrix to a scale value.",env:"both",subCommand:[]}]},on={convertMatrixToScale:e=>{let t=e.split("(");if(t.length<2)return 0;let r=t[1].split(")")[0];if(!r)return 0;let n=r.split(","),o=Number.parseFloat(n[0]||"0"),a=Number.parseFloat(n[1]||"0");return Math.sqrt(o*o+a*a)}};dphelper?.setDescription(nn,on);var an={name:"triggers",active:true,subCommand:[{name:"add",version:"0.0.1",example:"dphelper.triggers.add('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Add a trigger for custom events.",env:"client",subCommand:[]},{name:"on",version:"0.0.1",example:"dphelper.triggers.on('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Listen for a trigger event.",env:"client",subCommand:[]},{name:"emit",version:"0.0.1",example:"dphelper.triggers.emit('event', data)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Emit a trigger event.",env:"client",subCommand:[]},{name:"remove",version:"0.0.1",example:"dphelper.triggers.remove('event')",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Remove a trigger event.",env:"client",subCommand:[]}]},M=new Map,ie={add:(e,t)=>{M.has(e)||M.set(e,new Set),M.get(e).add(t);},on:(e,t)=>{ie.add(e,t);},emit:(e,...t)=>{let r=M.get(e);r&&r.forEach(n=>{try{n(...t);}catch(o){console.error(`Error in trigger callback for event '${e}':`,o);}});},remove:e=>{M.delete(e);},off:(e,t)=>{let r=M.get(e);r&&r.delete(t);},clear:()=>{M.clear();},list:()=>Array.from(M.keys())};dphelper?.setDescription(an,ie);var sn={name:"type",active:true,subCommand:[{name:"of",version:"0.0.2",example:"dphelper.type.of(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Returns the type of the given parameter.",env:"both",subCommand:[]},{name:"instOfObj",version:"0.0.2",example:"dphelper.type.instOfObj(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is an instance of Object.",env:"both",subCommand:[]},{name:"isNaN",version:"0.0.2",example:"dphelper.type.isNaN(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is NaN.",env:"both",subCommand:[]},{name:"isBool",version:"0.0.2",example:"dphelper.type.isBool(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is a boolean.",env:"both",subCommand:[]}]},ln={of:e=>typeof e,instOfObj:e=>e instanceof Object,isNull:e=>t=>!e(t),isBool:e=>!e||e.length==null?true:e==="1"};dphelper?.setDescription(sn,ln);var cn={name:"UI",active:true,subCommand:[{name:"input",version:"0.0.2",example:"dphelper.UI.input(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Creates an input element with specified options.",env:"client",subCommand:[]},{name:"fps",version:"0.0.2",example:"dphelper.UI.fps(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle a real-time FPS and Memory monitor overlay",env:"client",subCommand:[]},{name:"boxModel",version:"0.0.2",example:"dphelper.UI.boxModel(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle visual box-model highlighter for all elements",env:"client",subCommand:[]},{name:"anchorContext",version:"0.0.1",example:"dphelper.UI.anchorContext()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Snapshot and auto-restore UI state (inputs, scroll) across reloads.",env:"client",subCommand:[]}]},dn={anchorContext:()=>{if(typeof window>"u"||typeof localStorage>"u")return;let e=`dp_anchor_${btoa(location.pathname).replace(/=/g,"")}`,t=()=>{let n={scroll:{x:window.scrollX,y:window.scrollY},inputs:Array.from(document.querySelectorAll("input, textarea, select")).filter(o=>o.type!=="password"&&!o.hasAttribute("data-private")&&o.getAttribute("autocomplete")!=="off").map(o=>({id:o.id,name:o.name,value:o.value}))};localStorage.setItem(e,JSON.stringify(n));},r=()=>{let n=localStorage.getItem(e);if(n)try{let o=JSON.parse(n);window.scrollTo(o.scroll.x,o.scroll.y),o.inputs.forEach(a=>{let i=a.id?document.getElementById(a.id):document.querySelector(`[name="${a.name}"]`);i&&(i.value=a.value);});}catch{console.warn("dphelper: anchorContext restoration failed.");}};window.addEventListener("beforeunload",t),r();},fps:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-fps-monitor");if(!e){t?.remove();return}t||(t=document.createElement("div"),t.id="dphelper-fps-monitor",Object.assign(t.style,{position:"fixed",top:"10px",right:"10px",padding:"8px 12px",background:"rgba(0,0,0,0.8)",color:"#0f0",fontFamily:"monospace",fontSize:"12px",zIndex:"99999",borderRadius:"4px",pointerEvents:"none",boxShadow:"0 2px 10px rgba(0,0,0,0.5)",border:"1px solid #333"}),document.body.appendChild(t));let r=0,n=performance.now(),o=()=>{if(!document.getElementById("dphelper-fps-monitor"))return;r++;let a=performance.now();if(a>=n+1e3){let i=Math.round(r*1e3/(a-n)),s=performance.memory?` | Mem: ${Math.round(performance.memory.usedJSHeapSize/1048576)}MB`:"";t.innerText=`FPS: ${i}${s}`,r=0,n=a;}requestAnimationFrame(o);};requestAnimationFrame(o);},boxModel:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-boxmodel-style");if(!e){t?.remove();return}t||(t=document.createElement("style"),t.id="dphelper-boxmodel-style",t.innerHTML=`
|
|
146
|
+
`,env:"both",subCommand:[],author:"Dario Passariello",creationDate:"20250612",lastMod:"20250612"},{name:"subString",version:"0.0.1",example:"dphelper.text.subString(text)",type:"function",active:true,description:"Length Of Longest Substring",env:"both",subCommand:[],author:"Dario Passariello",creationDate:"20260801",lastMod:"20260801"}]},Xr={trim:(e,t,r,n)=>e.charAt(0)===t?e.substring(r,n):e,capitalize:e=>e.toLowerCase().replace(/\b\w/g,t=>t.toUpperCase()),lower:e=>e.toLowerCase(),upper:e=>e.toUpperCase(),nl2br:e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/(?:\r\n|\r|\n)/g,"<br>"),sanitize:e=>e.replace(/<(|\/|[^>\bi]|\/[^>bi]|[^/>][^>]+|\/[^>][^>]+)>/g,""),camelCase:{toSpace:e=>e.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()),toUnderscore:e=>e.replace(/\.?([A-Z])/g,(t,r)=>`_${r.toLowerCase()}`).replace(/^_/,"")},fitContainer:e=>{if(!e)return;function t(r){let n=document.querySelectorAll(r),o=n.length;if(!(o<=0))for(let a=0;a<o;a++){let i=n[a].offsetWidth*.05;n[a].style.fontSize=`${i}px`;}}dphelper.addListenerMulti(window,"load resize",()=>t(e));},keywords:e=>{let t=/\b[A-Z][a-z]+\b/g,r=e.match(t)?.filter(n=>n.length>3)||[];return [...new Set(r.map(n=>n.toLowerCase()))]},replaceText:(e,t)=>{let r=e;for(let n in t)Object.hasOwn(t,n)&&(r=r.replaceAll(n,t[n]||""));return r},subString:e=>{let t=new Int32Array(65536);t.fill(-1);let r=0,n=0;for(let o=0;o<e.length;o++){let a=e.charCodeAt(o),i=t[a];r=r+(i-r+1&-(i>=r)),t[a]=o;let s=o-r+1;n=n+(s-n&-(s>n));}return n}};dphelper?.setDescription(Zr,Xr);var Qr={name:"timer",active:true,subCommand:[{name:"sleep",version:"0.0.2",example:"dphelper.timer.sleep([ms]) ",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Pauses execution for a specified number of milliseconds.",env:"both",subCommand:[]},{name:"percentage",version:"0.0.2",example:"dphelper.timer.percentage([start], [end])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Calculates the percentage of time elapsed between two time strings.",env:"both",subCommand:[]}]},en={sleep:e=>new Promise(t=>setTimeout(t,e)),percentage:(e,t)=>{function r(n){let o=n.split(":");return Number.parseInt(o[0]||"",10)*3600+Number.parseInt(o[1]||"",10)*60+Number.parseInt(o[2]||"",10)}return (100*r(e)/r(t)).toFixed(2)}};dphelper?.setDescription(Qr,en);var tn={name:"tools",active:true,subCommand:[{name:"byteSize",description:"Give you the total in 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb' starting from bytes",example:"dphelper.tools.byteSize(bytes)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"hashPass",description:"Hashes a password using a specified number and total.",example:"dphelper.tools.hashPass(number, total)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"zIndex",description:"Finds the highest z-index value in the document.",example:"dphelper.tools.zIndex()",version:"0.0.2",author:"Dario Passariello",creationDate:"20240807",lastMod:"20240807",type:"function",active:true,env:"both",subCommand:[]},{name:"zeroToFalse",description:"Converts zero to false, otherwise returns the value.",example:"dphelper.tools.zeroToFalse(num)",version:"0.0.2",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:true,env:"both",subCommand:[]}]},rn={byteSize:e=>{if(Math.abs(e)<1024)return `${e}b`;let r=["Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],n=-1,o=e;do o/=1024,++n;while(Math.abs(o)>=1024&&n<r.length-1);return o.toFixed(1)+r[n]},zIndex:()=>Array.from(document.querySelectorAll("body *")).map(e=>Number.parseFloat(getComputedStyle(e).zIndex)).reduce((e,t)=>t>e?t:e,1),zeroToFalse:e=>e===0?false:e};dphelper?.setDescription(tn,rn);var nn={name:"translators",active:true,subCommand:[{name:"convertMatrixToScale",version:"0.0.2",example:"dphelper.translators.convertMatrixToScale({value})",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Converts a transformation matrix to a scale value.",env:"both",subCommand:[]}]},on={convertMatrixToScale:e=>{let t=e.split("(");if(t.length<2)return 0;let r=t[1].split(")")[0];if(!r)return 0;let n=r.split(","),o=Number.parseFloat(n[0]||"0"),a=Number.parseFloat(n[1]||"0");return Math.sqrt(o*o+a*a)}};dphelper?.setDescription(nn,on);var an={name:"triggers",active:true,subCommand:[{name:"add",version:"0.0.1",example:"dphelper.triggers.add('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Add a trigger for custom events.",env:"client",subCommand:[]},{name:"on",version:"0.0.1",example:"dphelper.triggers.on('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Listen for a trigger event.",env:"client",subCommand:[]},{name:"emit",version:"0.0.1",example:"dphelper.triggers.emit('event', data)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Emit a trigger event.",env:"client",subCommand:[]},{name:"remove",version:"0.0.1",example:"dphelper.triggers.remove('event')",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Remove a trigger event.",env:"client",subCommand:[]}]},M=new Map,ie={add:(e,t)=>{M.has(e)||M.set(e,new Set),M.get(e).add(t);},on:(e,t)=>{ie.add(e,t);},emit:(e,...t)=>{let r=M.get(e);r&&r.forEach(n=>{try{n(...t);}catch(o){console.error(`Error in trigger callback for event '${e}':`,o);}});},remove:e=>{M.delete(e);},off:(e,t)=>{let r=M.get(e);r&&r.delete(t);},clear:()=>{M.clear();},list:()=>Array.from(M.keys())};dphelper?.setDescription(an,ie);var sn={name:"type",active:true,subCommand:[{name:"of",version:"0.0.2",example:"dphelper.type.of(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Returns the type of the given parameter.",env:"both",subCommand:[]},{name:"instOfObj",version:"0.0.2",example:"dphelper.type.instOfObj(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is an instance of Object.",env:"both",subCommand:[]},{name:"isNaN",version:"0.0.2",example:"dphelper.type.isNaN(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is NaN.",env:"both",subCommand:[]},{name:"isBool",version:"0.0.2",example:"dphelper.type.isBool(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is a boolean.",env:"both",subCommand:[]}]},ln={of:e=>typeof e,instOfObj:e=>e instanceof Object,isNull:e=>t=>!e(t),isBool:e=>!e||e.length==null?true:e==="1"};dphelper?.setDescription(sn,ln);var cn={name:"UI",active:true,subCommand:[{name:"input",version:"0.0.2",example:"dphelper.UI.input(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Creates an input element with specified options.",env:"client",subCommand:[]},{name:"fps",version:"0.0.2",example:"dphelper.UI.fps(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle a real-time FPS and Memory monitor overlay",env:"client",subCommand:[]},{name:"boxModel",version:"0.0.2",example:"dphelper.UI.boxModel(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle visual box-model highlighter for all elements",env:"client",subCommand:[]},{name:"anchorContext",version:"0.0.1",example:"dphelper.UI.anchorContext()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Snapshot and auto-restore UI state (inputs, scroll) across reloads.",env:"client",subCommand:[]}]},dn={anchorContext:()=>{if(typeof window>"u"||typeof localStorage>"u")return;let e=`dp_anchor_${btoa(location.pathname).replace(/=/g,"")}`,t=()=>{let n={scroll:{x:window.scrollX,y:window.scrollY},inputs:Array.from(document.querySelectorAll("input, textarea, select")).filter(o=>o.type!=="password"&&!o.hasAttribute("data-private")&&o.getAttribute("autocomplete")!=="off").map(o=>({id:o.id,name:o.name,value:o.value}))};localStorage.setItem(e,JSON.stringify(n));},r=()=>{let n=localStorage.getItem(e);if(n)try{let o=JSON.parse(n);window.scrollTo(o.scroll.x,o.scroll.y),o.inputs.forEach(a=>{let i=a.id?document.getElementById(a.id):document.querySelector(`[name="${a.name}"]`);i&&(i.value=a.value);});}catch{console.warn("dphelper: anchorContext restoration failed.");}};window.addEventListener("beforeunload",t),r();},fps:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-fps-monitor");if(!e){t?.remove();return}t||(t=document.createElement("div"),t.id="dphelper-fps-monitor",Object.assign(t.style,{position:"fixed",top:"10px",right:"10px",padding:"8px 12px",background:"rgba(0,0,0,0.8)",color:"#0f0",fontFamily:"monospace",fontSize:"12px",zIndex:"99999",borderRadius:"4px",pointerEvents:"none",boxShadow:"0 2px 10px rgba(0,0,0,0.5)",border:"1px solid #333"}),document.body.appendChild(t));let r=0,n=performance.now(),o=()=>{if(!document.getElementById("dphelper-fps-monitor"))return;r++;let a=performance.now();if(a>=n+1e3){let i=Math.round(r*1e3/(a-n)),s=performance.memory?` | Mem: ${Math.round(performance.memory.usedJSHeapSize/1048576)}MB`:"";t.innerText=`FPS: ${i}${s}`,r=0,n=a;}requestAnimationFrame(o);};requestAnimationFrame(o);},boxModel:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-boxmodel-style");if(!e){t?.remove();return}t||(t=document.createElement("style"),t.id="dphelper-boxmodel-style",t.innerHTML=`
|
|
147
147
|
* { outline: 1px solid rgba(255, 0, 0, 0.3) !important; }
|
|
148
148
|
* * { outline: 1px solid rgba(0, 255, 0, 0.3) !important; }
|
|
149
149
|
* * * { outline: 1px solid rgba(0, 0, 255, 0.3) !important; }
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var K={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var C={codeName:"dphelper",version:"4.
|
|
1
|
+
var K={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var C={codeName:"dphelper",version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...K},configurable:true,writable:true},version:{value:C.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var k=dphelper;Object.defineProperty(k,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(k,"setDescription",{value:(e,t)=>{Object.defineProperties(k,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(k[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),k.setProps(k,e,{writable:false,configurable:false,enumerable:false}),k._list.scripts.push(e);}});var pe={name:"ai",active:true,subCommand:[{name:"tokenCount",version:"0.0.3",example:"dphelper.ai.tokenCount({ users: [1,2,3] })",author:"Dario Passariello",creationDate:"20260220",lastMod:"20260221",type:"function",active:true,description:"Estimate token count for LLMs. If an object is passed, it uses TOON format for calculation.",env:"both",subCommand:[]},{name:"smartSanitize",version:"0.0.2",example:"dphelper.ai.smartSanitize('My email is test@example.com')",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Remove PII (emails, phones, etc) from text for AI privacy",subCommand:[]},{name:"toon",version:"0.0.1",example:"dphelper.ai.toon({ users: [{id: 1, name: 'Ada'}] })",author:"TOON + Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert JSON to TOON format (Token-Oriented Object Notation)",subCommand:[]},{name:"toonToJson",version:"0.0.1",example:"dphelper.ai.toonToJson('users[1]{id,name}:\\n 1,Ada')",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert TOON format back to JSON/Object",subCommand:[]},{name:"chunker",version:"0.0.1",example:"dphelper.ai.chunker(text, { size: 1000, overlap: 200 })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Split long text into chunks for RAG or AI processing.",subCommand:[]},{name:"similarity",version:"0.0.1",example:"dphelper.ai.similarity(vecA, vecB)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Calculate cosine similarity between two embedding vectors.",subCommand:[]},{name:"extractReasoning",version:"0.0.1",example:"dphelper.ai.extractReasoning(aiResponse)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Extract <think> tags or internal reasoning from AI responses.",subCommand:[]},{name:"prompt",version:"0.0.1",example:"dphelper.ai.prompt('Hello {{name}}', { name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Simple prompt template engine with variable injection.",subCommand:[]},{name:"schema",version:"0.0.1",example:"dphelper.ai.schema({ id: 1, name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Generate a TOON-style schema definition for AI instructions.",subCommand:[]},{name:"snapshot",version:"0.0.1",example:"dphelper.ai.snapshot()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Capture a 'mental snapshot' of the app state (logs/globals) in TOON format for AI debugging.",env:"both",subCommand:[]}]},W=e=>e===null||typeof e!="object",U=e=>e===null?"null":typeof e=="string"?e.includes(",")||e.includes(":")||e.includes('"')||e.includes(`
|
|
2
2
|
`)||e.trim()!==e?`"${e.replace(/"/g,'\\"')}"`:e||'""':String(e),$=(e,t=0)=>{let r=" ".repeat(t);if(W(e))return U(e);if(Array.isArray(e)){if(e.length===0)return "[0]:";let n=e[0];if(!W(n)&&!Array.isArray(n)){let o=Object.keys(n),a=`[${e.length}]{${o.join(",")}}:`;for(let i of e){let s=o.map(l=>U(i[l])).join(",");a+=`
|
|
3
3
|
${r} ${s}`;}return a}else return `[${e.length}]: `+e.map(U).join(",")}else return Object.entries(e).map(([n,o])=>{let a=n.includes(" ")||n.includes(":")?`"${n}"`:n;if(!W(o)){let i=$(o,t+1);return i.startsWith("[")?`${a}${i}`:`${a}:
|
|
4
4
|
${r}${i}`}return `${a}: ${U(o)}`}).join(`
|
|
@@ -143,7 +143,7 @@ ${t(i,`${n} `)}${n}</${a}>
|
|
|
143
143
|
)
|
|
144
144
|
|
|
145
145
|
Copyright text (c) became an html symbol
|
|
146
|
-
`,env:"both",subCommand:[],author:"Dario Passariello",creationDate:"20250612",lastMod:"20250612"}]},Qr={trim:(e,t,r,n)=>e.charAt(0)===t?e.substring(r,n):e,capitalize:e=>e.toLowerCase().replace(/\b\w/g,t=>t.toUpperCase()),lower:e=>e.toLowerCase(),upper:e=>e.toUpperCase(),nl2br:e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/(?:\r\n|\r|\n)/g,"<br>"),sanitize:e=>e.replace(/<(|\/|[^>\bi]|\/[^>bi]|[^/>][^>]+|\/[^>][^>]+)>/g,""),camelCase:{toSpace:e=>e.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()),toUnderscore:e=>e.replace(/\.?([A-Z])/g,(t,r)=>`_${r.toLowerCase()}`).replace(/^_/,"")},fitContainer:e=>{if(!e)return;function t(r){let n=document.querySelectorAll(r),o=n.length;if(!(o<=0))for(let a=0;a<o;a++){let i=n[a].offsetWidth*.05;n[a].style.fontSize=`${i}px`;}}dphelper.addListenerMulti(window,"load resize",()=>t(e));},keywords:e=>{let t=/\b[A-Z][a-z]+\b/g,r=e.match(t)?.filter(n=>n.length>3)||[];return [...new Set(r.map(n=>n.toLowerCase()))]},replaceText:(e,t)=>{let r=e;for(let n in t)Object.hasOwn(t,n)&&(r=r.replaceAll(n,t[n]||""));return r}};dphelper?.setDescription(Xr,Qr);var en={name:"timer",active:true,subCommand:[{name:"sleep",version:"0.0.2",example:"dphelper.timer.sleep([ms]) ",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Pauses execution for a specified number of milliseconds.",env:"both",subCommand:[]},{name:"percentage",version:"0.0.2",example:"dphelper.timer.percentage([start], [end])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Calculates the percentage of time elapsed between two time strings.",env:"both",subCommand:[]}]},tn={sleep:e=>new Promise(t=>setTimeout(t,e)),percentage:(e,t)=>{function r(n){let o=n.split(":");return Number.parseInt(o[0]||"",10)*3600+Number.parseInt(o[1]||"",10)*60+Number.parseInt(o[2]||"",10)}return (100*r(e)/r(t)).toFixed(2)}};dphelper?.setDescription(en,tn);var rn={name:"tools",active:true,subCommand:[{name:"byteSize",description:"Give you the total in 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb' starting from bytes",example:"dphelper.tools.byteSize(bytes)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"hashPass",description:"Hashes a password using a specified number and total.",example:"dphelper.tools.hashPass(number, total)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"zIndex",description:"Finds the highest z-index value in the document.",example:"dphelper.tools.zIndex()",version:"0.0.2",author:"Dario Passariello",creationDate:"20240807",lastMod:"20240807",type:"function",active:true,env:"both",subCommand:[]},{name:"zeroToFalse",description:"Converts zero to false, otherwise returns the value.",example:"dphelper.tools.zeroToFalse(num)",version:"0.0.2",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:true,env:"both",subCommand:[]}]},nn={byteSize:e=>{if(Math.abs(e)<1024)return `${e}b`;let r=["Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],n=-1,o=e;do o/=1024,++n;while(Math.abs(o)>=1024&&n<r.length-1);return o.toFixed(1)+r[n]},zIndex:()=>Array.from(document.querySelectorAll("body *")).map(e=>Number.parseFloat(getComputedStyle(e).zIndex)).reduce((e,t)=>t>e?t:e,1),zeroToFalse:e=>e===0?false:e};dphelper?.setDescription(rn,nn);var on={name:"translators",active:true,subCommand:[{name:"convertMatrixToScale",version:"0.0.2",example:"dphelper.translators.convertMatrixToScale({value})",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Converts a transformation matrix to a scale value.",env:"both",subCommand:[]}]},an={convertMatrixToScale:e=>{let t=e.split("(");if(t.length<2)return 0;let r=t[1].split(")")[0];if(!r)return 0;let n=r.split(","),o=Number.parseFloat(n[0]||"0"),a=Number.parseFloat(n[1]||"0");return Math.sqrt(o*o+a*a)}};dphelper?.setDescription(on,an);var sn={name:"triggers",active:true,subCommand:[{name:"add",version:"0.0.1",example:"dphelper.triggers.add('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Add a trigger for custom events.",env:"client",subCommand:[]},{name:"on",version:"0.0.1",example:"dphelper.triggers.on('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Listen for a trigger event.",env:"client",subCommand:[]},{name:"emit",version:"0.0.1",example:"dphelper.triggers.emit('event', data)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Emit a trigger event.",env:"client",subCommand:[]},{name:"remove",version:"0.0.1",example:"dphelper.triggers.remove('event')",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Remove a trigger event.",env:"client",subCommand:[]}]},S=new Map,se={add:(e,t)=>{S.has(e)||S.set(e,new Set),S.get(e).add(t);},on:(e,t)=>{se.add(e,t);},emit:(e,...t)=>{let r=S.get(e);r&&r.forEach(n=>{try{n(...t);}catch(o){console.error(`Error in trigger callback for event '${e}':`,o);}});},remove:e=>{S.delete(e);},off:(e,t)=>{let r=S.get(e);r&&r.delete(t);},clear:()=>{S.clear();},list:()=>Array.from(S.keys())};dphelper?.setDescription(sn,se);var ln={name:"type",active:true,subCommand:[{name:"of",version:"0.0.2",example:"dphelper.type.of(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Returns the type of the given parameter.",env:"both",subCommand:[]},{name:"instOfObj",version:"0.0.2",example:"dphelper.type.instOfObj(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is an instance of Object.",env:"both",subCommand:[]},{name:"isNaN",version:"0.0.2",example:"dphelper.type.isNaN(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is NaN.",env:"both",subCommand:[]},{name:"isBool",version:"0.0.2",example:"dphelper.type.isBool(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is a boolean.",env:"both",subCommand:[]}]},cn={of:e=>typeof e,instOfObj:e=>e instanceof Object,isNull:e=>t=>!e(t),isBool:e=>!e||e.length==null?true:e==="1"};dphelper?.setDescription(ln,cn);var dn={name:"UI",active:true,subCommand:[{name:"input",version:"0.0.2",example:"dphelper.UI.input(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Creates an input element with specified options.",env:"client",subCommand:[]},{name:"fps",version:"0.0.2",example:"dphelper.UI.fps(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle a real-time FPS and Memory monitor overlay",env:"client",subCommand:[]},{name:"boxModel",version:"0.0.2",example:"dphelper.UI.boxModel(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle visual box-model highlighter for all elements",env:"client",subCommand:[]},{name:"anchorContext",version:"0.0.1",example:"dphelper.UI.anchorContext()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Snapshot and auto-restore UI state (inputs, scroll) across reloads.",env:"client",subCommand:[]}]},un={anchorContext:()=>{if(typeof window>"u"||typeof localStorage>"u")return;let e=`dp_anchor_${btoa(location.pathname).replace(/=/g,"")}`,t=()=>{let n={scroll:{x:window.scrollX,y:window.scrollY},inputs:Array.from(document.querySelectorAll("input, textarea, select")).filter(o=>o.type!=="password"&&!o.hasAttribute("data-private")&&o.getAttribute("autocomplete")!=="off").map(o=>({id:o.id,name:o.name,value:o.value}))};localStorage.setItem(e,JSON.stringify(n));},r=()=>{let n=localStorage.getItem(e);if(n)try{let o=JSON.parse(n);window.scrollTo(o.scroll.x,o.scroll.y),o.inputs.forEach(a=>{let i=a.id?document.getElementById(a.id):document.querySelector(`[name="${a.name}"]`);i&&(i.value=a.value);});}catch{console.warn("dphelper: anchorContext restoration failed.");}};window.addEventListener("beforeunload",t),r();},fps:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-fps-monitor");if(!e){t?.remove();return}t||(t=document.createElement("div"),t.id="dphelper-fps-monitor",Object.assign(t.style,{position:"fixed",top:"10px",right:"10px",padding:"8px 12px",background:"rgba(0,0,0,0.8)",color:"#0f0",fontFamily:"monospace",fontSize:"12px",zIndex:"99999",borderRadius:"4px",pointerEvents:"none",boxShadow:"0 2px 10px rgba(0,0,0,0.5)",border:"1px solid #333"}),document.body.appendChild(t));let r=0,n=performance.now(),o=()=>{if(!document.getElementById("dphelper-fps-monitor"))return;r++;let a=performance.now();if(a>=n+1e3){let i=Math.round(r*1e3/(a-n)),s=performance.memory?` | Mem: ${Math.round(performance.memory.usedJSHeapSize/1048576)}MB`:"";t.innerText=`FPS: ${i}${s}`,r=0,n=a;}requestAnimationFrame(o);};requestAnimationFrame(o);},boxModel:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-boxmodel-style");if(!e){t?.remove();return}t||(t=document.createElement("style"),t.id="dphelper-boxmodel-style",t.innerHTML=`
|
|
146
|
+
`,env:"both",subCommand:[],author:"Dario Passariello",creationDate:"20250612",lastMod:"20250612"},{name:"subString",version:"0.0.1",example:"dphelper.text.subString(text)",type:"function",active:true,description:"Length Of Longest Substring",env:"both",subCommand:[],author:"Dario Passariello",creationDate:"20260801",lastMod:"20260801"}]},Qr={trim:(e,t,r,n)=>e.charAt(0)===t?e.substring(r,n):e,capitalize:e=>e.toLowerCase().replace(/\b\w/g,t=>t.toUpperCase()),lower:e=>e.toLowerCase(),upper:e=>e.toUpperCase(),nl2br:e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/(?:\r\n|\r|\n)/g,"<br>"),sanitize:e=>e.replace(/<(|\/|[^>\bi]|\/[^>bi]|[^/>][^>]+|\/[^>][^>]+)>/g,""),camelCase:{toSpace:e=>e.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()),toUnderscore:e=>e.replace(/\.?([A-Z])/g,(t,r)=>`_${r.toLowerCase()}`).replace(/^_/,"")},fitContainer:e=>{if(!e)return;function t(r){let n=document.querySelectorAll(r),o=n.length;if(!(o<=0))for(let a=0;a<o;a++){let i=n[a].offsetWidth*.05;n[a].style.fontSize=`${i}px`;}}dphelper.addListenerMulti(window,"load resize",()=>t(e));},keywords:e=>{let t=/\b[A-Z][a-z]+\b/g,r=e.match(t)?.filter(n=>n.length>3)||[];return [...new Set(r.map(n=>n.toLowerCase()))]},replaceText:(e,t)=>{let r=e;for(let n in t)Object.hasOwn(t,n)&&(r=r.replaceAll(n,t[n]||""));return r},subString:e=>{let t=new Int32Array(65536);t.fill(-1);let r=0,n=0;for(let o=0;o<e.length;o++){let a=e.charCodeAt(o),i=t[a];r=r+(i-r+1&-(i>=r)),t[a]=o;let s=o-r+1;n=n+(s-n&-(s>n));}return n}};dphelper?.setDescription(Xr,Qr);var en={name:"timer",active:true,subCommand:[{name:"sleep",version:"0.0.2",example:"dphelper.timer.sleep([ms]) ",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Pauses execution for a specified number of milliseconds.",env:"both",subCommand:[]},{name:"percentage",version:"0.0.2",example:"dphelper.timer.percentage([start], [end])",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Calculates the percentage of time elapsed between two time strings.",env:"both",subCommand:[]}]},tn={sleep:e=>new Promise(t=>setTimeout(t,e)),percentage:(e,t)=>{function r(n){let o=n.split(":");return Number.parseInt(o[0]||"",10)*3600+Number.parseInt(o[1]||"",10)*60+Number.parseInt(o[2]||"",10)}return (100*r(e)/r(t)).toFixed(2)}};dphelper?.setDescription(en,tn);var rn={name:"tools",active:true,subCommand:[{name:"byteSize",description:"Give you the total in 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb' starting from bytes",example:"dphelper.tools.byteSize(bytes)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"hashPass",description:"Hashes a password using a specified number and total.",example:"dphelper.tools.hashPass(number, total)",version:"0.0.2",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"zIndex",description:"Finds the highest z-index value in the document.",example:"dphelper.tools.zIndex()",version:"0.0.2",author:"Dario Passariello",creationDate:"20240807",lastMod:"20240807",type:"function",active:true,env:"both",subCommand:[]},{name:"zeroToFalse",description:"Converts zero to false, otherwise returns the value.",example:"dphelper.tools.zeroToFalse(num)",version:"0.0.2",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:true,env:"both",subCommand:[]}]},nn={byteSize:e=>{if(Math.abs(e)<1024)return `${e}b`;let r=["Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],n=-1,o=e;do o/=1024,++n;while(Math.abs(o)>=1024&&n<r.length-1);return o.toFixed(1)+r[n]},zIndex:()=>Array.from(document.querySelectorAll("body *")).map(e=>Number.parseFloat(getComputedStyle(e).zIndex)).reduce((e,t)=>t>e?t:e,1),zeroToFalse:e=>e===0?false:e};dphelper?.setDescription(rn,nn);var on={name:"translators",active:true,subCommand:[{name:"convertMatrixToScale",version:"0.0.2",example:"dphelper.translators.convertMatrixToScale({value})",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Converts a transformation matrix to a scale value.",env:"both",subCommand:[]}]},an={convertMatrixToScale:e=>{let t=e.split("(");if(t.length<2)return 0;let r=t[1].split(")")[0];if(!r)return 0;let n=r.split(","),o=Number.parseFloat(n[0]||"0"),a=Number.parseFloat(n[1]||"0");return Math.sqrt(o*o+a*a)}};dphelper?.setDescription(on,an);var sn={name:"triggers",active:true,subCommand:[{name:"add",version:"0.0.1",example:"dphelper.triggers.add('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Add a trigger for custom events.",env:"client",subCommand:[]},{name:"on",version:"0.0.1",example:"dphelper.triggers.on('event', callback)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Listen for a trigger event.",env:"client",subCommand:[]},{name:"emit",version:"0.0.1",example:"dphelper.triggers.emit('event', data)",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Emit a trigger event.",env:"client",subCommand:[]},{name:"remove",version:"0.0.1",example:"dphelper.triggers.remove('event')",author:"Dario Passariello",creationDate:"20250220",lastMod:"20250220",type:"function",active:true,description:"Remove a trigger event.",env:"client",subCommand:[]}]},S=new Map,se={add:(e,t)=>{S.has(e)||S.set(e,new Set),S.get(e).add(t);},on:(e,t)=>{se.add(e,t);},emit:(e,...t)=>{let r=S.get(e);r&&r.forEach(n=>{try{n(...t);}catch(o){console.error(`Error in trigger callback for event '${e}':`,o);}});},remove:e=>{S.delete(e);},off:(e,t)=>{let r=S.get(e);r&&r.delete(t);},clear:()=>{S.clear();},list:()=>Array.from(S.keys())};dphelper?.setDescription(sn,se);var ln={name:"type",active:true,subCommand:[{name:"of",version:"0.0.2",example:"dphelper.type.of(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Returns the type of the given parameter.",env:"both",subCommand:[]},{name:"instOfObj",version:"0.0.2",example:"dphelper.type.instOfObj(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is an instance of Object.",env:"both",subCommand:[]},{name:"isNaN",version:"0.0.2",example:"dphelper.type.isNaN(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is NaN.",env:"both",subCommand:[]},{name:"isBool",version:"0.0.2",example:"dphelper.type.isBool(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Checks if the given parameter is a boolean.",env:"both",subCommand:[]}]},cn={of:e=>typeof e,instOfObj:e=>e instanceof Object,isNull:e=>t=>!e(t),isBool:e=>!e||e.length==null?true:e==="1"};dphelper?.setDescription(ln,cn);var dn={name:"UI",active:true,subCommand:[{name:"input",version:"0.0.2",example:"dphelper.UI.input(...)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Creates an input element with specified options.",env:"client",subCommand:[]},{name:"fps",version:"0.0.2",example:"dphelper.UI.fps(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle a real-time FPS and Memory monitor overlay",env:"client",subCommand:[]},{name:"boxModel",version:"0.0.2",example:"dphelper.UI.boxModel(true)",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Toggle visual box-model highlighter for all elements",env:"client",subCommand:[]},{name:"anchorContext",version:"0.0.1",example:"dphelper.UI.anchorContext()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Snapshot and auto-restore UI state (inputs, scroll) across reloads.",env:"client",subCommand:[]}]},un={anchorContext:()=>{if(typeof window>"u"||typeof localStorage>"u")return;let e=`dp_anchor_${btoa(location.pathname).replace(/=/g,"")}`,t=()=>{let n={scroll:{x:window.scrollX,y:window.scrollY},inputs:Array.from(document.querySelectorAll("input, textarea, select")).filter(o=>o.type!=="password"&&!o.hasAttribute("data-private")&&o.getAttribute("autocomplete")!=="off").map(o=>({id:o.id,name:o.name,value:o.value}))};localStorage.setItem(e,JSON.stringify(n));},r=()=>{let n=localStorage.getItem(e);if(n)try{let o=JSON.parse(n);window.scrollTo(o.scroll.x,o.scroll.y),o.inputs.forEach(a=>{let i=a.id?document.getElementById(a.id):document.querySelector(`[name="${a.name}"]`);i&&(i.value=a.value);});}catch{console.warn("dphelper: anchorContext restoration failed.");}};window.addEventListener("beforeunload",t),r();},fps:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-fps-monitor");if(!e){t?.remove();return}t||(t=document.createElement("div"),t.id="dphelper-fps-monitor",Object.assign(t.style,{position:"fixed",top:"10px",right:"10px",padding:"8px 12px",background:"rgba(0,0,0,0.8)",color:"#0f0",fontFamily:"monospace",fontSize:"12px",zIndex:"99999",borderRadius:"4px",pointerEvents:"none",boxShadow:"0 2px 10px rgba(0,0,0,0.5)",border:"1px solid #333"}),document.body.appendChild(t));let r=0,n=performance.now(),o=()=>{if(!document.getElementById("dphelper-fps-monitor"))return;r++;let a=performance.now();if(a>=n+1e3){let i=Math.round(r*1e3/(a-n)),s=performance.memory?` | Mem: ${Math.round(performance.memory.usedJSHeapSize/1048576)}MB`:"";t.innerText=`FPS: ${i}${s}`,r=0,n=a;}requestAnimationFrame(o);};requestAnimationFrame(o);},boxModel:(e=true)=>{if(typeof document>"u")return;let t=document.getElementById("dphelper-boxmodel-style");if(!e){t?.remove();return}t||(t=document.createElement("style"),t.id="dphelper-boxmodel-style",t.innerHTML=`
|
|
147
147
|
* { outline: 1px solid rgba(255, 0, 0, 0.3) !important; }
|
|
148
148
|
* * { outline: 1px solid rgba(0, 255, 0, 0.3) !important; }
|
|
149
149
|
* * * { outline: 1px solid rgba(0, 0, 255, 0.3) !important; }
|
package/modules/ai.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var P={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var v={version:"4.
|
|
1
|
+
'use strict';var P={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var v={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...P},configurable:true,writable:true},version:{value:v.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var f=dphelper;Object.defineProperty(f,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(f,"setDescription",{value:(e,t)=>{Object.defineProperties(f,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(f[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),f.setProps(f,e,{writable:false,configurable:false,enumerable:false}),f._list.scripts.push(e);}});var M={name:"ai",active:true,subCommand:[{name:"tokenCount",version:"0.0.3",example:"dphelper.ai.tokenCount({ users: [1,2,3] })",author:"Dario Passariello",creationDate:"20260220",lastMod:"20260221",type:"function",active:true,description:"Estimate token count for LLMs. If an object is passed, it uses TOON format for calculation.",env:"both",subCommand:[]},{name:"smartSanitize",version:"0.0.2",example:"dphelper.ai.smartSanitize('My email is test@example.com')",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Remove PII (emails, phones, etc) from text for AI privacy",subCommand:[]},{name:"toon",version:"0.0.1",example:"dphelper.ai.toon({ users: [{id: 1, name: 'Ada'}] })",author:"TOON + Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert JSON to TOON format (Token-Oriented Object Notation)",subCommand:[]},{name:"toonToJson",version:"0.0.1",example:"dphelper.ai.toonToJson('users[1]{id,name}:\\n 1,Ada')",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert TOON format back to JSON/Object",subCommand:[]},{name:"chunker",version:"0.0.1",example:"dphelper.ai.chunker(text, { size: 1000, overlap: 200 })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Split long text into chunks for RAG or AI processing.",subCommand:[]},{name:"similarity",version:"0.0.1",example:"dphelper.ai.similarity(vecA, vecB)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Calculate cosine similarity between two embedding vectors.",subCommand:[]},{name:"extractReasoning",version:"0.0.1",example:"dphelper.ai.extractReasoning(aiResponse)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Extract <think> tags or internal reasoning from AI responses.",subCommand:[]},{name:"prompt",version:"0.0.1",example:"dphelper.ai.prompt('Hello {{name}}', { name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Simple prompt template engine with variable injection.",subCommand:[]},{name:"schema",version:"0.0.1",example:"dphelper.ai.schema({ id: 1, name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Generate a TOON-style schema definition for AI instructions.",subCommand:[]},{name:"snapshot",version:"0.0.1",example:"dphelper.ai.snapshot()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Capture a 'mental snapshot' of the app state (logs/globals) in TOON format for AI debugging.",env:"both",subCommand:[]}]},x=e=>e===null||typeof e!="object",O=e=>e===null?"null":typeof e=="string"?e.includes(",")||e.includes(":")||e.includes('"')||e.includes(`
|
|
2
2
|
`)||e.trim()!==e?`"${e.replace(/"/g,'\\"')}"`:e||'""':String(e),b=(e,t=0)=>{let r=" ".repeat(t);if(x(e))return O(e);if(Array.isArray(e)){if(e.length===0)return "[0]:";let n=e[0];if(!x(n)&&!Array.isArray(n)){let s=Object.keys(n),o=`[${e.length}]{${s.join(",")}}:`;for(let i of e){let u=s.map(a=>O(i[a])).join(",");o+=`
|
|
3
3
|
${r} ${u}`;}return o}else return `[${e.length}]: `+e.map(O).join(",")}else return Object.entries(e).map(([n,s])=>{let o=n.includes(" ")||n.includes(":")?`"${n}"`:n;if(!x(s)){let i=b(s,t+1);return i.startsWith("[")?`${o}${i}`:`${o}:
|
|
4
4
|
${r}${i}`}return `${o}: ${O(s)}`}).join(`
|
package/modules/ai.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var v={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var $={version:"4.
|
|
1
|
+
var v={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var $={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...v},configurable:true,writable:true},version:{value:$.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var f=dphelper;Object.defineProperty(f,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(f,"setDescription",{value:(e,t)=>{Object.defineProperties(f,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(f[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),f.setProps(f,e,{writable:false,configurable:false,enumerable:false}),f._list.scripts.push(e);}});var N={name:"ai",active:true,subCommand:[{name:"tokenCount",version:"0.0.3",example:"dphelper.ai.tokenCount({ users: [1,2,3] })",author:"Dario Passariello",creationDate:"20260220",lastMod:"20260221",type:"function",active:true,description:"Estimate token count for LLMs. If an object is passed, it uses TOON format for calculation.",env:"both",subCommand:[]},{name:"smartSanitize",version:"0.0.2",example:"dphelper.ai.smartSanitize('My email is test@example.com')",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Remove PII (emails, phones, etc) from text for AI privacy",subCommand:[]},{name:"toon",version:"0.0.1",example:"dphelper.ai.toon({ users: [{id: 1, name: 'Ada'}] })",author:"TOON + Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert JSON to TOON format (Token-Oriented Object Notation)",subCommand:[]},{name:"toonToJson",version:"0.0.1",example:"dphelper.ai.toonToJson('users[1]{id,name}:\\n 1,Ada')",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert TOON format back to JSON/Object",subCommand:[]},{name:"chunker",version:"0.0.1",example:"dphelper.ai.chunker(text, { size: 1000, overlap: 200 })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Split long text into chunks for RAG or AI processing.",subCommand:[]},{name:"similarity",version:"0.0.1",example:"dphelper.ai.similarity(vecA, vecB)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Calculate cosine similarity between two embedding vectors.",subCommand:[]},{name:"extractReasoning",version:"0.0.1",example:"dphelper.ai.extractReasoning(aiResponse)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Extract <think> tags or internal reasoning from AI responses.",subCommand:[]},{name:"prompt",version:"0.0.1",example:"dphelper.ai.prompt('Hello {{name}}', { name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Simple prompt template engine with variable injection.",subCommand:[]},{name:"schema",version:"0.0.1",example:"dphelper.ai.schema({ id: 1, name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Generate a TOON-style schema definition for AI instructions.",subCommand:[]},{name:"snapshot",version:"0.0.1",example:"dphelper.ai.snapshot()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Capture a 'mental snapshot' of the app state (logs/globals) in TOON format for AI debugging.",env:"both",subCommand:[]}]},A=e=>e===null||typeof e!="object",O=e=>e===null?"null":typeof e=="string"?e.includes(",")||e.includes(":")||e.includes('"')||e.includes(`
|
|
2
2
|
`)||e.trim()!==e?`"${e.replace(/"/g,'\\"')}"`:e||'""':String(e),b=(e,t=0)=>{let r=" ".repeat(t);if(A(e))return O(e);if(Array.isArray(e)){if(e.length===0)return "[0]:";let n=e[0];if(!A(n)&&!Array.isArray(n)){let s=Object.keys(n),o=`[${e.length}]{${s.join(",")}}:`;for(let i of e){let u=s.map(a=>O(i[a])).join(",");o+=`
|
|
3
3
|
${r} ${u}`;}return o}else return `[${e.length}]: `+e.map(O).join(",")}else return Object.entries(e).map(([n,s])=>{let o=n.includes(" ")||n.includes(":")?`"${n}"`:n;if(!A(s)){let i=b(s,t+1);return i.startsWith("[")?`${o}${i}`:`${o}:
|
|
4
4
|
${r}${i}`}return `${o}: ${O(s)}`}).join(`
|
package/modules/anchor.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var p={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var c={version:"4.
|
|
1
|
+
'use strict';var p={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var c={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...p},configurable:true,writable:true},version:{value:c.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var r=dphelper;Object.defineProperty(r,"setProps",{value:(e,t,a)=>{Object.defineProperty(e,t.name,a||{writable:false,configurable:false,enumerable:false}),a?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(r,"setDescription",{value:(e,t)=>{Object.defineProperties(r,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(a=>(Object.defineProperties(r[e.name],{[a]:{writable:false,configurable:false,enumerable:false}}),null)),r.setProps(r,e,{writable:false,configurable:false,enumerable:false}),r._list.scripts.push(e);}});var b={name:"anchor",active:true,subCommand:[{name:"toOnClick",type:"function",version:"0.0.2",example:"dphelper.anchor.toOnClick([element, 'foo' | '.foo' | '#foo'])",description:`This tool allows you to convert all links in an element to 'onclick'.
|
|
2
2
|
It allows you to avoid the message with the path relative to the requested address
|
|
3
3
|
and it is very useful when you work with SPA but you want to keep even older browsers.`,author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",active:true,env:"client",subCommand:[]}]},d={toOnClick:e=>{let t=document.querySelector(e);if(!t)return;t.querySelectorAll("a").forEach(o=>{let l=o.getAttribute("href");if(!l)return;o.style.cursor="pointer";let n=dphelper.pathRail()?.[3]?.replace(/\//g,"")||"";n&&o.classList.add(n);let s=o.cloneNode(true);o.parentNode?.replaceChild(s,o),s.removeAttribute("href"),s.addEventListener("mouseup",u=>{l.startsWith("/")?(history.pushState({href:l},"",l),dphelper.navigation.load(l),u.stopPropagation()):dphelper.browser.href(l);});});}};dphelper?.setDescription(b,d);var A=dphelper.anchor;
|
|
4
4
|
exports.anchor=A;
|
package/modules/anchor.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var c={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var u={version:"4.
|
|
1
|
+
var c={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var u={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...c},configurable:true,writable:true},version:{value:u.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var r=dphelper;Object.defineProperty(r,"setProps",{value:(e,t,a)=>{Object.defineProperty(e,t.name,a||{writable:false,configurable:false,enumerable:false}),a?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(r,"setDescription",{value:(e,t)=>{Object.defineProperties(r,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(a=>(Object.defineProperties(r[e.name],{[a]:{writable:false,configurable:false,enumerable:false}}),null)),r.setProps(r,e,{writable:false,configurable:false,enumerable:false}),r._list.scripts.push(e);}});var d={name:"anchor",active:true,subCommand:[{name:"toOnClick",type:"function",version:"0.0.2",example:"dphelper.anchor.toOnClick([element, 'foo' | '.foo' | '#foo'])",description:`This tool allows you to convert all links in an element to 'onclick'.
|
|
2
2
|
It allows you to avoid the message with the path relative to the requested address
|
|
3
3
|
and it is very useful when you work with SPA but you want to keep even older browsers.`,author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",active:true,env:"client",subCommand:[]}]},m={toOnClick:e=>{let t=document.querySelector(e);if(!t)return;t.querySelectorAll("a").forEach(o=>{let l=o.getAttribute("href");if(!l)return;o.style.cursor="pointer";let p=dphelper.pathRail()?.[3]?.replace(/\//g,"")||"";p&&o.classList.add(p);let s=o.cloneNode(true);o.parentNode?.replaceChild(s,o),s.removeAttribute("href"),s.addEventListener("mouseup",h=>{l.startsWith("/")?(history.pushState({href:l},"",l),dphelper.navigation.load(l),h.stopPropagation()):dphelper.browser.href(l);});});}};dphelper?.setDescription(d,m);var D=dphelper.anchor;
|
|
4
4
|
export{D as anchor};
|
package/modules/array.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var c={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var p={version:"4.
|
|
1
|
+
'use strict';var c={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var p={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...c},configurable:true,writable:true},version:{value:p.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var i=dphelper;Object.defineProperty(i,"setProps",{value:(e,a,r)=>{Object.defineProperty(e,a.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[a.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(i,"setDescription",{value:(e,a)=>{Object.defineProperties(i,{[e.name]:{value:a,writable:false,configurable:false,enumerable:false}}),Object.keys(a).map(r=>(Object.defineProperties(i[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),i.setProps(i,e,{writable:false,configurable:false,enumerable:false}),i._list.scripts.push(e);}});var f={name:"array",active:true,subCommand:[{name:"find",version:"0.0.2",example:"dphelper.array.find(array, 'key')",description:"Find an item in the array recursively.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"delete",version:"0.0.2",example:"dphelper.array.delete(array, 'key')",description:"Delete an item from the array recursively.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"unique",version:"0.0.2",example:"dphelper.array.unique(array)",description:"Remove duplicate values from an array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"merge",version:"0.0.2",example:"dphelper.array.merge(arrA, arrB)",description:"Merge two arrays into one.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"mergeByKey",version:"0.0.2",example:"dphelper.array.mergeByKey(arrA, arrB, 'id')",author:"Dario Passariello",creationDate:"20230603",lastMod:"20260220",type:"function",active:true,description:"Merge two arrays of objects by a specific key.",env:"both",subCommand:[]},{name:"asc",version:"0.0.2",example:"dphelper.array.asc(array)",description:"Sort array in ascending order.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"desc",version:"0.0.2",example:"dphelper.array.desc(array)",description:"Sort array in descending order.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"duplicates",version:"0.0.2",example:"dphelper.array.duplicates(array)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Find duplicate items in an array.",env:"both",subCommand:[]},{name:"even",version:"0.0.2",example:"dphelper.array.even(array)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Filter even numbers from an array.",env:"both",subCommand:[]},{name:"odd",version:"0.0.2",example:"dphelper.array.odd(array)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Filter odd numbers from an array.",env:"both",subCommand:[]},{name:"toObj",version:"0.0.2",example:"dphelper.array.toObj(array)",description:"Convert an array to an object.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"sumColumn",version:"0.0.2",example:"dphelper.array.sumColumn(arr, 0)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Sum the values of a specified column in a multidimensional array.",env:"both",subCommand:[]},{name:"shuffle",version:"0.0.2",example:"dphelper.array.shuffle(array)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Randomly shuffle the elements of an array.",env:"both",subCommand:[]},{name:"generate",version:"0.0.2",example:"dphelper.array.generate(10)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Generate an array of random numbers (max 500000).",env:"both",subCommand:[]},{name:"testArrayInt",version:"0.0.2",example:"dphelper.array.testArrayInt([1,2,4])",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Check if an array contains consecutive integers.",env:"both",subCommand:[]},{name:"rand32",version:"0.0.2",example:"dphelper.array.rand32(5)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Generate an array of random 32-bit unsigned integers.",env:"both",subCommand:[]},{name:"findindex",version:"0.0.2",example:"dphelper.array.findindex(array, 'name')",description:"Find the index of an item in an array by key.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"pathToJson",version:"0.0.2",example:"dphelper.array.pathToJson(paths, '/')",description:"Convert an array of paths into a JSON object.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"deepClone",version:"0.0.2",example:"dphelper.array.deepClone(array)",description:"Create a deep clone of an array using structuredClone.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"match",version:"0.0.2",example:"dphelper.array.match(arrA, arrB)",author:"Dario Passariello",creationDate:"20250101",lastMod:"20260220",type:"function",active:true,description:"Find a perfect match between an array of words and an array to check.",env:"both",subCommand:[]}]},y={find:(e,a)=>{if(Array.isArray(e)){for(let r of e){if(r[a]===a)return r;if(r.children){let t=dphelper.array.find(a,r.children);if(t)return t}}return false}},delete:(e,a)=>{Array.isArray(e)&&e.some(function r(t,n,o){if(t[a]===a)return o.splice(n,1),true;for(let s of Object.keys(t)){let u=t[s];if(Array.isArray(u))return u.some(r)}return null});},merge:(e,a)=>{if(!(e&&a))return a||e;for(let r of Object.keys(e))r==="__proto__"||r==="constructor"||r==="prototype"||e[r]instanceof Object&&a[r]&&Object.assign(e[r],dphelper.array.merge(a[r],e[r]));return Object.assign(a,e)},mergeByKey:(e,a,r)=>e.map(t=>{let n=a.find(o=>t[r]===o[r]);return n?Object.assign({},t,n):t}),duplicates:e=>{if(!Array.isArray(e))return;let a=new Set,r=new Set;for(let t of e)a.has(t)?r.add(t):a.add(t);return Array.from(r)},even:e=>{if(Array.isArray(e))return e.filter(a=>a%2===0)},odd:e=>{if(Array.isArray(e))return e.filter(a=>a%2!==0)},sumColumn:(e=[],a=0)=>Array.isArray(e)?typeof a>"u"?"provide a column":e.reduce((r,t)=>r+(t[a]||0),0):"provide a multidimensional array",shuffle:e=>{if(Array.isArray(e)){for(let a=e.length-1;a>0;a--){let r=Math.floor(Math.random()*(a+1));[e[a],e[r]]=[e[r],e[a]];}return e}},generate:e=>{if(Number.isNaN(e))return;let a=Array.from({length:e},(r,t)=>t+1);return dphelper.array.shuffle(a)},testArrayInt:e=>{if(!Array.isArray(e))return;let a=[];for(let r=1;r<=e.length;r++)e.includes(r)||a.push(r);return a},rand32:e=>{let a=performance.now(),r=[];r.nums=[],r.time=[];for(let n=0;n<e;++n)r.nums.push(crypto.getRandomValues(new Uint32Array(1))[0]);let t=performance.now();return r.time.push(t-a),r},match:(e,a)=>e.filter(r=>a.includes(r)),pathToJson:(e,a="/")=>{let r={},t;for(let n of e){t=r;let o=n.split(a);for(let s of o.slice(1,-1)){if(s==="")return;s in t||(t[s]={}),t=t[s];}o.at(-1)&&(t[o.at(-1)]=null);}return r}};dphelper?.setDescription(f,y);var M=dphelper.array;exports.array=M;
|
package/modules/array.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var p={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var d={version:"4.
|
|
1
|
+
var p={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var d={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...p},configurable:true,writable:true},version:{value:d.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var i=dphelper;Object.defineProperty(i,"setProps",{value:(e,a,r)=>{Object.defineProperty(e,a.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[a.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(i,"setDescription",{value:(e,a)=>{Object.defineProperties(i,{[e.name]:{value:a,writable:false,configurable:false,enumerable:false}}),Object.keys(a).map(r=>(Object.defineProperties(i[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),i.setProps(i,e,{writable:false,configurable:false,enumerable:false}),i._list.scripts.push(e);}});var y={name:"array",active:true,subCommand:[{name:"find",version:"0.0.2",example:"dphelper.array.find(array, 'key')",description:"Find an item in the array recursively.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"delete",version:"0.0.2",example:"dphelper.array.delete(array, 'key')",description:"Delete an item from the array recursively.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"unique",version:"0.0.2",example:"dphelper.array.unique(array)",description:"Remove duplicate values from an array.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"merge",version:"0.0.2",example:"dphelper.array.merge(arrA, arrB)",description:"Merge two arrays into one.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"mergeByKey",version:"0.0.2",example:"dphelper.array.mergeByKey(arrA, arrB, 'id')",author:"Dario Passariello",creationDate:"20230603",lastMod:"20260220",type:"function",active:true,description:"Merge two arrays of objects by a specific key.",env:"both",subCommand:[]},{name:"asc",version:"0.0.2",example:"dphelper.array.asc(array)",description:"Sort array in ascending order.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"desc",version:"0.0.2",example:"dphelper.array.desc(array)",description:"Sort array in descending order.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"duplicates",version:"0.0.2",example:"dphelper.array.duplicates(array)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Find duplicate items in an array.",env:"both",subCommand:[]},{name:"even",version:"0.0.2",example:"dphelper.array.even(array)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Filter even numbers from an array.",env:"both",subCommand:[]},{name:"odd",version:"0.0.2",example:"dphelper.array.odd(array)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Filter odd numbers from an array.",env:"both",subCommand:[]},{name:"toObj",version:"0.0.2",example:"dphelper.array.toObj(array)",description:"Convert an array to an object.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"sumColumn",version:"0.0.2",example:"dphelper.array.sumColumn(arr, 0)",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,description:"Sum the values of a specified column in a multidimensional array.",env:"both",subCommand:[]},{name:"shuffle",version:"0.0.2",example:"dphelper.array.shuffle(array)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Randomly shuffle the elements of an array.",env:"both",subCommand:[]},{name:"generate",version:"0.0.2",example:"dphelper.array.generate(10)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Generate an array of random numbers (max 500000).",env:"both",subCommand:[]},{name:"testArrayInt",version:"0.0.2",example:"dphelper.array.testArrayInt([1,2,4])",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Check if an array contains consecutive integers.",env:"both",subCommand:[]},{name:"rand32",version:"0.0.2",example:"dphelper.array.rand32(5)",author:"Dario Passariello",creationDate:"20230527",lastMod:"20260220",type:"function",active:true,description:"Generate an array of random 32-bit unsigned integers.",env:"both",subCommand:[]},{name:"findindex",version:"0.0.2",example:"dphelper.array.findindex(array, 'name')",description:"Find the index of an item in an array by key.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"pathToJson",version:"0.0.2",example:"dphelper.array.pathToJson(paths, '/')",description:"Convert an array of paths into a JSON object.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"deepClone",version:"0.0.2",example:"dphelper.array.deepClone(array)",description:"Create a deep clone of an array using structuredClone.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]},{name:"match",version:"0.0.2",example:"dphelper.array.match(arrA, arrB)",author:"Dario Passariello",creationDate:"20250101",lastMod:"20260220",type:"function",active:true,description:"Find a perfect match between an array of words and an array to check.",env:"both",subCommand:[]}]},h={find:(e,a)=>{if(Array.isArray(e)){for(let r of e){if(r[a]===a)return r;if(r.children){let t=dphelper.array.find(a,r.children);if(t)return t}}return false}},delete:(e,a)=>{Array.isArray(e)&&e.some(function r(t,n,o){if(t[a]===a)return o.splice(n,1),true;for(let s of Object.keys(t)){let c=t[s];if(Array.isArray(c))return c.some(r)}return null});},merge:(e,a)=>{if(!(e&&a))return a||e;for(let r of Object.keys(e))r==="__proto__"||r==="constructor"||r==="prototype"||e[r]instanceof Object&&a[r]&&Object.assign(e[r],dphelper.array.merge(a[r],e[r]));return Object.assign(a,e)},mergeByKey:(e,a,r)=>e.map(t=>{let n=a.find(o=>t[r]===o[r]);return n?Object.assign({},t,n):t}),duplicates:e=>{if(!Array.isArray(e))return;let a=new Set,r=new Set;for(let t of e)a.has(t)?r.add(t):a.add(t);return Array.from(r)},even:e=>{if(Array.isArray(e))return e.filter(a=>a%2===0)},odd:e=>{if(Array.isArray(e))return e.filter(a=>a%2!==0)},sumColumn:(e=[],a=0)=>Array.isArray(e)?typeof a>"u"?"provide a column":e.reduce((r,t)=>r+(t[a]||0),0):"provide a multidimensional array",shuffle:e=>{if(Array.isArray(e)){for(let a=e.length-1;a>0;a--){let r=Math.floor(Math.random()*(a+1));[e[a],e[r]]=[e[r],e[a]];}return e}},generate:e=>{if(Number.isNaN(e))return;let a=Array.from({length:e},(r,t)=>t+1);return dphelper.array.shuffle(a)},testArrayInt:e=>{if(!Array.isArray(e))return;let a=[];for(let r=1;r<=e.length;r++)e.includes(r)||a.push(r);return a},rand32:e=>{let a=performance.now(),r=[];r.nums=[],r.time=[];for(let n=0;n<e;++n)r.nums.push(crypto.getRandomValues(new Uint32Array(1))[0]);let t=performance.now();return r.time.push(t-a),r},match:(e,a)=>e.filter(r=>a.includes(r)),pathToJson:(e,a="/")=>{let r={},t;for(let n of e){t=r;let o=n.split(a);for(let s of o.slice(1,-1)){if(s==="")return;s in t||(t[s]={}),t=t[s];}o.at(-1)&&(t[o.at(-1)]=null);}return r}};dphelper?.setDescription(y,h);var A=dphelper.array;export{A as array};
|
package/modules/audio.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var i={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var s={version:"4.
|
|
1
|
+
'use strict';var i={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var s={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...i},configurable:true,writable:true},version:{value:s.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var a=dphelper;Object.defineProperty(a,"setProps",{value:(e,o,r)=>{Object.defineProperty(e,o.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[o.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(a,"setDescription",{value:(e,o)=>{Object.defineProperties(a,{[e.name]:{value:o,writable:false,configurable:false,enumerable:false}}),Object.keys(o).map(r=>(Object.defineProperties(a[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),a.setProps(a,e,{writable:false,configurable:false,enumerable:false}),a._list.scripts.push(e);}});var c={name:"audio",active:true,subCommand:[{name:"play",version:"0.0.2",example:"dphelper.audio.play([audiofile])",description:"Plays an audio file or removes all audio elements from the document.",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:true,env:"client",subCommand:[]}]},d={play:(e,o="",r=false)=>{if(e){if(!document.querySelector(`#audio_${e}`)){let t=document.createElement("audio");t.id=`audio_${e}`,t.dataset.dphelper="audio",t.src=o+e,t.loop=r,document.body.appendChild(t),t.load(),t.play()?.catch?.(n=>console.error("Error playing audio:",n));}}else document.querySelectorAll("audio[data-dphelper='audio']").forEach(t=>t.remove());}};dphelper?.setDescription(c,d);var O=dphelper.audio;exports.audio=O;
|
package/modules/audio.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var s={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var n={version:"4.
|
|
1
|
+
var s={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var n={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...s},configurable:true,writable:true},version:{value:n.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var a=dphelper;Object.defineProperty(a,"setProps",{value:(e,o,r)=>{Object.defineProperty(e,o.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[o.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(a,"setDescription",{value:(e,o)=>{Object.defineProperties(a,{[e.name]:{value:o,writable:false,configurable:false,enumerable:false}}),Object.keys(o).map(r=>(Object.defineProperties(a[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),a.setProps(a,e,{writable:false,configurable:false,enumerable:false}),a._list.scripts.push(e);}});var d={name:"audio",active:true,subCommand:[{name:"play",version:"0.0.2",example:"dphelper.audio.play([audiofile])",description:"Plays an audio file or removes all audio elements from the document.",author:"Dario Passariello",creationDate:"20240924",lastMod:"20240924",type:"function",active:true,env:"client",subCommand:[]}]},b={play:(e,o="",r=false)=>{if(e){if(!document.querySelector(`#audio_${e}`)){let t=document.createElement("audio");t.id=`audio_${e}`,t.dataset.dphelper="audio",t.src=o+e,t.loop=r,document.body.appendChild(t),t.load(),t.play()?.catch?.(p=>console.error("Error playing audio:",p));}}else document.querySelectorAll("audio[data-dphelper='audio']").forEach(t=>t.remove());}};dphelper?.setDescription(d,b);var k=dphelper.audio;export{k as audio};
|
package/modules/avoid.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var l={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var s={version:"4.
|
|
1
|
+
'use strict';var l={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var s={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...l},configurable:true,writable:true},version:{value:s.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var t=dphelper;Object.defineProperty(t,"setProps",{value:(e,r,a)=>{Object.defineProperty(e,r.name,a||{writable:false,configurable:false,enumerable:false}),a?.lock&&Object.freeze(e[r.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(t,"setDescription",{value:(e,r)=>{Object.defineProperties(t,{[e.name]:{value:r,writable:false,configurable:false,enumerable:false}}),Object.keys(r).map(a=>(Object.defineProperties(t[e.name],{[a]:{writable:false,configurable:false,enumerable:false}}),null)),t.setProps(t,e,{writable:false,configurable:false,enumerable:false}),t._list.scripts.push(e);}});var p={name:"avoid",active:true,subCommand:[{name:"cache",version:"0.0.2",example:"dphelper.avoid.cache()",description:"Appends a cache-busting query parameter to a given URI.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]}]},c={cache:e=>{if(typeof e!="string")throw new Error("The provided URI must be a string");return e.concat(/\?/.test(e)?"&":"?","t=",Math.random().toString(36).substring(2))}};dphelper?.setDescription(p,c);var j=dphelper.avoid;exports.avoid=j;
|
package/modules/avoid.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var s={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var i={version:"4.
|
|
1
|
+
var s={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var i={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...s},configurable:true,writable:true},version:{value:i.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var t=dphelper;Object.defineProperty(t,"setProps",{value:(e,r,a)=>{Object.defineProperty(e,r.name,a||{writable:false,configurable:false,enumerable:false}),a?.lock&&Object.freeze(e[r.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(t,"setDescription",{value:(e,r)=>{Object.defineProperties(t,{[e.name]:{value:r,writable:false,configurable:false,enumerable:false}}),Object.keys(r).map(a=>(Object.defineProperties(t[e.name],{[a]:{writable:false,configurable:false,enumerable:false}}),null)),t.setProps(t,e,{writable:false,configurable:false,enumerable:false}),t._list.scripts.push(e);}});var c={name:"avoid",active:true,subCommand:[{name:"cache",version:"0.0.2",example:"dphelper.avoid.cache()",description:"Appends a cache-busting query parameter to a given URI.",author:"Dario Passariello",creationDate:"20210101",lastMod:"20260220",type:"function",active:true,env:"both",subCommand:[]}]},u={cache:e=>{if(typeof e!="string")throw new Error("The provided URI must be a string");return e.concat(/\?/.test(e)?"&":"?","t=",Math.random().toString(36).substring(2))}};dphelper?.setDescription(c,u);var P=dphelper.avoid;export{P as avoid};
|
package/modules/biometric.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var f={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var b={version:"4.
|
|
1
|
+
'use strict';var f={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var b={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...f},configurable:true,writable:true},version:{value:b.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var o=dphelper;Object.defineProperty(o,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(o,"setDescription",{value:(e,t)=>{Object.defineProperties(o,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(o[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),o.setProps(o,e,{writable:false,configurable:false,enumerable:false}),o._list.scripts.push(e);}});var g={name:"biometric",active:true,subCommand:[{name:"isAvailable",version:"0.0.1",example:"dphelper.biometric.isAvailable()",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Check if WebAuthn/biometric authentication is available",env:"client",subCommand:[]},{name:"register",version:"0.0.1",example:"dphelper.biometric.register('user123', 'https://example.com')",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Register a new credential for biometric authentication",env:"client",subCommand:[]},{name:"authenticate",version:"0.0.1",example:"dphelper.biometric.authenticate('user123', 'https://example.com')",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Authenticate using stored biometric credential",env:"client",subCommand:[]},{name:"getCredential",version:"0.0.1",example:"dphelper.biometric.getCredential(credentialId)",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Get a stored credential by ID",env:"client",subCommand:[]},{name:"deleteCredential",version:"0.0.1",example:"dphelper.biometric.deleteCredential(credentialId)",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Delete a stored credential",env:"client",subCommand:[]},{name:"listCredentials",version:"0.0.1",example:"dphelper.biometric.listCredentials()",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"List all stored credentials",env:"client",subCommand:[]},{name:"isSensorAvailable",version:"0.0.1",example:"dphelper.biometric.isSensorAvailable('fingerprint')",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Check if specific biometric sensor is available",env:"client",subCommand:[]},{name:"getWebAuthnSupport",version:"0.0.1",example:"dphelper.biometric.getWebAuthnSupport()",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Get detailed WebAuthn support information",env:"client",subCommand:[]}]},l=()=>!!navigator.credentials&&!!navigator.credentials.create,v=()=>{if(!l())return {supported:false,platformAuthenticator:false,hybridTransport:false,uvToken:false};let t=navigator.userAgent,r=t.includes("Windows"),a=t.includes("Mac"),i=t.includes("Linux");return {supported:true,platformAuthenticator:r||a||i,hybridTransport:false,uvToken:false}},w=async e=>{if(!l())return false;if(typeof PublicKeyCredential<"u")try{if(e==="fingerprint")return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();if(e==="face")return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();if(e==="iris")return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()}catch{return false}return false},m=(e=32)=>{let t=new Uint8Array(e);return crypto.getRandomValues(t),t},C=e=>{let t=e instanceof Uint8Array?e:new Uint8Array(e),r="";return t.forEach(a=>r+=String.fromCharCode(a)),btoa(r)},A=e=>{let t=atob(e),r=new Uint8Array(t.length);for(let a=0;a<t.length;a++)r[a]=t.charCodeAt(a);return r},s=new Map,P=async(e,t=window.location.hostname,r=window.location.hostname,a=e)=>{if(!l())return {success:false,error:"WebAuthn not supported"};try{let p={challenge:m().buffer,rp:{id:t,name:r},user:{id:new TextEncoder().encode(e),name:a,displayName:a},pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],timeout:6e4,attestation:"none",authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred"}},n=await navigator.credentials.create({publicKey:p});if(!n)return {success:!1,error:"Credential creation failed"};let d=C(n.rawId);return s.set(d,{type:"public-key",id:n.rawId}),{success:!0,credentialId:d}}catch(i){return {success:false,error:i.message||"Registration failed"}}},D=async(e,t=window.location.hostname,r)=>{if(!l())return {success:false,error:"WebAuthn not supported"};try{let a=m(),i=[];if(r){let n=A(r).buffer;i.push({type:"public-key",id:n});}else s.size>0&&s.forEach(n=>{i.push(n);});let u={challenge:a.buffer,rpId:t,timeout:6e4,userVerification:"preferred",allowCredentials:i.length>0?i:void 0};return await navigator.credentials.get({publicKey:u})?{success:!0}:{success:!1,error:"Authentication failed"}}catch(a){return {success:false,error:a.message||"Authentication failed"}}},k=e=>s.get(e),x=e=>s.delete(e),j=()=>Array.from(s.keys()),K={isAvailable:l,getWebAuthnSupport:v,isSensorAvailable:w,register:P,authenticate:D,getCredential:k,deleteCredential:x,listCredentials:j};dphelper?.setDescription(g,K);var L=dphelper.biometric;
|
|
2
2
|
exports.biometric=L;
|
package/modules/biometric.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var b={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var m={version:"4.
|
|
1
|
+
var b={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var m={version:"4.6.1"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...b},configurable:true,writable:true},version:{value:m.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var o=dphelper;Object.defineProperty(o,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(o,"setDescription",{value:(e,t)=>{Object.defineProperties(o,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(o[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),o.setProps(o,e,{writable:false,configurable:false,enumerable:false}),o._list.scripts.push(e);}});var v={name:"biometric",active:true,subCommand:[{name:"isAvailable",version:"0.0.1",example:"dphelper.biometric.isAvailable()",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Check if WebAuthn/biometric authentication is available",env:"client",subCommand:[]},{name:"register",version:"0.0.1",example:"dphelper.biometric.register('user123', 'https://example.com')",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Register a new credential for biometric authentication",env:"client",subCommand:[]},{name:"authenticate",version:"0.0.1",example:"dphelper.biometric.authenticate('user123', 'https://example.com')",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Authenticate using stored biometric credential",env:"client",subCommand:[]},{name:"getCredential",version:"0.0.1",example:"dphelper.biometric.getCredential(credentialId)",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Get a stored credential by ID",env:"client",subCommand:[]},{name:"deleteCredential",version:"0.0.1",example:"dphelper.biometric.deleteCredential(credentialId)",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Delete a stored credential",env:"client",subCommand:[]},{name:"listCredentials",version:"0.0.1",example:"dphelper.biometric.listCredentials()",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"List all stored credentials",env:"client",subCommand:[]},{name:"isSensorAvailable",version:"0.0.1",example:"dphelper.biometric.isSensorAvailable('fingerprint')",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Check if specific biometric sensor is available",env:"client",subCommand:[]},{name:"getWebAuthnSupport",version:"0.0.1",example:"dphelper.biometric.getWebAuthnSupport()",author:"Dario Passariello",creationDate:"20260313",lastMod:"20260313",type:"function",active:true,description:"Get detailed WebAuthn support information",env:"client",subCommand:[]}]},l=()=>!!navigator.credentials&&!!navigator.credentials.create,w=()=>{if(!l())return {supported:false,platformAuthenticator:false,hybridTransport:false,uvToken:false};let t=navigator.userAgent,r=t.includes("Windows"),a=t.includes("Mac"),i=t.includes("Linux");return {supported:true,platformAuthenticator:r||a||i,hybridTransport:false,uvToken:false}},C=async e=>{if(!l())return false;if(typeof PublicKeyCredential<"u")try{if(e==="fingerprint")return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();if(e==="face")return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();if(e==="iris")return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable()}catch{return false}return false},h=(e=32)=>{let t=new Uint8Array(e);return crypto.getRandomValues(t),t},A=e=>{let t=e instanceof Uint8Array?e:new Uint8Array(e),r="";return t.forEach(a=>r+=String.fromCharCode(a)),btoa(r)},P=e=>{let t=atob(e),r=new Uint8Array(t.length);for(let a=0;a<t.length;a++)r[a]=t.charCodeAt(a);return r},s=new Map,D=async(e,t=window.location.hostname,r=window.location.hostname,a=e)=>{if(!l())return {success:false,error:"WebAuthn not supported"};try{let d={challenge:h().buffer,rp:{id:t,name:r},user:{id:new TextEncoder().encode(e),name:a,displayName:a},pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],timeout:6e4,attestation:"none",authenticatorSelection:{authenticatorAttachment:"platform",userVerification:"preferred"}},n=await navigator.credentials.create({publicKey:d});if(!n)return {success:!1,error:"Credential creation failed"};let f=A(n.rawId);return s.set(f,{type:"public-key",id:n.rawId}),{success:!0,credentialId:f}}catch(i){return {success:false,error:i.message||"Registration failed"}}},k=async(e,t=window.location.hostname,r)=>{if(!l())return {success:false,error:"WebAuthn not supported"};try{let a=h(),i=[];if(r){let n=P(r).buffer;i.push({type:"public-key",id:n});}else s.size>0&&s.forEach(n=>{i.push(n);});let p={challenge:a.buffer,rpId:t,timeout:6e4,userVerification:"preferred",allowCredentials:i.length>0?i:void 0};return await navigator.credentials.get({publicKey:p})?{success:!0}:{success:!1,error:"Authentication failed"}}catch(a){return {success:false,error:a.message||"Authentication failed"}}},x=e=>s.get(e),j=e=>s.delete(e),K=()=>Array.from(s.keys()),M={isAvailable:l,getWebAuthnSupport:w,isSensorAvailable:C,register:D,authenticate:k,getCredential:x,deleteCredential:j,listCredentials:K};dphelper?.setDescription(v,M);var E=dphelper.biometric;
|
|
2
2
|
export{E as biometric};
|