Files
konstitisyon.nu/lib/format.js
T
cedric 7e6dc2a536
Déploiement Frontend BETA / Lint et tests (push) Successful in 1m58s
Déploiement Frontend BETA / Déploiement beta (push) Failing after 6m57s
lint: fix lint errors
2026-05-15 21:26:03 +04:00

48 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 = new 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('\'', '')
}