• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mac-s-g / react-json-view / #3045

05 Feb 2021 11:19PM UTC coverage: 2.313% (-80.9%) from 83.209%
#3045

push

web-flow
Merge pull request #328 from mac-s-g/bump-minor

quotesOnKeys bugfix

0 of 412 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 2 new or added lines in 1 file covered. (0.0%)

593 existing lines in 29 files now uncovered.

25 of 669 relevant lines covered (3.74%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/js/helpers/parseInput.js
1
export default function parseInput(input) {
2
    //following code is to make a best guess at
3
    //the type for a variable being submitted.
4

5
    //we are working with a serialized data representation
UNCOV
6
    input = input.trim();
×
UNCOV
7
    try {
×
UNCOV
8
        input = JSON.stringify(JSON.parse(input));
×
UNCOV
9
        if (input[0] === '[') {
×
10
            //array
UNCOV
11
            return formatResponse('array', JSON.parse(input));
×
UNCOV
12
        } else if (input[0] === '{') {
×
13
            //object
UNCOV
14
            return formatResponse('object', JSON.parse(input));
×
UNCOV
15
        } else if (
×
16
            input.match(/\-?\d+\.\d+/) &&
×
17
            input.match(/\-?\d+\.\d+/)[0] === input
18
        ) {
19
            //float
UNCOV
20
            return formatResponse('float', parseFloat(input));
×
UNCOV
21
        } else if (
×
22
            input.match(/\-?\d+e-\d+/) &&
×
23
            input.match(/\-?\d+e-\d+/)[0] === input
24
        ) {
25
            //scientific float
UNCOV
26
            return formatResponse('float', Number(input));
×
UNCOV
27
        } else if (
×
28
            input.match(/\-?\d+/) &&
×
29
            input.match(/\-?\d+/)[0] === input
30
        ) {
31
            //integer
UNCOV
32
            return formatResponse('integer', parseInt(input));
×
UNCOV
33
        } else if (
×
34
            input.match(/\-?\d+e\+\d+/) &&
×
35
            input.match(/\-?\d+e\+\d+/)[0] === input
36
        ) {
37
            //scientific integer
38
            return formatResponse('integer', Number(input));
×
39
        }
40
    } catch (e) {
41
        // no-op
42
    }
43

44
    //run in case input was not serializable
UNCOV
45
    input = input.toLowerCase();
×
UNCOV
46
    switch (input) {
×
47
        case 'undefined': {
UNCOV
48
            return formatResponse('undefined', undefined);
×
49
        }
50
        case 'nan': {
UNCOV
51
            return formatResponse('nan', NaN);
×
52
        }
53
        case 'null': {
UNCOV
54
            return formatResponse('null', null);
×
55
        }
56
        case 'true': {
UNCOV
57
            return formatResponse('boolean', true);
×
58
        }
59
        case 'false': {
UNCOV
60
            return formatResponse('boolean', false);
×
61
        }
62
        default: {
63
            //check to see if this is a date
UNCOV
64
            input = Date.parse(input);
×
UNCOV
65
            if (input) {
×
UNCOV
66
                return formatResponse('date', new Date(input));
×
67
            }
68
        }
69
    }
70

UNCOV
71
    return formatResponse(false, null);
×
72
}
73

74
function formatResponse(type, value) {
UNCOV
75
    return {
×
76
        type: type,
77
        value: value
78
    };
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc