@groww-tech/ella
Version:
Ella is a utility-belt library for JavaScript that provides general purpose methods used in day to day programming.
2 lines (1 loc) • 11.3 kB
JavaScript
import{b as E,c as l,d as m}from"./chunk-AED4KRKC.js";function S(e,t){try{if(typeof document<"u")document.documentElement.addEventListener(e,t);else throw new Error("window is undefined")}catch(r){u(l.TRACK_LOG,{function:"listenToCustomEvent",error:r}),console.error(`Error in listening to ${e} custom event: `,r)}}function u(e,t={}){try{if(typeof document<"u")document.documentElement.dispatchEvent(new CustomEvent(e,{detail:t}));else throw new Error("window is undefined")}catch(r){console.error(`Error in dispatching custom event ${e} and details ${t} ${r}`)}}function R(e,t){try{if(typeof document<"u")document.documentElement.removeEventListener(e,t);else throw new Error("window is undefined")}catch(r){console.error(` Error in unListening to ${e} custom event: `,r),u(l.TRACK_LOG,{function:"unlistenToCustomEvent",params:{eventName:e,methodToUnListen:t==null?void 0:t.toString()},error:r})}}function k(){try{if(typeof window<"u")window.scrollTo(0,0);else throw new Error("window is undefined")}catch(e){console.error(`Error while scrolling page to top ${e}`),u(l.TRACK_LOG,{function:"scrollPageToTop",error:e})}}function P(e,t){let r=e.key;r>="a"&&r<="z"||r>="A"&&r<="Z"||r==="Backspace"||r===" "||r>="0"&&r<="9"||r==="."||r===","||t.includes(r)||e.preventDefault()}function B(e){let t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}function F(e){var t;(t=window==null?void 0:window.performance)!=null&&t.mark&&window.performance.mark(e)}function D(e,t){var r;if((r=window==null?void 0:window.performance)!=null&&r.measure)return window.performance.measure("",e,t).duration}function I(e){let t="";try{t=decodeURIComponent(e)}catch(r){t=e,u(l.TRACK_LOG,{function:"encodeURLParams",error:r})}return encodeURIComponent(t)}function T(){try{if(typeof window>"u"||typeof navigator>"u")throw new Error("window or navigator is undefined");return(navigator.userAgent.indexOf("Opera")||navigator.userAgent.indexOf("OPR"))!==-1?"Opera":navigator.userAgent.indexOf("Edg")!==-1?"Edge":navigator.userAgent.indexOf("Chrome")!==-1?"Chrome":navigator.userAgent.indexOf("Safari")!==-1?"Safari":navigator.userAgent.indexOf("Firefox")!==-1?"Firefox":navigator.userAgent.indexOf("MSIE")!==-1||!!document.DOCUMENT_NODE?"IE":"unknown"}catch(e){console.error(`Error with getBrowserName ${e}`),u(l.TRACK_LOG,{function:"getBrowserName",error:e})}return""}function U(){var e,t;try{let r=navigator.userAgent,n=r.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[],o=[];return/trident/i.test(n[1])?(o=/\brv[ :]+(\d+)/g.exec(r)||[],{name:"IE",version:o[1]||""}):n[1]==="Chrome"&&(o=(e=r.match(/\bOPR|Edge\/(\d+)/))!=null?e:[],o.length)?{name:"Opera",version:o[1]}:(n=n[2]?[n[1],n[2]]:[navigator.appName,navigator.appVersion,"-?"],o=(t=r.match(/version\/(\d+)/i))!=null?t:[],o.length&&n.splice(1,1,o[1]),{name:n[0],version:n[1]})}catch(r){return console.error(`Error with getBrowserName ${r}`),u(l.TRACK_LOG,{function:"getBrowserName",error:r}),{name:null,version:null}}}function b(){try{if(typeof window>"u"||typeof navigator>"u")throw new Error("window or navigator is undefined");let e=window.navigator.userAgent,t=window.navigator.platform,r=["Macintosh","MacIntel","MacPPC","Mac68K"],n=["Win32","Win64","Windows","WinCE"],o=["iPhone","iPad","iPod"],i="";return r.indexOf(t)!==-1?i="Mac OS":o.indexOf(t)!==-1?i="iOS":n.indexOf(t)!==-1?i="Windows":/Android/i.test(e)?i="Android":!i&&/Linux/.test(t)&&(i="Linux"),i}catch(e){u(l.TRACK_LOG,{function:"getOSName",error:e}),console.error(`Error with getOSName ${e}`)}return""}function G(){try{if(typeof window<"u")try{window.scroll({top:0,behavior:"smooth"})}catch{window.scrollTo(0,0)}else throw new Error("window is undefined")}catch(e){console.error(`Error with smoothScrollToTop ${e}`)}}function K(e,t=0){try{if(typeof window<"u"){let r=document.getElementById(e);if(r){let n=t,o=document.body.getBoundingClientRect().top,f=r.getBoundingClientRect().top-o-n;window.scrollTo({top:f,behavior:"smooth"})}}else throw new Error("window is undefined")}catch(r){console.error("Error in scrollToElementWithId: ",r)}}function N(e,t,r=2){if(y(e.key))return;let n=t.toString();!h(n)&&n.length>1&&n.includes(".")&&n.split(".")[1].length>=r&&e.preventDefault()}function _(e){if(y(e.key))return;let t=e.key;t>="0"&&t<="9"||e.preventDefault()}function j(e){if(y(e.key))return;let t=e.key;t>="0"&&t<="9"||t==="."||e.preventDefault()}function y(e){return["ArrowLeft","ArrowRight","Backspace","Delete"].includes(e)}function $(e={},t="CUSTOM_MESSAGE",r){var n,o;try{if(typeof window>"u")return;let i={...e,identifier:t},s=typeof r>"u"?window:r;s==null||s.postMessage(JSON.stringify(i),(o=(n=window==null?void 0:window.location)==null?void 0:n.origin)!=null?o:"*")}catch(i){throw console.error("Error while window.postMessage",i),u(l.TRACK_LOG,{function:"postWindowMessage",error:i}),i}}function W(e,t="CUSTOM_MESSAGE"){try{if(typeof window>"u")throw new Error("window is undefined");window.addEventListener("message",r=>{var i;if(r.origin!==window.location.origin)throw new Error("Origin breach");((i=r.data)==null?void 0:i.identifier)===t&&e(r.data)})}catch(r){throw console.error("Error while setting up message listener",r),r}}function V(){try{typeof window<"u"&&window.addEventListener("pageshow",v)}catch(e){console.error("Error in disableBackForwardCache method: ",e)}}function v(e){(e.persisted||typeof window.performance<"u"&&window.performance.navigation.type===2)&&window.location.reload()}function H(e){try{let t;e.split(",")[0].indexOf("base64")>=0?t=window.atob(e.split(",")[1]):t=window.unescape(e.split(",")[1]);let r=e.split(",")[0].split(":")[1].split(";")[0],n=new Uint8Array(t.length);for(let o=0;o<t.length;o++)n[o]=t.charCodeAt(o);return new Blob([n],{type:r})}catch{return new Blob}}function J(e,t=0){try{if(b()===E.IOS){if(t||(t=100),e){let n=document.createElement("input");n.style.position="absolute",n.style.top=e.offsetTop+"px",n.style.left=e.offsetLeft+"px",n.style.height="0",n.style.opacity="0",document.body.appendChild(n),n.focus(),setTimeout(function(){e.focus(),e.click(),document.body.removeChild(n)},t)}}else setTimeout(()=>{e==null||e.focus()},t)}catch(r){console.error("Unable to force focus input",r)}}function z(){try{if(typeof window<"u"&&navigator!=null){let e=T(),t=b(),r=null,n=navigator.userAgent;return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile|CriOS/i.test(n)?r=m.MOBILE:r=m.DESKTOP,{browserName:e,userAgent:navigator.userAgent,OSName:t,origin:r}}}catch(e){console.error(`Error with getDeviceDetails ${e}`),u(l.TRACK_LOG,{function:"getDeviceDetails",error:e})}return""}import{default as me}from"lodash.clonedeep";import{default as ye}from"lodash.isequal";function h(e){try{if(e==null||typeof e>"u")return!0;switch(typeof e){case"string":return e.trim()===""||e==="null"||e===null;case"object":return Object.keys(e).length<=0;case"number":return!1;default:return!!(Array.isArray(e)&&e.length<=0)}}catch(t){return u(l.TRACK_LOG,{function:"isEmpty",params:{data:e},error:t}),!0}}function Q(e,t){return new Array(e).fill(t)}function X(e,t){let r=0;try{return t&&e.map((n,o)=>{n.searchId===t&&(r=o)}),r}catch{return console.error("Unable to return the selected tab index"),r}}function ee(e){let t={BLOB:"blob",URL:"url"},{file:r=null,type:n,fileName:o,downloadMethod:i=t.URL,fileExtension:s,fileUrl:f}=e,c=(a,w)=>{if(a){let g=new Blob([a],{type:w});return(window.URL||window.webkitURL).createObjectURL(g)}else throw new Error("file/blob is null")},p=(a,w,g)=>{if(a){let d=document.createElement("a");d.href=a,d.download=`${w}.${g}`,d.target="_blank",document.body.appendChild(d),d.click(),setTimeout(function(){document.body.removeChild(d),window.URL.revokeObjectURL(a)},10)}else throw new Error("fileUrl is empty")};try{if(typeof window>"u")throw new Error("window is undefined");switch(i){case t.BLOB:let a=c(r,n);p(a,o,s);break;case t.URL:p(f,o,s);break}}catch(a){console.error("File download failed - ",a)}}function re(e,t){try{let r=[];for(let o in e)r.push([o,e[o]]);r.sort(function(o,i){return t?i[1]<o[1]?-1:i[1]>o[1]?1:0:o[1]<i[1]?-1:o[1]>i[1]?1:0});let n={};for(let o in r)n[r[o][0]]=r[o][1];return n}catch(r){return console.error("Error in sorting object, original object returned",r),e}}function te(e,t,r=null){function n(i,s,f){var c;return(c=i==null?void 0:i.split(s))==null?void 0:c.join(f)}let o=i=>{let s=["[","]",".."],c=String(i);for(let a in s)c=n(c,s[a],".");let p=c.lastIndexOf(".")===c.length-1;return c=c.slice(0,p?c.lastIndexOf("."):c.length),c};try{let i=String(o(t)).split(".");for(let s of i)e=e==null?void 0:e[s];return typeof e>"u"?r:e}catch(i){return console.error("Error while using getData",i),u(l.TRACK_LOG,{function:"getData",params:{obj:e,path:t,def:r},error:i}),r}}function L(e){try{return Object.keys(e).map(r=>[r,e[r]])}catch(t){throw console.error("There was problem while creating object entries",t),t}}function ne(e,t,r){try{for(let n=0;n<e.length;n++)if(e[n][t]===r)return n;return-1}catch(n){throw console.error("Error while find index by matching object value",n),n}}function oe(e,t=0){try{let r=[...e.split("/")];if(r.length>t){let n=r==null?void 0:r[(r==null?void 0:r.length)-1-t],o=n==null?void 0:n.indexOf("?");return o>=0&&(n=n.substring(0,o)),n}}catch(r){return console.error("Unable to get path variable - ",r),u(l.TRACK_LOG,{function:"getPathVariableFromUrlIndex",params:{url:e,indexFromLast:t},error:r}),""}}function ie(e,t=200,r=!1){let n,o=(...i)=>{!n&&r&&e(...i),clearTimeout(n),n=setTimeout(()=>e(...i),t)};return o.cancel=()=>{clearTimeout(n)},o}function se(e,t){let r=0,n=async(...o)=>{let i=r+t-Date.now();return i<=0?(r=Date.now(),await e(o)):await new Promise(function(f){setTimeout(function(){f(n(o))},i)})};return n}function ce(e,t){try{if(!Array.isArray(e))return[];let r=typeof t=="function"?t:o=>o[t];return[...e.filter(o=>o).reduce((o,i)=>{let s=r(i);return s?o.has(s)?o:o.set(s,i):o},new Map).values()]}catch(r){throw console.error(r),r}}function le(e,t){try{let r=e.length,n=[],o=[];for(let i=0;i<r;i++)t(e[i],i,e)&&(n.push(i-n.length),o.push(e[i]));return n.forEach(i=>e.splice(i,1)),o}catch(r){throw console.error(r),r}}function ue(e,t){try{if(h(e)||typeof e!="object")return{};let r=t.map(String),n={};for(let o in e)r.includes(o)||(n[o]=e[o]);return n}catch(r){return console.error(r),e}}var ae=(e,t=[])=>{try{let r=JSON.parse(e);return typeof r=="object"&&r!==null||Array.isArray(r)?r:t}catch{return t}},fe=(e,t="",r)=>{try{return JSON.parse(e,r)}catch{return t}},de=e=>{try{return e===null||typeof e>"u"?!0:Object.values(e).every(t=>t===0)}catch(t){console.error("Failed with: ",t)}};function A(e){try{let t={};return L(e).forEach(([r,n])=>{n===Object(n)?t[r]=A(n):n!=null&&(t[r]=e[r])}),t}catch(t){throw console.error(t),t}}function pe(e){if(!e)return{};let t={};return t=e.split(";").reduce((r,n)=>{let[o,i]=n.split("=");return r[o.trim()]=i,r},{}),t}export{h as a,Q as b,X as c,ee as d,re as e,te as f,L as g,ne as h,oe as i,ie as j,se as k,ce as l,le as m,ue as n,ae as o,fe as p,de as q,A as r,pe as s,me as t,ye as u,S as v,u as w,R as x,k as y,P as z,B as A,F as B,D as C,I as D,T as E,U as F,b as G,G as H,K as I,N as J,_ as K,j as L,y as M,$ as N,W as O,V as P,H as Q,J as R,z as S};