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
27 lines (24 loc) · 765 Bytes
/
Copy pathfilters.ts
File metadata and controls
27 lines (24 loc) · 765 Bytes
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
import Vue from 'vue'
import { parsePhoneNumber, isValidPhoneNumber } from 'libphonenumber-js'
Vue.filter('phoneNumber', (value: string): string => {
if (!isValidPhoneNumber(value)) {
return value
}
const phoneNumber = parsePhoneNumber(value)
if (phoneNumber) {
return phoneNumber.formatInternational()
}
return 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()
})