suitest-js-api 3.7.0 → 3.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,7 +8,7 @@ const {invalidInputMessage} = require('../texts');
|
|
|
8
8
|
*/
|
|
9
9
|
const repeatComposer = makeModifierComposer(composers.REPEAT, ['repeat'], (_, meta, value) => ({
|
|
10
10
|
...meta,
|
|
11
|
-
repeat: validate(validators.
|
|
11
|
+
repeat: validate(validators.ST_VAR_OR_POSITIVE_NUMBER_NOT_ZERO, value, invalidInputMessage('repeat', 'Repeat')),
|
|
12
12
|
}));
|
|
13
13
|
|
|
14
14
|
module.exports = repeatComposer;
|
|
@@ -4,6 +4,7 @@ const validationKeys = {
|
|
|
4
4
|
NON_EMPTY_STRING: Symbol('nonEmptyString'),
|
|
5
5
|
POSITIVE_NUMBER: Symbol('positiveNumber'),
|
|
6
6
|
ST_VAR_OR_POSITIVE_NUMBER: Symbol('stVarOrPositiveNumber'),
|
|
7
|
+
ST_VAR_OR_POSITIVE_NUMBER_NOT_ZERO: Symbol('stVarOrPositiveNumberNotZero'),
|
|
7
8
|
ST_VAR_OR_NUMBER: Symbol('stVarOrNumber'),
|
|
8
9
|
NON_EMPTY_STRING_OR_UNDEFINED: Symbol('nonEmptyStringOrUndefined'),
|
|
9
10
|
NON_EMPTY_STRING_OR_NUll: Symbol('nonEmptyStringOrNull'),
|
|
@@ -153,6 +153,14 @@ const validatePositiveNumber = (val, name) => {
|
|
|
153
153
|
return val;
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
+
const validatePositiveNumberNotZero = (val, name) => {
|
|
157
|
+
if (!Number.isFinite(val) || val <= 0) {
|
|
158
|
+
throwError(name + ' should be positive number');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return val;
|
|
162
|
+
};
|
|
163
|
+
|
|
156
164
|
const validateNumber = (val, name) => {
|
|
157
165
|
if (!Number.isFinite(val)) {
|
|
158
166
|
throwError(name + ' should be number');
|
|
@@ -161,11 +169,15 @@ const validateNumber = (val, name) => {
|
|
|
161
169
|
return val;
|
|
162
170
|
};
|
|
163
171
|
|
|
164
|
-
const createStVarOrNumberValidator = (onlyPositiveNumber = false) => (val, name) => {
|
|
172
|
+
const createStVarOrNumberValidator = (onlyPositiveNumber = false, biggerThanZero = false) => (val, name) => {
|
|
165
173
|
if (!['number', 'string'].includes(typeof val)) {
|
|
166
174
|
throwError(name + ' should be suitest configuration variable or number');
|
|
167
175
|
} else if (typeof val === 'number') {
|
|
168
|
-
(onlyPositiveNumber
|
|
176
|
+
if (onlyPositiveNumber && biggerThanZero) {
|
|
177
|
+
(validatePositiveNumberNotZero)(val, name);
|
|
178
|
+
} else {
|
|
179
|
+
(onlyPositiveNumber ? validatePositiveNumber : validateNumber)(val, name);
|
|
180
|
+
}
|
|
169
181
|
} else if (typeof val === 'string' && !/^<%.+%>$/.test(val)) {
|
|
170
182
|
throwError(name + ' should be suitest configuration variable');
|
|
171
183
|
}
|
|
@@ -175,6 +187,7 @@ const createStVarOrNumberValidator = (onlyPositiveNumber = false) => (val, name)
|
|
|
175
187
|
|
|
176
188
|
const validateStVarOrNumber = createStVarOrNumberValidator();
|
|
177
189
|
const validateStVarOrPositiveNumber = createStVarOrNumberValidator(true);
|
|
190
|
+
const validateStVarOrPositiveNumberNotZero = createStVarOrNumberValidator(true, true);
|
|
178
191
|
|
|
179
192
|
const validateNonEmptyStringOrUndefined = (val, name) => {
|
|
180
193
|
if (typeof val === 'string' && val.length || val === undefined) {
|
|
@@ -292,5 +305,6 @@ module.exports = {
|
|
|
292
305
|
validateNonEmptyArrayOfStrings,
|
|
293
306
|
validateStVarOrNumber,
|
|
294
307
|
validateStVarOrPositiveNumber,
|
|
308
|
+
validateStVarOrPositiveNumberNotZero,
|
|
295
309
|
validateTapTypeAndDuration,
|
|
296
310
|
};
|
|
@@ -14,6 +14,9 @@ const validatorsMap = {
|
|
|
14
14
|
[validationKeys.ST_VAR_OR_POSITIVE_NUMBER]: (value, text) => {
|
|
15
15
|
return validators.validateStVarOrPositiveNumber(value, text);
|
|
16
16
|
},
|
|
17
|
+
[validationKeys.ST_VAR_OR_POSITIVE_NUMBER_NOT_ZERO]: (value, text) => {
|
|
18
|
+
return validators.validateStVarOrPositiveNumberNotZero(value, text);
|
|
19
|
+
},
|
|
17
20
|
[validationKeys.ST_VAR_OR_NUMBER]: (value, text) => {
|
|
18
21
|
return validators.validateStVarOrNumber(value, text);
|
|
19
22
|
},
|
package/package.json
CHANGED