]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/read-package-json/node_modules/json-parse-helpfulerror/node_modules/jju/lib/utils.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / read-package-json / node_modules / json-parse-helpfulerror / node_modules / jju / lib / utils.js
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