"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/jju/lib/utils.js" (11 Apr 2017, 1260 Bytes) of package /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 var FS  = require('fs')
    2 var jju = require('../')
    3 
    4 // this function registers json5 extension, so you
    5 // can do `require("./config.json5")` kind of thing
    6 module.exports.register = function() {
    7   var r = require, e = 'extensions'
    8   r[e]['.json5'] = function(m, f) {
    9     /*eslint no-sync:0*/
   10     m.exports = jju.parse(FS.readFileSync(f, 'utf8'))
   11   }
   12 }
   13 
   14 // this function monkey-patches JSON.parse, so it
   15 // will return an exact position of error in case
   16 // of parse failure
   17 module.exports.patch_JSON_parse = function() {
   18   var _parse = JSON.parse
   19   JSON.parse = function(text, rev) {
   20     try {
   21       return _parse(text, rev)
   22     } catch(err) {
   23       // this call should always throw
   24       require('jju').parse(text, {
   25         mode: 'json',
   26         legacy: true,
   27         reviver: rev,
   28         reserved_keys: 'replace',
   29         null_prototype: false,
   30       })
   31 
   32       // if it didn't throw, but original parser did,
   33       // this is an error in this library and should be reported
   34       throw err
   35     }
   36   }
   37 }
   38 
   39 // this function is an express/connect middleware
   40 // that accepts uploads in application/json5 format
   41 module.exports.middleware = function() {
   42   return function(req, res, next) {
   43     throw Error('this function is removed, use express-json5 instead')
   44   }
   45 }
   46