ameliance-scripts
Version:
39 lines • 12.7 kB
JavaScript
;var E=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var d=(r,t)=>{for(var e in t)E(r,e,{get:t[e],enumerable:!0})},M=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of N(t))!D.call(r,o)&&o!==e&&E(r,o,{get:()=>t[o],enumerable:!(n=K(t,o))||n.enumerable});return r};var $=r=>M(E({},"__esModule",{value:!0}),r);var Pr={};d(Pr,{addId:()=>G,className:()=>J,clearLocalStorageAndReload:()=>U,createHTMLElem:()=>W,default:()=>kr,detectValueType:()=>C,errorHandler:()=>p,getChangedProperties:()=>Y,getCommonValues:()=>q,getCurrentDateInMs:()=>X,getCurrentTimeWithOffset:()=>z,getDifferentValues:()=>Q,getElemByKey:()=>Z,getFormattedDate:()=>rr,getIndexByKey:()=>tr,getIndexesOfNonEmptyElements:()=>er,getMatch:()=>or,getMatchSoft:()=>nr,getObjKeyByValue:()=>ir,getRandomHEXColor:()=>sr,getRandomNumber:()=>l,getRandomRGBColor:()=>ur,getScrollDirection:()=>ar,getToday:()=>cr,getValueType:()=>lr,groupBy:()=>mr,hideEmail:()=>gr,isArraysEqual:()=>yr,isClient:()=>br,isObject:()=>f,isObjectEmpty:()=>y,isObjectHasValue:()=>xr,isObjectValid:()=>wr,join:()=>Er,joinWith:()=>h,kebabToCamelCase:()=>hr,lab:()=>A,legacy:()=>T,log:()=>I,parseCurrentDateFromMs:()=>Ir,removeEmptyValues:()=>Sr,setIntervalCounts:()=>jr,shuffleArray:()=>Cr,sortArrayLocalCompare:()=>Or,sortArrayOfObj:()=>Kr,stringCut:()=>Nr,toTimeFormat:()=>Dr,trimEndEmptyValues:()=>Mr,trimStartEmptyValues:()=>$r,writeTextToClipboard:()=>Vr,\u0456sValidUrl:()=>Ar});module.exports=$(Pr);var A={};d(A,{getLocalStorage:()=>H,setLocalStorage:()=>_});var m="ameliance-scripts";function h(r,...t){return t.flat(1/0).filter(e=>e).map(e=>String(e).trim()).join(r)}var O=`
color: white;
border-radius: 4px;
padding: 2px 4px;
font-weight: bold;
margin-bottom: 4px;
`,V=`
background-color: blue;
`,L=`
background-color: green;
`,k=`
background-color: darkorange;
`,P=`
background-color: red;
`;function w(r,t,e,n){let o=[];if(Array.isArray(n[0])){let[i,s]=n.reduce((u,a)=>(Array.isArray(a)&&(u[0].push(`%c${a[0]}`),u[1].push(a[1])),u),[[],[]]);o=[`%c${t}${i.join("")}`,`${O}${e} margin-right: 4px; `,...s]}else o=[`%c${t}`,`${O}${e}`,n.join(`
`)];console[r](...o)}var I={info:(r,...t)=>w("log",r,V,t),success:(r,...t)=>w("log",r,L,t),warn:(r,...t)=>w("warn",r,k,t),error:(r,...t)=>w("error",r,P,t)};function p({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 a=2+u,g=u<0?0:i,c={status:t,code:e,message:n};if(r&&(r instanceof Error&&(c.message=r.message,c.code=r.name),typeof r=="string"&&(c.message=r),typeof r=="object"&&r!==null&&("status"in r&&typeof r.status=="number"&&(c.status=r.status),"message"in r&&typeof r.message=="string"&&(c.message=r.message),"code"in r&&typeof r.code=="string"&&(c.code=r.code))),s){let b=` ${o} ERROR:
`,x=`${h(" | ",c.status,c.code,c.message)}`;I.error(b,[x,`
background-color: hsla(0, 0%, 0%, 0.5);
color: white;
border-radius: 4px;
padding: 2px 4px;
margin-bottom: 4px;
`],[`
${new Error().stack?.split(`
`).splice(a,g).join(`
`)}`,""])}return c}function H(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 p({error:i,title:m}),n}}function _(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){p({error:i,title:m})}}var T={};d(T,{join:()=>F,returnError1:()=>S,returnError2:()=>j});function F(...r){return r.flat(1/0).filter(t=>t).join(" ").trim()}var S={};d(S,{returnError:()=>B});function B(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 j={};d(j,{returnError:()=>v});function v(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 G(r,t){return t&&t.length===r.length?r.map((e,n)=>({...e,id:t[n]})):r.map((e,n)=>({...e,id:n}))}function J(...r){return{className:r.flat(1/0).filter(t=>t).join(" ").trim()}}function U(){localStorage.clear(),window.location.reload()}function W(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"}var Y=(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 q(...r){return r.reduce((t,e)=>t.filter(n=>e.includes(n)))}function X(){return Date.now()}function z(r){let t=new Date;return t.setTime(t.getTime()+r),t.toLocaleTimeString("en-US",{hour12:!1})}function Q(...r){return r.reduce((t,e)=>t.filter(n=>!e.includes(n)))}function Z(r,t,e){return r.find(n=>n[t]===e)||null}function rr(r,t="long",e="en-US"){return new Intl.DateTimeFormat(e,{dateStyle:t}).format(new Date(r))}function tr(r,t,e){return r.findIndex(n=>n[t]===e)}function er(r){return r.map((t,e)=>t!==""?e:"").filter(String)}function nr(r,t){return r==null||!(r in t)?t._??null:t[r]??t._??null}function or(r,t){if(r==null||r===void 0||!(r in t))return t._;let e=t[r];return e===void 0?t._:e}function ir(r,t){try{return Object.keys(r).find(e=>r[e]===t)}catch(e){p({error:e,title:m})}}function l(r,t){return Math.trunc(Math.random()*(t-r+1)+r)}function sr(){let r=l(0,255).toString(16),t=l(0,255).toString(16),e=l(0,255).toString(16);return`#${r}${t}${e}`}function ur(){let r=l(0,255),t=l(0,255),e=l(0,255);return[r,t,e]}function fr(){let r;return()=>{let t=r>window.scrollY?"UP":"DOWN";return r=window.scrollY,t}}var ar=fr();function cr(){let r=new Date;return`${r.getFullYear()}-${r.getMonth()+1}-${r.getDate()}`}function lr(r){return r===null?"null":r===void 0?"undefined":r instanceof Date?"date":Array.isArray(r)?"array":typeof r}function f(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function pr(r,t,e=0){return e===0&&typeof r=="string"?r:typeof r=="string"?r[0]:f(r)&&t||Array.isArray(r)&&t&&typeof t=="number"?e===0?String(r[t]):String(r[t]).slice(0,e):""}function mr(r,t,e=0){let n=r[0];if(typeof n!="string"&&typeof n!="number"&&!f(n)&&!Array.isArray(n))throw new Error("Invalid value");if((f(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=pr(i,t||void 0,e);o.has(s)?o.set(s,[...o.get(s),i]):o.set(s,[i])}),Array.from(o.entries())}function gr(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}`}function dr(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 yr(r,t){if(!r||!t)return r===t;if(r.length!==t.length)return!1;if(dr(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 br(){return typeof window<"u"}function y(r){return Object.keys(r).length===0}function xr(r,t){if(y(r))throw new Error("Object is empty");return Object.values(r).includes(t)}function wr(r){return f(r)&&!y(r)}function Ar(r){try{return!!new URL(r)}catch{return!1}}function Tr(r){let t=Object.entries(r);return t.length>0?t.map(e=>e[1]?e[0]:"").filter(e=>e):[]}function Er(...r){return r.flat(1/0).map(t=>{if(t&&typeof t=="object"){let e=Tr(t);return e?e.join(" "):""}return t}).filter(t=>t).join(" ").trim()}function hr(r){return r.replace(/-./g,t=>t[1].toUpperCase())}function Ir(r){return new Date(Number(r))}function Sr(r,t){let e=r.slice(),n=e[0];if(typeof n!="string"&&typeof n!="number"&&!f(n)&&!Array.isArray(n))throw new Error("Invalid value");if((f(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()!=="")),f(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 jr({callback:r,delay:t,counts:e}){let n=0,o=setInterval(()=>{r(),n+=1,n===e&&clearInterval(o)},t);return o}function Cr(r){let t=r.slice();for(let e=0;e<r.length;e++){let n=l(0,r.length-1);[t[e],t[n]]=[t[n],t[e]]}return t}function Or(r,t){let e=r.slice(),n=e[0];if(typeof n!="string"&&typeof n!="number"&&!f(n)&&!Array.isArray(n))throw new Error("Invalid value");if((f(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),a=String(s);return u.localeCompare(a)})),f(n)&&t&&(o=e.sort((i,s)=>{let u=String(i[t]),a=String(s[t]);return u.localeCompare(a.toString())})),Array.isArray(n)&&t&&typeof t=="number"&&(o=e.sort((i,s)=>{let u=String(i[t]),a=String(s[t]);return u.localeCompare(a)})),o}var Rr=(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 Kr(r,t,e,n="end"){let o=r.slice();if(!t||r.length===0)return o;let i=r.find(u=>{let a=u[t];return a!=null&&a!==""})?.[t],s=e||C(i);return o.sort((u,a)=>{let g=u[t],c=a[t],b=g==null||g==="",x=c==null||c==="";return b&&x?0:b?n==="start"?-1:1:x?n==="start"?1:-1:Rr(g,c,s)}),o}function Nr(r,t,e="..."){return r.length>t?`${r.substring(0,t).trim()}${e}`:r}function Dr(r){let t=r*1e3,e=new Date(t).toISOString().slice(11,19);return e.match(/^00/)?e.slice(3):e}function Mr(r,t){let e=r.slice(),n=e[0];if(typeof n!="string"&&!f(n))throw new Error("Invalid value");if(f(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 $r(r,t){let e=r[0];if(typeof e!="string"&&!f(e))throw new Error("Invalid value");if(f(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 Vr(r){if(r)try{return await navigator.clipboard.writeText(r),!0}catch(t){let{message:e}=p({error:t,title:m});throw new Error(e)}return!1}var Lr={lab:A,legacy:T},kr=Lr;0&&(module.exports={addId,className,clearLocalStorageAndReload,createHTMLElem,detectValueType,errorHandler,getChangedProperties,getCommonValues,getCurrentDateInMs,getCurrentTimeWithOffset,getDifferentValues,getElemByKey,getFormattedDate,getIndexByKey,getIndexesOfNonEmptyElements,getMatch,getMatchSoft,getObjKeyByValue,getRandomHEXColor,getRandomNumber,getRandomRGBColor,getScrollDirection,getToday,getValueType,groupBy,hideEmail,isArraysEqual,isClient,isObject,isObjectEmpty,isObjectHasValue,isObjectValid,join,joinWith,kebabToCamelCase,lab,legacy,log,parseCurrentDateFromMs,removeEmptyValues,setIntervalCounts,shuffleArray,sortArrayLocalCompare,sortArrayOfObj,stringCut,toTimeFormat,trimEndEmptyValues,trimStartEmptyValues,writeTextToClipboard,\u0456sValidUrl});
//# sourceMappingURL=index.js.map