Files
pnpm/lib/fs/require_json.js
Zoltan Kochan 9bc97e76d4 style: use more ES6 syntax
Use lebab to transpile ES5 code to ES6.
Use eslint to fix styling issues afterwards.
Run all js in strict mode to allow let/const
in Node 4.
2016-08-23 21:12:01 +03:00

15 lines
369 B
JavaScript

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