Add date formatter, language and text direction settings

This commit is contained in:
prototypa
2023-01-08 12:28:59 -05:00
parent a210c72431
commit 8ce8421334
12 changed files with 121 additions and 65 deletions

View File

@ -1,9 +1,21 @@
import { DATE_FORMATTER } from '~/config.mjs';
const formatter =
DATE_FORMATTER ||
new Intl.DateTimeFormat('en', {
year: 'numeric',
month: 'short',
day: 'numeric',
timeZone: 'UTC'
});
/* eslint-disable no-mixed-spaces-and-tabs */
export const getFormattedDate = (date: Date) =>
date
? new Date(date).toLocaleDateString('en-us', {
year: 'numeric',
month: 'short',
day: 'numeric',
})
: '';
export const getFormattedDate = (date: Date) => (date ? formatter.format(date) : '');
export const trim = (str = '', ch?: string) => {
let start = 0,
end = str.length || 0;
while (start < end && str[start] === ch) ++start;
while (end > start && str[end - 1] === ch) --end;
return start > 0 || end < str.length ? str.substring(start, end) : str;
};