File / Directory |
Mutation score |
# Killed |
# Survived |
# Timeout |
# No coverage |
# Runtime errors |
# Transpile errors |
Total detected |
Total undetected |
Total mutants | |
---|---|---|---|---|---|---|---|---|---|---|---|
validate-data.js | 84.21 | 48 | 9 | 0 | 0 | 0 | 0 | 48 | 9 | 57 |
import { getValueByName } from './get-data';
/**
* Check rule for dependencies
* @param {*} params - validation params
* @param {object} data - form data
* @returns {*} - validation params or null if rule is not checkable
*/
export function isCheckable(params, data) 0{}{
if (1false2true3params!params) 4{}{
return null;
}
let checkable = 5falsetrue;
let param = params;
if (6false7trueArray.isArray(params)) 8{}{
let dependencies = [];
[param, ...dependencies] = params;
if (9false10true11param!param) 12{}{
return null;
}
try 13{}{
checkable = dependencies.reduce(
(required, dependency) =>
14required || (typeof dependency === 'function' ? dependency(data) : !!data[dependency])15false16truerequired && (17typeof dependency !== 'function'18false19truetypeof dependency === 20""'function' ? dependency(data) : 21!data[dependency]!22data[dependency]!data[dependency]),
checkable,
);
} catch (e) 23{}{
if (24false25true26process.env.NODE_ENV !== 'development'process.env.NODE_ENV === 27""'development') 28{}{
console.warn(29""`Dependency function error: ${e.toString()}`);
}
}
}
return checkable ? param : null;
}
/**
* Validate field
* @param {object} rules - object with rules for validation
* @param {object} methods - validation methods
* @param {string|FileList|Array} value - input value
* @param {string} name - input name
* @param {object} errorMessages - object with error messages
* @param {object} data - form data
* @param {function} translate - translation function
* @returns {Array.<string>} - array of field errors
*/
export function validateField(rules, methods, value, name, errorMessages, data, translate) 30{}{
const isEmpty = 31methods.required.func(value)!methods.required.func(value);
const isRequired = isCheckable(rules.required, data);
if (32false33true34isEmpty || isRequiredisEmpty && isRequired) 35{}{
return 36[][translate(errorMessages[name].required)];
}
if (37false38trueisEmpty) 39{}{
return [];
}
return Object.keys(rules).reduce((errors, method) => 40{}{
const params = isCheckable(rules[method], data);
if (41false42true43params !== nullparams === null) 44{}{
return errors;
}
if (45false46truemethods[method]) 47{}{
const valid = methods[method].func(value, params);
if (48false49true50valid!valid) 51{}{
errors.push(translate(errorMessages[name][method]));
}
} else 52{}{
errors.push(53""`Method "${method}" not found`); // todo translation
}
return errors;
}, []);
}
/**
* Validate data object
* @param {object} rules - object with rules for validation
* @param {object} methods - validation methods
* @param {object} data - data object
* @param {object} errorMessages - object with error messages
* @param {function} translate - translation function
* @returns {object.<string, Array.<string>>} - object of fields error arrays
*/
export function validateData(rules, methods, data, errorMessages, translate) 54{}{
return Object.keys(rules).reduce((obj, name) => 55{}{
const value = getValueByName(name, data);
const errors = validateField(rules[name], methods, value, name, errorMessages, data, translate); // eslint-disable-line max-len
return 56{}{
...obj,
[name]: errors.length ? errors : undefined,
};
}, {});
}
# | Mutator | State | Location | Original | Replacement |
---|---|---|---|---|---|
0 | Block | Killed | 8 : 42 | {
... ;
} |
{} |
1 | IfStatement | Killed | 9 : 8 | ! |
|
2 | IfStatement | Killed | 9 : 8 | ! |
|
3 | PrefixUnaryExpression | Killed | 9 : 8 | ! |
|
4 | Block | Killed | 9 : 17 | {
... } |
{} |
5 | BooleanSubstitution | Killed | 13 : 20 |
|
|
6 | IfStatement | Killed | 16 : 8 | . ... ) |
|
7 | IfStatement | Killed | 16 : 8 | . ... ) |
|
8 | Block | Killed | 16 : 31 | {
... } |
{} |
9 | IfStatement | Killed | 19 : 12 | ! |
|
10 | IfStatement | Killed | 19 : 12 | ! |
|
11 | PrefixUnaryExpression | Killed | 19 : 12 | ! |
|
12 | Block | Killed | 19 : 20 | {
... } |
{} |
13 | Block | Killed | 23 : 12 | {
... } |
{} |
14 | BinaryExpression | Killed | 26 : 20 | && ( ... ]) |
|| ( ... ]) |
15 | ConditionalExpression | Killed | 26 : 20 | && ( ... ]) |
|
16 | ConditionalExpression | Killed | 26 : 20 | && ( ... ]) |
|
17 | BinaryExpression | Killed | 26 : 33 | === ' ' |
!== ' ' |
18 | ConditionalExpression | Killed | 26 : 33 | === ' ' |
|
19 | ConditionalExpression | Killed | 26 : 33 | === ' ' |
|
20 | StringLiteral | Killed | 26 : 55 | ' ' |
"" |
21 | PrefixUnaryExpression | Killed | 26 : 87 | !! ... ] |
! ... ] |
22 | PrefixUnaryExpression | Killed | 26 : 88 | ! ... ] |
[ ] |
23 | Block | Survived | 29 : 20 | {
... } |
{} |
24 | IfStatement | Survived | 30 : 16 | . .... ' |
|
25 | IfStatement | Survived | 30 : 16 | . .... ' |
|
26 | BinaryExpression | Survived | 30 : 16 | . .... ' |
. .... ' |
27 | StringLiteral | Survived | 30 : 41 | ' ' |
"" |
28 | Block | Survived | 30 : 56 | {
... } |
{} |
29 | StringLiteral | Survived | 31 : 29 | ` ... ()}` |
"" |
30 | Block | Killed | 50 : 91 | {
...]);
} |
{} |
31 | PrefixUnaryExpression | Killed | 51 : 20 | ! ... ) |
. ... ) |
32 | IfStatement | Killed | 55 : 8 | && |
|
33 | IfStatement | Killed | 55 : 8 | && |
|
34 | BinaryExpression | Killed | 55 : 8 | && |
|| |
35 | Block | Killed | 55 : 31 | {
... } |
{} |
36 | ArrayLiteral | Killed | 56 : 15 | [ ... )] |
[] |
37 | IfStatement | Survived | 59 : 8 |
|
|
38 | IfStatement | Killed | 59 : 8 |
|
|
39 | Block | Survived | 59 : 17 | {
... } |
{} |
40 | Block | Killed | 63 : 57 | {
... } |
{} |
41 | IfStatement | Killed | 66 : 12 | === |
|
42 | IfStatement | Killed | 66 : 12 | === |
|
43 | BinaryExpression | Killed | 66 : 12 | === |
!== |
44 | Block | Killed | 66 : 29 | {
... } |
{} |
45 | IfStatement | Killed | 70 : 12 | [ ] |
|
46 | IfStatement | Killed | 70 : 12 | [ ] |
|
47 | Block | Killed | 70 : 29 | {
... } |
{} |
48 | IfStatement | Killed | 73 : 16 | ! |
|
49 | IfStatement | Killed | 73 : 16 | ! |
|
50 | PrefixUnaryExpression | Killed | 73 : 16 | ! |
|
51 | Block | Killed | 73 : 24 | {
... } |
{} |
52 | Block | Killed | 76 : 15 | {
... } |
{} |
53 | StringLiteral | Killed | 77 : 24 | ` ... ` |
"" |
54 | Block | Killed | 93 : 77 | {
...});
} |
{} |
55 | Block | Killed | 94 : 52 | {
... } |
{} |
56 | ObjectLiteral | Killed | 97 : 15 | {
... } |
{} |