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
|
'use strict';
const realTypes = [
'string',
'boolean',
'integer',
'numeric',
'enumeration',
'set',
'directory name',
'file name',
'byte',
];
/**
* Clean type using real types
* @param {String} type The type
* @return {String|undefined} The cleaned type
*/
const cleanType = function(type) {
if (realTypes.includes(type) === false && typeof type === 'string') {
if (type.match(/in bytes/i) || type.match(/number of bytes/i) || type.match(/size in mb/i)) {
type = 'byte';
} else if (
type.match(/number of/i) ||
type.match(/size of/i) ||
type.match(/in microseconds/i) ||
type.match(/in seconds/i)
) {
type = 'integer';
} else if (
type.match(/numeric (64-bit unsigned integer)/i) ||
type.match(/numeric (32-bit unsigned integer)/i)
) {
type = 'numeric';
} else {
type = undefined;
}
}
return type;
};
const regexCli = /([-]{2})([0-9a-z-_]+)/i;
/**
* Clean cli argument
* @param {String} cli The command line string
* @param {boolean} skipRegex Skip regex check
* @returns {String} The cleaned cli
*/
const cleanCli = function(cli, skipRegex = false) {
if (typeof cli === 'string') {
if (cli.match(/<code\>/i) || cli.match(/<\/code\>/i)) {
cli = cli.replace(/<code\>/gi, '');
cli = cli.replace(/<\/code\>/gi, '');
cli = cli.replace(/\>/gi, '');
cli = cli.replace(/</gi, '');
}
if (!cli.match(regexCli) && skipRegex === false) {
cli = undefined;
}
}
return cli;
};
/**
* Clean the range object
* @param {Object} range The range object
* @returns {Object} The cleaned range object
*/
const cleanRange = function(range) {
if (range !== undefined) {
// clean range
if (typeof range.from !== 'number' || isNaN(range.from)) {
delete range.from;
}
if (typeof range.to === 'string' && range.to.match(/upwards/i)) {
range.to = 'upwards';
} else if (typeof range.to !== 'number' || isNaN(range.to)) {
delete range.to;
}
}
return range;
};
/**
* Clean a default value
* @param {String} defaultValue The default value
* @returns {String} The same or an alternative formated text
*/
const cleanDefault = function(defaultValue) {
return defaultValue
.split('\n')
.map(el => cleanTextDefault(el.trim()))
.join(', ');
};
/**
* Clean text of a default value
* @param {String} defaultTextValue The default text value
* @returns {String} The same or an alternative text
*/
const cleanTextDefault = function(defaultTextValue) {
if (defaultTextValue === 'Autosized (see description)') {
defaultTextValue = '(autosized)';
}
if (defaultTextValue.indexOf('Based on the number of processors') !== -1) {
defaultTextValue = '(based on the number of processors)';
}
if (defaultTextValue === 'The MariaDB data directory') {
defaultTextValue = '(the MariaDB data directory)';
}
if (defaultTextValue.match(/-1 \(signifies (autoscaling); do not assign this literal value\)/g)) {
defaultTextValue = '(-1 signifies autoscaling; do not use -1)';
}
if (defaultTextValue.match(/-1 \(signifies (autosizing); do not assign this literal value\)/g)) {
defaultTextValue = '(-1 signifies autosizing; do not use -1)';
}
return defaultTextValue;
};
module.exports = {
regexCli: regexCli,
cleanType: cleanType,
cleanCli: cleanCli,
cleanRange: cleanRange,
cleanDefault: cleanDefault,
};
|