-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext_filters.js
71 lines (57 loc) · 1.99 KB
/
text_filters.js
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
import Vue from 'vue'
// import CheckValueType from '~/plugins/utils/checkValueType.js'
const getValType = (valueRaw, sep = '|') => {
// console.log("\ngetValType / valueRaw : ", valueRaw ) ;
var valConcat = valueRaw
var valType = typeof valueRaw
// console.log("getValType / valType : ", valType ) ;
// join array
if (valueRaw != null) {
if (valType === 'object' && valueRaw.constructor === Array) {
valConcat = valConcat.join(sep)
valType = 'array'
};
}
// console.log("getValType / valConcat : ", valConcat ) ;
return {
value: valueRaw,
as_str: (valueRaw === null) ? '' : valConcat.toString(),
type: valType
}
}
Vue.filter('json', function (value) {
// console.log("> > > plugin json filter / value : ", value) ;
var pretty = JSON.stringify(value, null, 2)
// console.log("> > > plugin json filter / pretty : ", pretty) ;
return pretty
})
// Vue.filter('capitalize', val => "... from plugins/json_filter.js ..." )
Vue.filter('date_str', function (dateRaw) {
// console.log("> > > plugin date_str filter / dateRaw : ", dateRaw) ;
var cleanDate = new Date(dateRaw).toDateString()
// console.log("> > > plugin date_str filter / cleanDate : ", cleanDate) ;
return cleanDate
})
Vue.filter('truncate', function (value, length, suffix, sep = ' ') {
// console.log("\n> > > plugin truncate filter / value : ", value) ;
if (value === undefined) {
value = ''
}
var valueType = getValType(value, sep)
// console.log("> > > plugin truncate filter / valueType : ", valueType ) ;
var truncated = ''
if (value === null || value === undefined) {
truncated = ''
} else if (valueType.type === 'number') {
truncated = value
} else if (valueType.type === 'array') {
truncated = valueType.as_str
} else {
truncated = value
}
if (truncated.length > length && length > 0) {
truncated = truncated.substring(0, length) + suffix
}
// console.log("> > > plugin truncate filter / truncated : ", truncated ) ;
return truncated
})