-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathvue.ts
157 lines (152 loc) · 3.04 KB
/
vue.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/**
* Indicates whether the attribute name is a Vue event binding.
*
* ---
*
* Example event binding:
* ```
* v-btn(@click="doSomething") Do Something
* ```
*
* In this case `name` is `@click`.
*
* ---
*
* Checks for: `v-on:`.
*
* Also shorthands like `@*` are checked.
*
* ---
*
* @param name Name of tag attribute.
* @returns `true` if `name` passes the vue event binding check, otherwise `false`.
*/
export function isVueEventBinding(name: string): boolean {
return /^(v-on:|@).*/.test(name);
}
/**
* Indicates whether the attribute name is a Vue expression.
*
* ---
*
* Example expression:
* ```
* v-text-field(v-model="value", :label="label") Do Something
* ```
*
* In this case `name` is `v-model` and `:label`.
*
* ---
*
* Checks for: `v-bind`, `v-slot`, `v-model`, `v-if`, `v-else-if`, `v-for`,
* `v-text`, `v-html` and `v-t`.
*
* Also shorthands like `:*` are checked.
*
* ---
*
* @param name Name of tag attribute.
* @returns `true` if `name` passes the vue expression check, otherwise `false`.
*/
export function isVueExpression(name: string): boolean {
return /^((v-(bind|slot))?:|v-(model|slot|if|for|else-if|text|html|t)|#).*/.test(
name,
);
}
/**
* Indicates whether the attribute name is a Vue v-for and includes a `of`.
*
* ---
*
* Example expression:
* ```
* tr(v-for="item of items", :key="item.id")
* ```
*
* In this case `name` is `v-for` and it includes a `of`.
*
* ---
*
* Checks for: `v-for` and `of`.
*
* ---
*
* @param name Name of tag attribute.
* @param val Value of tag attribute.
* @returns `true` if `name` and `val` passes the vue `v-for` with `of` check, otherwise `false`.
*/
export function isVueVForWithOf(name: string, val: string): boolean {
return 'v-for' === name && val.includes('of');
}
/**
* Indicates whether the attribute name is a Vue v-bind.
*
* ---
*
* Example expression:
* ```
* v-btn(v-bind="$attrs")
* ```
*
* In this case `name` is `v-bind`.
*
* ---
*
* Checks for: `v-bind`.
*
* ---
*
* @param name Name of tag attribute.
* @returns `true` if `name` passes the vue `v-bind` check, otherwise `false`.
*/
export function isVueVBindExpression(name: string): boolean {
return 'v-bind' === name;
}
/**
* Indicates whether the attribute name is a Vue v-on.
*
* ---
*
* Example expression:
* ```
* v-btn(v-on="on")
* ```
*
* In this case `name` is `v-on`.
*
* ---
*
* Checks for: `v-on`.
*
* ---
*
* @param name Name of tag attribute.
* @returns `true` if `name` passes the vue `v-on` check, otherwise `false`.
*/
export function isVueVOnExpression(name: string): boolean {
return 'v-on' === name;
}
/**
* Indicates whether the attribute name is a Vue `v-` directive.
*
* ---
*
* Example expression:
* ```
* div(v-some="thing")
* ```
*
* In this case `name` is `v-some`.
*
* ---
*
* Checks for: `v-`.
*
* ---
*
* @param name Name of tag attribute.
* @returns `true` if `name` passes the vue `v-` check, otherwise `false`.
*/
export function isVueVDirective(name: string): boolean {
return name.startsWith('v-');
}