wallet-core/node_modules/load-json-file/index.js

12 lines
422 B
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
2017-05-27 17:36:13 +02:00
const path = require('path');
const fs = require('graceful-fs');
const stripBom = require('strip-bom');
const parseJson = require('parse-json');
const pify = require('pify');
2016-10-10 03:43:44 +02:00
2017-05-27 17:36:13 +02:00
const parse = (data, fp) => parseJson(stripBom(data), path.relative('.', fp));
2016-10-10 03:43:44 +02:00
2017-05-27 17:36:13 +02:00
module.exports = fp => pify(fs.readFile)(fp, 'utf8').then(data => parse(data, fp));
module.exports.sync = fp => parse(fs.readFileSync(fp, 'utf8'), fp);