-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (45 loc) · 1.58 KB
/
index.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
const path = require('path')
const defaultOptions = {
name: 'VueCustomTooltip',
color: '#fff',
background: '#000',
borderRadius: 12,
fontWeight: 400,
}
module.exports = (opt = {}, ctx) => {
// Grab user options
let userOptions = Object.assign({}, opt)
// HEX regex: Hash, plus 3 or 6 valid characters
const hexRegex = /^#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/
// Test color for valid HEX
if (userOptions.hasOwnProperty('color') && !hexRegex.test(userOptions.color)) {
delete userOptions.color
}
// Test background for valid HEX
if (userOptions.hasOwnProperty('background') && !hexRegex.test(userOptions.background)) {
delete userOptions.background
}
// borderRadius regex: number between 1-9, then any other numbers
const borderRadiusRegex = /^[0-9]+$/
// Test borderRadius for integer
if (userOptions.hasOwnProperty('borderRadius') && !borderRadiusRegex.test(userOptions.borderRadius)) {
delete userOptions.borderRadius
}
// fontWeight regex: number between 1-9 followed by two zeros
const fontWeightRegex = /^[1-9]{1}00$/
// Test fontWeight for integer
if (userOptions.hasOwnProperty('fontWeight') && !fontWeightRegex.test(userOptions.fontWeight)) {
delete userOptions.fontWeight
}
// Merge options
let options = Object.assign({}, defaultOptions, userOptions)
// Mutate borderRadius
options.borderRadius = options.borderRadius + 'px'
return {
enhanceAppFiles: [path.resolve(__dirname, 'enhanceAppFile.js')],
define: {
VUE_CUSTOM_TOOLTIP_OPTIONS: JSON.stringify(options),
},
globalUIComponents: options.name,
}
}