"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/utils/parse-json.js" (8 Mar 2017, 592 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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