Total Complexity | 12 |
Complexity/F | 6 |
Lines of Code | 33 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | const {jsonPrettify} = require('./jsonSnip.js') |
||
2 | |||
3 | export function setInputType (inpObj, newType) { // only exported for testing purposes |
||
4 | if (typeof inpObj.type === 'undefined' || inpObj.type === '') { // type has not previously been set |
||
5 | inpObj.type = newType |
||
6 | if (newType === 'json') { |
||
7 | inpObj.json = JSON.parse(inpObj.text) |
||
8 | jsonPrettify(inpObj) // sets default output options for json |
||
9 | return true |
||
10 | } else if (newType === 'plain') { |
||
11 | inpObj.plain = inpObj.text |
||
12 | return true |
||
13 | } else { |
||
14 | return false |
||
15 | } |
||
16 | } else if (inpObj.type !== newType) { // it's already been set to something else so there's a problem |
||
17 | if (typeof inpObj.error === 'undefined') { inpObj.error = [] } |
||
18 | inpObj.error.push('cannot mix options designed to process different types of file') |
||
19 | return false |
||
20 | } else { |
||
21 | return true |
||
22 | } |
||
23 | } |
||
24 | |||
25 | export function removeQuotes (str) { |
||
26 | // if the passed string has matching encapsulating quotes these are removed |
||
27 | if ((str.substr(0, 1) === '\'' && str.substr(-1) === '\'') || |
||
28 | (str.substr(0, 1) === '"' && str.substr(-1) === '"')) { |
||
29 | return str.substr(1, str.length - 2) |
||
30 | } else { |
||
31 | return str |
||
32 | } |
||
33 | } |
||
34 |