1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-22 21:52:54 +02:00

update to ES2020, some refactoring and cleanups

This commit is contained in:
Morris Brodersen
2022-05-09 15:46:58 +02:00
parent b4c57030f8
commit 2fbfc5e650
26 changed files with 1507 additions and 2129 deletions

View File

@@ -1,54 +1,45 @@
/* global VT */
window.VT = window.VT || {};
VT.uuid = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
export function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
};
}
VT.formatDateId = function (date) {
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
export function formatDateId(date) {
const y = date.getFullYear();
const m = date.getMonth() + 1;
const d = date.getDate();
const ys = y.toString().padStart(4, '0');
const ms = m.toString().padStart(2, '0');
const ds = d.toString().padStart(2, '0');
return (
y.toString().padStart(4, '0') +
'-' +
m.toString().padStart(2, '0') +
'-' +
d.toString().padStart(2, '0')
);
};
return `${ys}-${ms}-${ds}`;
}
VT.formatDate = function (date) {
return (
VT.formatMonth(date) +
' ' +
VT.formatDayOfMonth(date) +
' ' +
date.getFullYear().toString().padStart(4, '0')
);
};
export function formatDate(date) {
const m = formatMonth(date);
const d = formatDayOfMonth(date);
const y = date.getFullYear().toString().padStart(4, '0');
return `${m} ${d} ${y}`;
}
VT.formatDayOfMonth = function (date) {
var d = date.getDate();
var t = d % 10;
export function formatDayOfMonth(date) {
const d = date.getDate();
const t = d % 10;
return d === 11 || d === 12 || d === 13
? d + 'th'
? `${d}th`
: t === 1
? d + 'st'
? `${d}st`
: t === 2
? d + 'nd'
? `${d}nd`
: t === 3
? d + 'rd'
: d + 'th';
};
? `${d}rd`
: `${d}th`;
}
VT.DAY_NAMES = [
export const DAY_NAMES = [
'Sunday',
'Monday',
'Tuesday',
@@ -58,11 +49,11 @@ VT.DAY_NAMES = [
'Saturday',
];
VT.formatDayOfWeek = function (date) {
return VT.DAY_NAMES[date.getDay()];
};
export function formatDayOfWeek(date) {
return DAY_NAMES[date.getDay()];
}
VT.MONTH_NAMES = [
export const MONTH_NAMES = [
'January',
'February',
'March',
@@ -77,6 +68,6 @@ VT.MONTH_NAMES = [
'December',
];
VT.formatMonth = function (date) {
return VT.MONTH_NAMES[date.getMonth()];
};
export function formatMonth(date) {
return MONTH_NAMES[date.getMonth()];
}