ameliance-scripts
Version:
39 lines • 12.3 kB
JavaScript
var K=Object.defineProperty;var b=(r,t)=>{for(var e in t)K(r,e,{get:t[e],enumerable:!0})};var A={};b(A,{getLocalStorage:()=>D,setLocalStorage:()=>k});var p="ameliance-scripts";function h(r,...t){return t.flat(1/0).filter(e=>e).map(e=>String(e).trim()).join(r)}var S=`
color: white;
border-radius: 4px;
padding: 2px 4px;
font-weight: bold;
margin-bottom: 4px;
`,V=`
background-color: blue;
`,M=`
background-color: green;
`,N=`
background-color: darkorange;
`,$=`
background-color: red;
`;function x(r,t,e,n){let o=[];if(Array.isArray(n[0])){let[i,s]=n.reduce((u,f)=>(Array.isArray(f)&&(u[0].push(`%c${f[0]}`),u[1].push(f[1])),u),[[],[]]);o=[`%c${t}${i.join("")}`,`${S}${e} margin-right: 4px; `,...s]}else o=[`%c${t}`,`${S}${e}`,n.join(`
`)];console[r](...o)}var j={info:(r,...t)=>x("log",r,V,t),success:(r,...t)=>x("log",r,M,t),warn:(r,...t)=>x("warn",r,N,t),error:(r,...t)=>x("error",r,$,t)};function m({error:r,status:t,code:e,message:n="Sorry, something went wrong \xAF\\_(\u30C4)_/\xAF!",title:o="AMELIANCE SCRIPTS",errorDepth:i=1/0,showConsoleError:s=!0,wrapperCount:u=0}){let f=2+u,g=u<0?0:i,l={status:t,code:e,message:n};if(r&&(r instanceof Error&&(l.message=r.message,l.code=r.name),typeof r=="string"&&(l.message=r),typeof r=="object"&&r!==null&&("status"in r&&typeof r.status=="number"&&(l.status=r.status),"message"in r&&typeof r.message=="string"&&(l.message=r.message),"code"in r&&typeof r.code=="string"&&(l.code=r.code))),s){let d=` ${o} ERROR:
`,y=`${h(" | ",l.status,l.code,l.message)}`;j.error(d,[y,`
background-color: hsla(0, 0%, 0%, 0.5);
color: white;
border-radius: 4px;
padding: 2px 4px;
margin-bottom: 4px;
`],[`
${new Error().stack?.split(`
`).splice(f,g).join(`
`)}`,""])}return l}function D(r,t,e,n){let o=(i,s)=>{localStorage.setItem(r,JSON.stringify({...i,[t]:{...i[t],[e]:s}}))};try{let i=localStorage.getItem(r),s=i?JSON.parse(i):{};if(!i)return n&&o(s,n),n||null;let u=s[t][e];return u||(o(s,n),n||null)}catch(i){return m({error:i,title:p}),n}}function k(r,t,e,n){let o=(i,s)=>{let u={...i,[t]:{...i?.[t],[e]:{...i?.[t]?.[e],...s||null}}};localStorage.setItem(r,JSON.stringify(u))};try{let i=localStorage.getItem(r),s=i?JSON.parse(i):{};o(s,n)}catch(i){m({error:i,title:p})}}var I={};b(I,{join:()=>L,returnError1:()=>T,returnError2:()=>E});function L(...r){return r.flat(1/0).filter(t=>t).join(" ").trim()}var T={};b(T,{returnError:()=>P});function P(r,t,e=0,n=1/0){let o=2+e,i="Sorry, something went wrong \xAF\\_(\u30C4)_/\xAF!";return r&&(typeof r=="string"&&(i=r),r instanceof Error&&(i=r.message)),t?console.error(`${t} >`,`${i}
`,new Error().stack?.split(`
`).splice(o,n).join(`
`)):console.error(`${i}
`,new Error().stack?.split(`
`).splice(o,n).join(`
`)),i}var E={};b(E,{returnError:()=>H});function H(r,t,e,n=0,o=1/0){let i=2+n;t=t||-1;let s="Sorry, something went wrong \xAF\\_(\u30C4)_/\xAF!";return r&&(typeof r=="string"&&(s=r),r instanceof Error&&(s=r.message)),e?console.error(`${e} >`,`${t} | ${s}
`,new Error().stack?.split(`
`).splice(i,o).join(`
`)):console.error(`${t} | ${s}
`,new Error().stack?.split(`
`).splice(i,o).join(`
`)),{status:t,message:s}}function pr(r,t){return t&&t.length===r.length?r.map((e,n)=>({...e,id:t[n]})):r.map((e,n)=>({...e,id:n}))}function gr(...r){return{className:r.flat(1/0).filter(t=>t).join(" ").trim()}}function yr(){localStorage.clear(),window.location.reload()}function xr(r,t,e,n=""){let o=document.createElement(t);if(e?.class){let i=e.class.split(" ");o.classList.add(...i)}return e?.id&&o.setAttribute("id",e.id),e?.attributes&&e.attributes.forEach(i=>{let s=i.split("=")[0],u=(i.split("=")[1]||"").replaceAll('"',"");o.setAttribute(s,u)}),n&&(o.innerHTML=n),r.append(o),o}function C(r){return r===null?"null":r===void 0?"undefined":typeof r=="string"?isNaN(Date.parse(r))?isNaN(Number(r))?r==="true"||r==="false"?"boolean":"string":"number":"date":typeof r=="number"?"number":typeof r=="boolean"?"boolean":typeof r=="symbol"?"symbol":typeof r=="bigint"?"bigint":typeof r=="function"?"function":Array.isArray(r)?"array":r instanceof Date?"date":typeof r=="object"?"object":"string"}function O(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var Er=(r,t)=>Object.fromEntries(Object.entries(t).filter(([e,n])=>{let o=r[e];return n instanceof Date&&o instanceof Date?n.getTime()!==o.getTime():n!==o}));function hr(...r){return r.reduce((t,e)=>t.filter(n=>e.includes(n)))}function jr(){return Date.now()}function Or(r){let t=new Date;return t.setTime(t.getTime()+r),t.toLocaleTimeString("en-US",{hour12:!1})}function Kr(...r){return r.reduce((t,e)=>t.filter(n=>!e.includes(n)))}function Mr(r,t,e){return r.find(n=>n[t]===e)||null}function $r(r,t="long",e="en-US"){return new Intl.DateTimeFormat(e,{dateStyle:t}).format(new Date(r))}function kr(r,t,e){return r.findIndex(n=>n[t]===e)}function Pr(r){return r.map((t,e)=>t!==""?e:"").filter(String)}function _r(r,t){return r==null||!(r in t)?t._??null:t[r]??t._??null}function Fr(r,t){if(r==null||r===void 0||!(r in t))return t._;let e=t[r];return e===void 0?t._:e}function Ur(r,t){try{return Object.keys(r).find(e=>r[e]===t)}catch(e){m({error:e,title:p})}}function c(r,t){return Math.trunc(Math.random()*(t-r+1)+r)}function Xr(){let r=c(0,255).toString(16),t=c(0,255).toString(16),e=c(0,255).toString(16);return`#${r}${t}${e}`}function Zr(){let r=c(0,255),t=c(0,255),e=c(0,255);return[r,t,e]}function _(){let r;return()=>{let t=r>window.scrollY?"UP":"DOWN";return r=window.scrollY,t}}var tt=_();function nt(){let r=new Date;return`${r.getFullYear()}-${r.getMonth()+1}-${r.getDate()}`}function it(r){return r===null?"null":r===void 0?"undefined":r instanceof Date?"date":Array.isArray(r)?"array":typeof r}function a(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function v(r,t,e=0){return e===0&&typeof r=="string"?r:typeof r=="string"?r[0]:a(r)&&t||Array.isArray(r)&&t&&typeof t=="number"?e===0?String(r[t]):String(r[t]).slice(0,e):""}function at(r,t,e=0){let n=r[0];if(typeof n!="string"&&typeof n!="number"&&!a(n)&&!Array.isArray(n))throw new Error("Invalid value");if((a(n)||Array.isArray(n))&&!t)throw new Error("No key provided");if(Array.isArray(n)&&typeof t=="string")throw new Error("Key should be array index number");let o=new Map;return r.forEach(i=>{let s=v(i,t||void 0,e);o.has(s)?o.set(s,[...o.get(s),i]):o.set(s,[i])}),Array.from(o.entries())}function ct(r,t="middle"){if(r.length<0)return null;let[e,n]=r.split("@"),o=t==="left"?"*":e.charAt(0),i=t==="right"?"*":e.charAt(e.length-1),s="*".repeat(e.length-2);return`${o}${s}${i}@${n}`}var F=/{{([\w.]+)(?:\|([^}]*))?}}/g;function B(r){let t=new Map;return function(n){if(t.has(n))return t.get(n);let o;if(!n.includes("."))o=r[n];else{let i=n.split(".");o=r;for(let s of i)if(typeof o=="object"&&o!==null&&s in o)o=o[s];else{o=void 0;break}}return t.set(n,o),o}}function gt(r,t,e={throwIfMissing:!0,escapeValues:!0}){let n=B(t);return r.replace(F,(o,i,s)=>{let u=n(i),f;if(u!=null)f=String(u);else if(s!==void 0)f=s;else{if(e.throwIfMissing)throw new Error(`Missing value for interpolation key: "${i}"`);return o}return e.escapeValues?O(f):f})}function G(r){return r===null||typeof r>"u"||typeof r=="string"||typeof r=="number"||typeof r=="boolean"}function R(r,t){if(r===t)return!0;if(typeof r!="object"||typeof t!="object"||r===null||t===null)return r===t;let e=Object.keys(r),n=Object.keys(t);return e.length!==n.length?!1:e.every(o=>R(r[o],t[o]))}function yt(r,t){if(!r||!t)return r===t;if(r.length!==t.length)return!1;if(G(r[0])){let e=[...r].sort(),n=[...t].sort();return e.every((o,i)=>o===n[i])}return r.every((e,n)=>R(e,t[n]))}function xt(){return typeof window<"u"}function w(r){return Object.keys(r).length===0}function Et(r,t){if(w(r))throw new Error("Object is empty");return Object.values(r).includes(t)}function jt(r){return a(r)&&!w(r)}function Ot(r){try{return!!new URL(r)}catch{return!1}}function J(r){let t=Object.entries(r);return t.length>0?t.map(e=>e[1]?e[0]:"").filter(e=>e):[]}function Kt(...r){return r.flat(1/0).map(t=>{if(t&&typeof t=="object"){let e=J(t);return e?e.join(" "):""}return t}).filter(t=>t).join(" ").trim()}function Mt(r){return r.replace(/-./g,t=>t[1].toUpperCase())}function $t(r){return new Date(Number(r))}function Lt(r,t){let e=r.slice(),n=e[0];if(typeof n!="string"&&typeof n!="number"&&!a(n)&&!Array.isArray(n))throw new Error("Invalid value");if((a(n)||Array.isArray(n))&&!t)throw new Error("No key provided");if(Array.isArray(n)&&typeof t=="string")throw new Error("Key should be array index number");let o=[];return(typeof n=="string"||typeof n=="number")&&(o=e.filter(i=>String(i).trim()!=="")),a(n)&&t&&(o=e.filter(i=>String(i[t]).trim()!=="")),Array.isArray(n)&&t&&typeof t=="number"&&(o=e.filter(i=>String(i[t]).trim()!=="")),o}function Ht({callback:r,delay:t,counts:e}){let n=0,o=setInterval(()=>{r(),n+=1,n===e&&clearInterval(o)},t);return o}function Ft(r){let t=r.slice();for(let e=0;e<r.length;e++){let n=c(0,r.length-1);[t[e],t[n]]=[t[n],t[e]]}return t}function Jt(r,t){let e=r.slice(),n=e[0];if(typeof n!="string"&&typeof n!="number"&&!a(n)&&!Array.isArray(n))throw new Error("Invalid value");if((a(n)||Array.isArray(n))&&!t)throw new Error("No key provided");if(Array.isArray(n)&&typeof t=="string")throw new Error("Key should be array index number");let o=[];return(typeof n=="string"||typeof n=="number")&&(o=e.sort((i,s)=>{let u=String(i),f=String(s);return u.localeCompare(f)})),a(n)&&t&&(o=e.sort((i,s)=>{let u=String(i[t]),f=String(s[t]);return u.localeCompare(f.toString())})),Array.isArray(n)&&t&&typeof t=="number"&&(o=e.sort((i,s)=>{let u=String(i[t]),f=String(s[t]);return u.localeCompare(f)})),o}var U=(r,t,e)=>{switch(e){case"date":return new Date(String(r)).getTime()-new Date(String(t)).getTime();case"number":return Number(r)-Number(t);case"boolean":return+!!r-+!!t;case"string":default:return String(r).localeCompare(String(t))}};function Yt(r,t,e,n="end"){let o=r.slice();if(!t||r.length===0)return o;let i=r.find(u=>{let f=u[t];return f!=null&&f!==""})?.[t],s=e||C(i);return o.sort((u,f)=>{let g=u[t],l=f[t],d=g==null||g==="",y=l==null||l==="";return d&&y?0:d?n==="start"?-1:1:y?n==="start"?1:-1:U(g,l,s)}),o}function Xt(r,t,e="..."){return r.length>t?`${r.substring(0,t).trim()}${e}`:r}function Qt(r){let t=r*1e3,e=new Date(t).toISOString().slice(11,19);return e.match(/^00/)?e.slice(3):e}function te(r,t){let e=r.slice(),n=e[0];if(typeof n!="string"&&!a(n))throw new Error("Invalid value");if(a(n)&&!t)throw new Error("No key provided");let o=0;return!t&&typeof n=="string"?o=r.length-e.reverse().findIndex(i=>i!==""):t&&typeof n!="string"&&(o=r.length-e.reverse().findIndex(i=>i[t]!=="")),e.reverse().splice(0,o)}function oe(r,t){let e=r[0];if(typeof e!="string"&&!a(e))throw new Error("Invalid value");if(a(e)&&!t)throw new Error("No key provided");let n=r.slice(),o=0;return!t&&typeof e=="string"?o=n.findIndex(i=>i!==""):t&&typeof e!="string"&&(o=n.findIndex(i=>i[t]!=="")),n.splice(o)}async function fe(r){if(r)try{return await navigator.clipboard.writeText(r),!0}catch(t){let{message:e}=m({error:t,title:p});throw new Error(e)}return!1}var W={lab:A,legacy:I},le=W;export{pr as addId,gr as className,yr as clearLocalStorageAndReload,xr as createHTMLElem,le as default,C as detectValueType,m as errorHandler,O as escapeHtml,Er as getChangedProperties,hr as getCommonValues,jr as getCurrentDateInMs,Or as getCurrentTimeWithOffset,Kr as getDifferentValues,Mr as getElemByKey,$r as getFormattedDate,kr as getIndexByKey,Pr as getIndexesOfNonEmptyElements,Fr as getMatch,_r as getMatchSoft,Ur as getObjKeyByValue,Xr as getRandomHEXColor,c as getRandomNumber,Zr as getRandomRGBColor,tt as getScrollDirection,nt as getToday,it as getValueType,at as groupBy,ct as hideEmail,gt as interpolate,yt as isArraysEqual,xt as isClient,a as isObject,w as isObjectEmpty,Et as isObjectHasValue,jt as isObjectValid,Kt as join,h as joinWith,Mt as kebabToCamelCase,A as lab,I as legacy,j as log,$t as parseCurrentDateFromMs,Lt as removeEmptyValues,Ht as setIntervalCounts,Ft as shuffleArray,Jt as sortArrayLocalCompare,Yt as sortArrayOfObj,Xt as stringCut,Qt as toTimeFormat,te as trimEndEmptyValues,oe as trimStartEmptyValues,fe as writeTextToClipboard,Ot as \u0456sValidUrl};
//# sourceMappingURL=index.mjs.map