-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathutils.js
More file actions
58 lines (45 loc) · 1.46 KB
/
Copy pathutils.js
File metadata and controls
58 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {
format,
parseISO,
isToday,
} from 'date-fns';
const getDateAsString = function(date) {
const dateObj = typeof date === 'string' ? parseISO(date) : date;
return format(dateObj, 'yyyy-MM-dd')
}
const getDayOfTheWeek = function(date) {
return format(parseISO(date),'EEEE').toLowerCase();
}
// TODO make it somehow that i don't have to pass the debug level every time?
// TODO add different levels of debugging, store them in a object or something so they have labels maybe?
const debugLog = function(message, currentDebugLevel, requiredLevel, pluginName = 'Habit Tracker 21') {
if(!currentDebugLevel) return null;
if(requiredLevel && requiredLevel!==currentDebugLevel) return null;
console.log(`[${pluginName}]`, message);
}
const pluralize = function(count, singular, plural) {
if (count === 1) return singular
return plural || singular + 's'
}
const renderPrettyDate = function (dateString) {
// Parse the input date string into a Date object
const date = parseISO(dateString)
let prettyDate = window.moment(date).format('ll')
let prefix = isToday(date) ? 'Today' : window.moment(date).format('ddd')
prettyDate = `${prefix}, ${prettyDate}`;
return prettyDate
}
const isValidCSSColor = function (color) {
if (!color) return false
const tempEl = document.createElement('div')
tempEl.style.color = color
return tempEl.style.color !== ''
}
export {
getDateAsString,
getDayOfTheWeek,
debugLog,
renderPrettyDate,
pluralize,
isValidCSSColor
};