-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
105 lines (97 loc) · 2.1 KB
/
index.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import moment from 'https://deno.land/x/[email protected]/mod.ts'
import * as utils from './utils/index.ts'
import { AlfredItem, AlfredItemMod } from './types/index.ts'
function getNowTime(): Array<AlfredItem> {
const now = moment().clone()
return [
{
title: now.unix().toString(),
subtitle: now.unix().toString(),
arg: now.unix().toString(),
icon: {
path: './assets/now.png'
}
},
{
title: now.format('x').toString(),
subtitle: now.format('x').toString(),
arg: now.format('x').toString(),
icon: {
path: './assets/now.png'
}
},
{
title: now.format("YYYY-MM-DD HH:mm:ss").toString(),
subtitle: now.format("YYYY-MM-DD HH:mm:ss").toString(),
arg: now.format('x').toString(),
icon: {
path: './assets/now.png'
}
}
]
}
function parseTime(): Array<AlfredItem> {
const time = Deno.args[1]
if (!time) {
return [{
title: 'The input time is null.',
icon: {
path: './assets/error.png'
}
}]
}
if (+time) {
if (time.length != 10 && time.length != 13) {
throw 'Invalid timestcamp'
}
const parsedTime = moment(time.length == 10 ? +time * 1000 : +time).format("YYYY-MM-DD HH:mm:ss").toString()
return [{
title: parsedTime,
subtitle: `origin: ${time}`,
arg: parsedTime,
icon: {
path: './assets/moment.png'
},
}]
} else {
return [
{
title: moment(time).format('X').toString(),
subtitle: moment(time).format('X').toString(),
arg: moment(time).format('X').toString(),
icon: {
path: './assets/moment.png'
},
},
{
title: moment(time).format('x').toString(),
subtitle: moment(time).format('x').toString(),
arg: moment(time).format('x').toString(),
icon: {
path: './assets/moment.png'
},
}
]
}
}
function main() {
const command = Deno.args[0]
const resultItems: Array<AlfredItem> = []
try {
if (command == 'now') {
resultItems.push(...getNowTime())
} else {
resultItems.push(...parseTime())
}
} catch (e) {
resultItems.push({
title: e,
icon: {
path: './assets/error.png'
}
})
} finally {
utils.sendToAlfred(resultItems)
}
}
main()