update note display
This commit is contained in:
26
src/utils/helpers.ts
Normal file
26
src/utils/helpers.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { formatDistance, format, isToday } from 'date-fns'
|
||||
|
||||
export const formatDate = (date: Date | number): string => {
|
||||
const dateToFormat = ['number', 'string'].includes(typeof date)
|
||||
? new Date(date)
|
||||
: date
|
||||
const dateDistanceInWords = formatDistance(dateToFormat, new Date()) + ' ago'
|
||||
|
||||
return isToday(date)
|
||||
? dateDistanceInWords
|
||||
: format(date, 'D MMMM [at] HH:mm ')
|
||||
}
|
||||
|
||||
export const getAllMatches = (
|
||||
regex: RegExp,
|
||||
input: string
|
||||
): RegExpExecArray[] => {
|
||||
const matches = []
|
||||
let m
|
||||
do {
|
||||
m = regex.exec(input)
|
||||
// console.log(m)
|
||||
if (m) matches.push(m)
|
||||
} while (m)
|
||||
return matches
|
||||
}
|
||||
Reference in New Issue
Block a user