-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
51 lines (46 loc) · 882 Bytes
/
utils.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
import _ from 'lodash'
export function parseTemplate(value: string): string {
try {
return _.template(value)({})
} catch {
// There will be a ReferenceError if the template string will contain variables
return value
}
}
export function parseIntSafe(
value: string | undefined,
defaultValue: number
): number {
const parsed = parseInt(value || '', 10)
return isNaN(parsed) ? defaultValue : parsed
}
export function parseYamlBoolean(value: string): boolean | null {
const trueValues = [
'true',
'True',
'TRUE',
'yes',
'Yes',
'YES',
'on',
'On',
'ON'
]
const falseValues = [
'false',
'False',
'FALSE',
'no',
'No',
'NO',
'off',
'Off',
'OFF'
]
if (trueValues.includes(value)) {
return true
} else if (falseValues.includes(value)) {
return false
}
return null
}