Files
pnpm/lib/fs/require_json.js
2016-01-31 02:04:09 +08:00

13 lines
307 B
JavaScript

var cache = {}
/*
* Works identically to require('/path/to/file.json'), but safer.
*/
module.exports = function requireJson (path) {
path = require('path').resolve(path)
if (cache[path]) return cache[path]
cache[path] = JSON.parse(require('fs').readFileSync(path, 'utf-8'))
return cache[path]
}