-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathutil.js
62 lines (54 loc) · 2.19 KB
/
util.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
// @flow
import Vue from 'vue'
export function throwError (msg: string): void {
throw new Error(`[vue-test-utils]: ${msg}`)
}
export function warn (msg: string): void {
console.error(`[vue-test-utils]: ${msg}`)
}
const camelizeRE = /-(\w)/g
export const camelize = (str: string): string => {
const camelizedStr = str.replace(
camelizeRE,
(_, c) => (c ? c.toUpperCase() : '')
)
return camelizedStr.charAt(0).toLowerCase() + camelizedStr.slice(1)
}
export const htmlTags = [
'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', 'video',
'embed', 'object', 'param', 'source', 'canvas', 'script',
'noscript', 'del', 'ins', 'caption', 'col', 'colgroup', 'table',
'thead', 'tbody', 'td', 'th', 'tr', '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'
]
export const svgElements = [
'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'
]
/**
* Capitalize a string.
*/
export const capitalize = (str: string): string =>
str.charAt(0).toUpperCase() + str.slice(1)
/**
* Hyphenate a camelCase string.
*/
const hyphenateRE = /\B([A-Z])/g
export const hyphenate = (str: string): string =>
str.replace(hyphenateRE, '-$1').toLowerCase()
export const vueVersion = Number(
`${Vue.version.split('.')[0]}.${Vue.version.split('.')[1]}`
)