Last active
August 13, 2021 05:10
-
-
Save gaurangrshah/e450fdbc6fb357be0624910562ce7082 to your computer and use it in GitHub Desktop.
Vanilla JS Utils
This file contains hidden or 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
export function debounce(func, wait = 20, immediate = true) { | |
var timeout; | |
return function() { | |
var context = this, | |
args = arguments; | |
var later = function() { | |
timeout = null; | |
if (!immediate) func.apply(context, args); | |
}; | |
var callNow = immediate && !timeout; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
if (callNow) func.apply(context, args); | |
}; | |
} | |
/* | |
usage: debounce(anyFunction) | |
*/ |
This file contains hidden or 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
function formatCurrency(amount) { | |
return new Intl.NumberFormat('en-US', { | |
style: 'currency', | |
currency: 'USD', | |
minimumFractionDigits: 2, | |
}).format(amount); | |
} | |
// const zeroCurrency = formatCurrency(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment