-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
40 lines (34 loc) · 1.01 KB
/
util.js
File metadata and controls
40 lines (34 loc) · 1.01 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
function isValidDate(obj) {
return (obj instanceof Date && isFinite(obj))
}
const dateStringFrom = (property) => {
return function dateStringGetter() {
return this[property] ? this[property].toLocaleDateString('pt-BR', { year: 'numeric', month: '2-digit', day: '2-digit', timeZone: 'America/Fortaleza' }) : undefined
}
}
const timeStringFrom = (property) => {
return function timeStringGetter() {
return this[property] ? this[property].toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit', timeZone: 'America/Fortaleza' }) : undefined
}
}
function deleteIdTransform(doc, ret, options) {
delete ret.id
delete ret._id
return ret
}
function applyTransforms(...transforms) {
return function transformChain(doc, ret, options) {
const final = transforms.reduce((prev, curr, index) => {
const result = curr(doc, prev, options)
return result
}, ret)
return final
}
}
module.exports = {
isValidDate,
dateStringFrom,
timeStringFrom,
applyTransforms,
deleteIdTransform
}