Last active
December 27, 2021 16:31
-
-
Save mehuljariwala/a1df17208a3713f227aa3e2eec22ed7d to your computer and use it in GitHub Desktop.
Common Utils for developer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//check if the string is empty of not | |
const isEmpty = (string) => { | |
if (string.trim() === "") return true; | |
else return false; | |
}; | |
//CSS Media queries | |
// @media only screen and (max-width: 320px) {} | |
// @media only screen and (min-width: 480px) {} | |
// @media only screen and (min-width: 768px) {} | |
// @media only screen and (min-width: 1024px) {} | |
// @media only screen and (min-width: 1440px) {} | |
//mobile check | |
function isMobile() { | |
if (window) return window.matchMedia(`(max-width: 767px)`).matches; | |
return false; | |
} | |
//desktop check | |
function isMdScreen() { | |
if (window) return window.matchMedia(`(max-width: 1199px)`).matches; | |
return false; | |
} | |
//random id generater | |
function generateuuId() { | |
return Math.random().toString().substr(2); | |
} | |
//check empty object | |
const isEmptyObject = (object) => { | |
if ( | |
object === null || | |
typeof object === "undefined" || | |
Object.keys(object).length === 0 | |
) { | |
return true; | |
} | |
return false; | |
}; | |
//check number is integer or not | |
function isInt(n){ | |
return Number(n) === n && n % 1 === 0; | |
} | |
//check number is float or not | |
function isFloat(n){ | |
return Number(n) === n && n % 1 !== 0; | |
} | |
//check value is empty | |
const isEmpty = (value) => { | |
if ( | |
value === null || | |
typeof value === "undefined" || | |
value === '' | |
) { | |
return true; | |
} | |
return false; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment