forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
36 lines (30 loc) · 869 Bytes
/
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
// @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)
}
/**
* 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]}`
)