read-json.js 481 B

123456789101112131415
  1. 'use strict'
  2. module.exports = function (content) {
  3. // Code also yanked from read-package-json.
  4. function stripBOM (content) {
  5. content = content.toString()
  6. // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  7. // because the buffer-to-string conversion in `fs.readFileSync()`
  8. // translates it to FEFF, the UTF-16 BOM.
  9. if (content.charCodeAt(0) === 0xFEFF) return content.slice(1)
  10. return content
  11. }
  12. return JSON.parse(stripBOM(content))
  13. }