• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var parseJsonWithErrors = require('json-parse-better-errors')
3var parseJSON = module.exports = function (content) {
4  return parseJsonWithErrors(stripBOM(content))
5}
6
7parseJSON.noExceptions = function (content) {
8  try {
9    return parseJSON(content)
10  } catch (ex) {
11
12  }
13}
14
15// from read-package-json
16function stripBOM (content) {
17  content = content.toString()
18  // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
19  // because the buffer-to-string conversion in `fs.readFileSync()`
20  // translates it to FEFF, the UTF-16 BOM.
21  if (content.charCodeAt(0) === 0xFEFF) {
22    content = content.slice(1)
23  }
24  return content
25}
26