forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilters.ts
More file actions
66 lines (57 loc) · 1.7 KB
/
filters.ts
File metadata and controls
66 lines (57 loc) · 1.7 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
59
60
61
62
63
64
65
66
import Vue from 'vue'
import { intervalToDuration, formatDuration } from 'date-fns'
import { parsePhoneNumber, isValidPhoneNumber } from 'libphonenumber-js'
export const formatPhoneNumber = (value: string) => {
if (!isValidPhoneNumber(value)) {
return value
}
const phoneNumber = parsePhoneNumber(value)
if (phoneNumber) {
return phoneNumber.formatInternational()
}
return value
}
Vue.filter('phoneNumber', (value: string): string => {
return formatPhoneNumber(value)
})
Vue.filter('phoneCountry', (value: string): string => {
const phoneNumber = parsePhoneNumber(value)
if (phoneNumber && phoneNumber.country) {
// @ts-ignore
const regionNames = new Intl.DisplayNames(undefined, { type: 'region' })
return regionNames.of(phoneNumber.country) ?? 'earth'
}
return 'Earth'
})
Vue.filter('timestamp', (value: string): string => {
return new Date(value).toLocaleString()
})
Vue.filter('money', (value: string): string => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
}).format(parseInt(value))
})
Vue.filter('decimal', (value: string): string => {
return new Intl.NumberFormat('en-US', {
style: 'decimal',
}).format(parseInt(value))
})
Vue.filter('billingPeriod', (value: string): string => {
const options = {
year: 'numeric',
month: 'long',
}
// @ts-ignore
return new Date(value).toLocaleDateString('en-US', options)
})
Vue.filter('humanizeTime', (value: string): string => {
const durations = intervalToDuration({
start: new Date(),
end: new Date(value),
})
return formatDuration(durations)
})
Vue.filter('capitalize', (value: string): string => {
return value.charAt(0).toUpperCase() + value.slice(1)
})