All files index.ts

100% Statements 10/10
75% Branches 6/8
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      5x 10x 5x 5x   5x 5x   2x     5x     1x
import { Options } from '../types';
 
function safeParse(str: string, options ?: Options): [any, any] {
  options = options || {};
  const { reviver = null, initialValue = null } = options;
  let json = initialValue;
  let error = null
 
  try {
      json = JSON.parse(str, reviver) || initialValue; // if obj is null, will cover init.
  } catch (err) {
      error = err
  }
 
  return [error, json];
}
 
export default safeParse