forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidators.js
148 lines (125 loc) · 3.88 KB
/
validators.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
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
// @flow
import { throwError, capitalize, camelize, hyphenate } from './util'
export function isDomSelector (selector: any): boolean {
if (typeof selector !== 'string') {
return false
}
try {
if (typeof document === 'undefined') {
throwError(
`mount must be run in a browser environment like ` +
`PhantomJS, jsdom or chrome`
)
}
} catch (error) {
throwError(
`mount must be run in a browser environment like ` +
`PhantomJS, jsdom or chrome`
)
}
try {
document.querySelector(selector)
return true
} catch (error) {
return false
}
}
export function isVueComponent (c: any): boolean {
if (isConstructor(c)) {
return true
}
if (c === null || typeof c !== 'object') {
return false
}
if (c.extends || c._Ctor) {
return true
}
if (typeof c.template === 'string') {
return true
}
return typeof c.render === 'function'
}
export function componentNeedsCompiling (component: Component): boolean {
return (
component &&
!component.render &&
(component.template || component.extends || component.extendOptions) &&
!component.functional
)
}
export function isRefSelector (refOptionsObject: any): boolean {
if (
typeof refOptionsObject !== 'object' ||
Object.keys(refOptionsObject || {}).length !== 1
) {
return false
}
return typeof refOptionsObject.ref === 'string'
}
export function isNameSelector (nameOptionsObject: any): boolean {
if (typeof nameOptionsObject !== 'object' || nameOptionsObject === null) {
return false
}
return !!nameOptionsObject.name
}
export function isConstructor (c: any) {
return typeof c === 'function' && c.cid
}
export function isDynamicComponent (c: any) {
return typeof c === 'function' && !c.cid
}
export function isComponentOptions (c: any) {
return typeof c === 'object' && (c.template || c.render)
}
export function templateContainsComponent (
template: string,
name: string
): boolean {
return [capitalize, camelize, hyphenate].some(format => {
const re = new RegExp(`<${format(name)}\\s*(\\s|>|(\/>))`, 'g')
return re.test(template)
})
}
export function isPlainObject (c: any): boolean {
return Object.prototype.toString.call(c) === '[object Object]'
}
export function isRequiredComponent (name: string): boolean {
return (
name === 'KeepAlive' || name === 'Transition' || name === 'TransitionGroup'
)
}
function makeMap (
str: string,
expectsLowerCase?: boolean
) {
var map = Object.create(null)
var list = str.split(',')
for (var i = 0; i < list.length; i++) {
map[list[i]] = true
}
return expectsLowerCase
? function (val: string) { return map[val.toLowerCase()] }
: function (val: string) { return map[val] }
}
export const isHTMLTag = makeMap(
'html,body,base,head,link,meta,style,title,' +
'address,article,aside,footer,header,h1,h2,h3,h4,h5,h6,hgroup,nav,section,' +
'div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,' +
'a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,rtc,ruby,' +
's,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,' +
'embed,object,param,source,canvas,script,noscript,del,ins,' +
'caption,col,colgroup,table,thead,tbody,td,th,tr,video,' +
'button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,' +
'output,progress,select,textarea,' +
'details,dialog,menu,menuitem,summary,' +
'content,element,shadow,template,blockquote,iframe,tfoot'
)
// this map is intentionally selective, only covering SVG elements that may
// contain child elements.
export const isSVG = makeMap(
'svg,animate,circle,clippath,cursor,defs,desc,ellipse,filter,font-face,' +
'foreignObject,g,glyph,image,line,marker,mask,missing-glyph,path,pattern,' +
'polygon,polyline,rect,switch,symbol,text,textpath,tspan,use,view',
true
)
export const isReservedTag = (tag: string) => isHTMLTag(tag) || isSVG(tag)