48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import {format} from 'date-fns'
|
||
import {fr} from 'date-fns/locale'
|
||
|
||
export function formatKonstitisyon(titres, articles) {
|
||
const konstitisyon = []
|
||
|
||
for (const titre of titres) {
|
||
const articlesFromTitres = articles.filter(article => article.titre === titre.id)
|
||
|
||
konstitisyon.push(
|
||
{
|
||
titre: titre.contenu,
|
||
titreId: titre.id,
|
||
articles: articlesFromTitres
|
||
}
|
||
)
|
||
}
|
||
|
||
return konstitisyon
|
||
}
|
||
|
||
export function formatDate(date, formatStr = 'PP', {withTimezone = false} = {}) {
|
||
const formatted = format(date, formatStr, {
|
||
locale: fr
|
||
})
|
||
|
||
if (withTimezone) {
|
||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||
return `${formatted} (${timezone})`
|
||
}
|
||
|
||
return formatted
|
||
}
|
||
|
||
export function hasRestrictedChar(text) {
|
||
const regex = /[<>&"]/g
|
||
|
||
return Boolean(regex.test(text))
|
||
}
|
||
|
||
export function formatFormContent(currentTarget) {
|
||
const formData = new FormData(currentTarget)
|
||
const formJson = Object.fromEntries(formData.entries())
|
||
const {content} = formJson
|
||
|
||
return content.replaceAll('\'', '’')
|
||
}
|