File / Directory |
Mutation score |
# Killed |
# Survived |
# Timeout |
# No coverage |
# Runtime errors |
# Transpile errors |
Total detected |
Total undetected |
Total mutants | |
---|---|---|---|---|---|---|---|---|---|---|---|
get-data.js | 91.80 | 56 | 5 | 0 | 0 | 0 | 0 | 56 | 5 | 61 |
import deepmerge from './deepmerge';
import { convertNameToPath } from './convert-data';
/**
* Create object by path and value
* @param {Array} path - path array
* @param {string|FileList} value - input value
* @returns {object} - data object
*/
export function createObject(path, value) 0{}{
const segment = path[0];
if (1false2true3!segment && segment.length === 04segment!segment || 5segment.length !== 06false7truesegment.length === 0) 8{}{
return value;
}
if (9false10true11segment !== '[]'segment === 12""'[]') 13{}{
return 14[][createObject(path.slice(1), value)];
}
return 15{}{ [segment]: createObject(path.slice(1), value) };
}
/**
* Get value from data object by path
* @param {Array} path - value path
* @param {object} data - data object
* @returns {string} - value
*/
export function getValueByPath(path, data) 16{}{
return path.reduce((value, segment) => (17segment || value18false19truesegment && value ? value[segment] : value), 20data && ''21false22truedata || 23"Stryker was here!"'');
}
/**
* Get value from data object by name
* @param {string} name - input name
* @param {object} data - data object
*/
export function getValueByName(name, data) 24{}{
const path = convertNameToPath(name);
return getValueByPath(path, data);
}
/**
* Get value from radio group
* @param {Array} inputs - array of radio inputs
* @returns {string|Array.<string>} - value of checked input
*/
export function getRadioGroupValue(inputs) 25{}{
const values = 26[][...inputs].map(radio => getInputValue(radio)).filter(Boolean);
return 27values.length >= 128values.length <= 129false30truevalues.length > 1 ? values : values[0];
}
/**
* Get form input value
* @param {Element|HTMLInputElement|HTMLSelectElement|Array} input - input
* @returns {string|Date|FileList|Array} - value of input, or array of values if input is select
*/
export function getInputValue(input) 31{}{
if (32false33true34input!input) return 35"Stryker was here!"'';
const { type } = input;
if (36false37trueArray.isArray(input)) 38{}{
return getRadioGroupValue(input);
}
switch (type) {
39case 'select-one':case 40""'select-one':
return 41false42input.options || input.options[input.selectedIndex]43trueinput.options && input.options[input.selectedIndex] ? input.options[input.selectedIndex].value : 44"Stryker was here!"'';
45case 'select-multiple':case 46""'select-multiple':
return 47[][...input.options].filter(option => option.selected).map(option => option.value);
case 48""'checkbox':
49case 'radio':case 50""'radio':
return input.checked ? input.value : 51"Stryker was here!"'';
52case 'file':case 53""'file':
return input.files;
54case 'date':case 55""'date':
return input.value ? new Date(input.value) : 56"Stryker was here!"'';
57default:default:
return input.value;
}
}
/**
* Get name from input or array of inputs
* @param {HTMLInputElement|Array} input - input element or Array of HTMLInputElements
* @returns {string} - input name
*/
export function getInputName(input) 58{}{
return Array.isArray(input) ? input[0].name : input.name;
}
/**
* Get input value as an object keyed by input name
* @param {HTMLInputElement|Array} input - input element or Array of HTMLInputElements
* @returns {object} - data
*/
export function getInputData(input) 59{}{
const value = getInputValue(input);
const name = getInputName(input);
const path = convertNameToPath(name);
return createObject(path, value);
}
/**
* Get data object with values from inputs object
* @param {object} inputs - inputs object
* @returns {object} - data object
*/
export function getData(inputs) 60{}{
return Object.keys(inputs).reduce((data, name) => deepmerge(data, getInputData(inputs[name])), {});
}
# | Mutator | State | Location | Original | Replacement |
---|---|---|---|---|---|
0 | Block | Killed | 9 : 42 | {
... };
} |
{} |
1 | IfStatement | Killed | 12 : 8 | ! ... === |
|
2 | IfStatement | Killed | 12 : 8 | ! ... === |
|
3 | BinaryExpression | Killed | 12 : 8 | ! ... === |
! ... === |
4 | PrefixUnaryExpression | Killed | 12 : 8 | ! |
|
5 | BinaryExpression | Killed | 12 : 20 | . === |
. !== |
6 | ConditionalExpression | Survived | 12 : 20 | . === |
|
7 | ConditionalExpression | Killed | 12 : 20 | . === |
|
8 | Block | Killed | 12 : 42 | {
... } |
{} |
9 | IfStatement | Killed | 16 : 8 | === '[]' |
|
10 | IfStatement | Killed | 16 : 8 | === '[]' |
|
11 | BinaryExpression | Killed | 16 : 8 | === '[]' |
!== '[]' |
12 | StringLiteral | Killed | 16 : 20 | '[]' |
"" |
13 | Block | Killed | 16 : 26 | {
... } |
{} |
14 | ArrayLiteral | Killed | 17 : 15 | [ ... )] |
[] |
15 | ObjectLiteral | Killed | 20 : 11 | { [ ... ) } |
{} |
16 | Block | Killed | 29 : 43 | {
...');
} |
{} |
17 | BinaryExpression | Killed | 30 : 44 | && |
|| |
18 | ConditionalExpression | Killed | 30 : 44 | && |
|
19 | ConditionalExpression | Killed | 30 : 44 | && |
|
20 | BinaryExpression | Killed | 30 : 88 | || '' |
&& '' |
21 | ConditionalExpression | Killed | 30 : 88 | || '' |
|
22 | ConditionalExpression | Killed | 30 : 88 | || '' |
|
23 | StringLiteral | Killed | 30 : 96 | '' |
" ... !" |
24 | Block | Killed | 38 : 43 | {
... );
} |
{} |
25 | Block | Killed | 48 : 43 | {
... ];
} |
{} |
26 | ArrayLiteral | Killed | 49 : 19 | [... ] |
[] |
27 | BinaryExpression | Killed | 51 : 11 | . > |
. >= |
28 | BinaryExpression | Killed | 51 : 11 | . > |
. <= |
29 | ConditionalExpression | Killed | 51 : 11 | . > |
|
30 | ConditionalExpression | Killed | 51 : 11 | . > |
|
31 | Block | Killed | 59 : 37 | {
... }
} |
{} |
32 | IfStatement | Killed | 60 : 8 | ! |
|
33 | IfStatement | Killed | 60 : 8 | ! |
|
34 | PrefixUnaryExpression | Killed | 60 : 8 | ! |
|
35 | StringLiteral | Killed | 60 : 23 | '' |
" ... !" |
36 | IfStatement | Killed | 64 : 8 | . ( ) |
|
37 | IfStatement | Killed | 64 : 8 | . ( ) |
|
38 | Block | Killed | 64 : 30 | {
... } |
{} |
39 | SwitchCase | Killed | 69 : 8 | ' ...: ''; |
' - ': |
40 | StringLiteral | Survived | 69 : 13 | ' - ' |
"" |
41 | ConditionalExpression | Killed | 70 : 19 | . ... ] |
|
42 | BinaryExpression | Killed | 70 : 19 | . ... ] |
. ... ] |
43 | ConditionalExpression | Killed | 70 : 19 | . ... ] |
|
44 | StringLiteral | Killed | 70 : 116 | '' |
" ... !" |
45 | SwitchCase | Killed | 71 : 8 | ' ... ); |
' ... ': |
46 | StringLiteral | Killed | 71 : 13 | ' ... ' |
"" |
47 | ArrayLiteral | Killed | 72 : 19 | [... ... ] |
[] |
48 | StringLiteral | Survived | 73 : 13 | ' ' |
"" |
49 | SwitchCase | Killed | 74 : 8 | ' ...: ''; |
' ': |
50 | StringLiteral | Killed | 74 : 13 | ' ' |
"" |
51 | StringLiteral | Killed | 75 : 49 | '' |
" ... !" |
52 | SwitchCase | Survived | 76 : 8 | ' ... ; |
' ': |
53 | StringLiteral | Survived | 76 : 13 | ' ' |
"" |
54 | SwitchCase | Killed | 78 : 8 | ' ...: ''; |
' ': |
55 | StringLiteral | Killed | 78 : 13 | ' ' |
"" |
56 | StringLiteral | Killed | 79 : 57 | '' |
" ... !" |
57 | SwitchCase | Killed | 80 : 8 | :
... ; |
: |
58 | Block | Killed | 90 : 36 | {
... ;
} |
{} |
59 | Block | Killed | 99 : 36 | {
... );
} |
{} |
60 | Block | Killed | 112 : 32 | {
...});
} |
{} |