All files jsonp_helper.js

100% Statements 9/9
100% Branches 0/0
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  5x 5x 5x 5x     5x   5x   2x 2x       4x      
function parseJSONP(jsonpData) {
  try {
    const startPos = jsonpData.indexOf('({');
    const endPos = jsonpData.lastIndexOf('})');
    let jsonString = jsonpData.substring(startPos + 1, endPos + 1);
 
    // remove escaped single quotes since they are not valid json
    jsonString = jsonString.replace(/\\'/g, "'");
 
    return JSON.parse(jsonString);
  } catch (e) {
    const error = new Error(`Failed to convert jsonp to json. ${e.message}`);
    throw error;
  }
}
 
module.exports = {
  parseJSONP
};