| Conditions | 7 |
| Paths | 6 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | const {jsonPrettify} = require('./jsonSnip.js') |
||
| 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 | |||
| 34 |