Created
February 3, 2021 17:19
-
-
Save eoguvo/265842629506f881e7ad2be92c88ab6d to your computer and use it in GitHub Desktop.
Generic Util
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
class Util { | |
static #defaultFormart = Intl.NumberFormat("en-us", { | |
currency: "BRL", | |
style: "currency" | |
}); | |
static formatDate(date) { | |
let d = new Date(date), | |
month = '' + (d.getMonth() + 1), | |
day = '' + (d.getDate() + 1), | |
year = d.getFullYear(); | |
if (month.length < 2) | |
month = '0' + month; | |
if (day.length < 2) | |
day = '0' + day; | |
return [day, month, year].join('/'); | |
} | |
static formatCurrency(value) { | |
return this.#defaultFormart.format(value); | |
} | |
static unFormartCurrency(value) { | |
value = String(value); | |
return Number(value.replace(/\D/g, '')) / 100; | |
} | |
} | |
export default Util; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment