updated all functions to use the "const fn = () => {}" syntax
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
export function addGlobalEventListener(
|
||||
export const addGlobalEventListener = (
|
||||
type: string,
|
||||
selector: string,
|
||||
callback: (arg0: Event) => void,
|
||||
options: boolean | AddEventListenerOptions,
|
||||
parent = document
|
||||
): void {
|
||||
): void => {
|
||||
parent.addEventListener(
|
||||
type,
|
||||
e => {
|
||||
@@ -15,10 +15,10 @@ export function addGlobalEventListener(
|
||||
)
|
||||
}
|
||||
|
||||
export function qs(selector: string, parent = document): Element {
|
||||
export const qs = (selector: string, parent = document): Element => {
|
||||
return parent.querySelector(selector)
|
||||
}
|
||||
|
||||
export function qsa(selector: string, parent = document): Element[] {
|
||||
export const qsa = (selector: string, parent = document): Element[] => {
|
||||
return [...parent.querySelectorAll(selector)]
|
||||
}
|
||||
|
@@ -1,20 +1,30 @@
|
||||
const CURRENCY_FORMATTER = new Intl.NumberFormat(undefined, {
|
||||
currency: "EUR",
|
||||
style: "currency",
|
||||
})
|
||||
export function formatCurrency (number: number): string {
|
||||
export const formatCurrency = (
|
||||
number: number,
|
||||
currency: string,
|
||||
locale: string | undefined = undefined
|
||||
): string => {
|
||||
const CURRENCY_FORMATTER = new Intl.NumberFormat(locale, {
|
||||
currency: currency,
|
||||
style: "currency",
|
||||
})
|
||||
return CURRENCY_FORMATTER.format(number)
|
||||
}
|
||||
|
||||
const NUMBER_FORMATTER = new Intl.NumberFormat(undefined)
|
||||
export function formatNumber (number: number): string {
|
||||
export const formatNumber = (
|
||||
number: number,
|
||||
locale: string | undefined = undefined
|
||||
): string => {
|
||||
const NUMBER_FORMATTER = new Intl.NumberFormat(locale)
|
||||
return NUMBER_FORMATTER.format(number)
|
||||
}
|
||||
|
||||
const COMPACT_NUMBER_FORMATTER = new Intl.NumberFormat(undefined, {
|
||||
notation: "compact"
|
||||
})
|
||||
export function formatCompactNumber (number: number): string {
|
||||
export const formatCompactNumber = (
|
||||
number: number,
|
||||
locale: string | undefined = undefined
|
||||
): string => {
|
||||
const COMPACT_NUMBER_FORMATTER = new Intl.NumberFormat(locale, {
|
||||
notation: "compact"
|
||||
})
|
||||
return COMPACT_NUMBER_FORMATTER.format(number)
|
||||
}
|
||||
|
||||
@@ -30,7 +40,7 @@ type DivisionsT = {
|
||||
"minute" | "minutes" |
|
||||
"second" | "seconds"
|
||||
}
|
||||
const DIVISTIONS: DivisionsT[] = [
|
||||
const DIVISIONS: DivisionsT[] = [
|
||||
{ amount: 60, name: "seconds" },
|
||||
{ amount: 60, name: "minutes" },
|
||||
{ amount: 24, name: "hours" },
|
||||
@@ -39,14 +49,18 @@ const DIVISTIONS: DivisionsT[] = [
|
||||
{ amount: 12, name: "months" },
|
||||
{ amount: Number.POSITIVE_INFINITY, name: "years" },
|
||||
]
|
||||
const RELATIVE_DATE_FORMATTER = new Intl.RelativeTimeFormat(undefined, {
|
||||
numeric: "auto"
|
||||
})
|
||||
export function formatRelativeDate(toDate: Date, fromDate: Date = new Date()) {
|
||||
let duration = (toDate.getSeconds() - fromDate.getSeconds()) / 1000
|
||||
export const formatRelativeDate = (
|
||||
toDate: number,
|
||||
fromDate: number = new Date().getSeconds(),
|
||||
locale: string | undefined = undefined
|
||||
): string => {
|
||||
const RELATIVE_DATE_FORMATTER = new Intl.RelativeTimeFormat(locale, {
|
||||
numeric: "auto"
|
||||
})
|
||||
let duration = (toDate - fromDate) / 1000
|
||||
|
||||
for (let i = 0; i <= DIVISTIONS.length; i++) {
|
||||
const division = DIVISTIONS[i]
|
||||
for (let i = 0; i <= DIVISIONS.length; i++) {
|
||||
const division = DIVISIONS[i]
|
||||
if (Math.abs(duration) < division.amount) {
|
||||
return RELATIVE_DATE_FORMATTER.format(Math.round(duration), division.name)
|
||||
}
|
||||
|
@@ -1,3 +1,3 @@
|
||||
export * from "./utils"
|
||||
export * from "./domUtils"
|
||||
export * from "./formatters"
|
||||
export * from "./utils.js"
|
||||
export * from "./domUtils.js"
|
||||
export * from "./formatters.js"
|
||||
|
@@ -1,3 +1,3 @@
|
||||
export function sleep (time: number): Promise<unknown> {
|
||||
export const sleep = (time: number): Promise<unknown> => {
|
||||
return new Promise((resolve => setTimeout(resolve, time)))
|
||||
}
|
||||
|
Reference in New Issue
Block a user