aboutsummaryrefslogtreecommitdiff
path: root/node_modules/write-json-file/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-03-27 21:01:33 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-03-27 21:01:33 +0100
commitcc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585 (patch)
tree92c5d88706a6ffc654d1b133618d357890e7096b /node_modules/write-json-file/index.js
parent3771b4d6b67b34c130f3a9a1a15f42deefdb2eda (diff)
remove node_modules
Diffstat (limited to 'node_modules/write-json-file/index.js')
-rw-r--r--node_modules/write-json-file/index.js73
1 files changed, 0 insertions, 73 deletions
diff --git a/node_modules/write-json-file/index.js b/node_modules/write-json-file/index.js
deleted file mode 100644
index cbd7e706a..000000000
--- a/node_modules/write-json-file/index.js
+++ /dev/null
@@ -1,73 +0,0 @@
-'use strict';
-const path = require('path');
-const fs = require('graceful-fs');
-const writeFileAtomic = require('write-file-atomic');
-const sortKeys = require('sort-keys');
-const makeDir = require('make-dir');
-const pify = require('pify');
-const detectIndent = require('detect-indent');
-
-const init = (fn, fp, data, opts) => {
- if (!fp) {
- throw new TypeError('Expected a filepath');
- }
-
- if (data === undefined) {
- throw new TypeError('Expected data to stringify');
- }
-
- opts = Object.assign({
- indent: '\t',
- sortKeys: false
- }, opts);
-
- if (opts.sortKeys) {
- data = sortKeys(data, {
- deep: true,
- compare: typeof opts.sortKeys === 'function' && opts.sortKeys
- });
- }
-
- return fn(fp, data, opts);
-};
-
-const readFile = fp => pify(fs.readFile)(fp, 'utf8').catch(() => {});
-
-const main = (fp, data, opts) => {
- return (opts.detectIndent ? readFile(fp) : Promise.resolve())
- .then(str => {
- const indent = str ? detectIndent(str).indent : opts.indent;
- const json = JSON.stringify(data, opts.replacer, indent);
-
- return pify(writeFileAtomic)(fp, `${json}\n`, {mode: opts.mode});
- });
-};
-
-const mainSync = (fp, data, opts) => {
- let indent = opts.indent;
-
- if (opts.detectIndent) {
- try {
- const file = fs.readFileSync(fp, 'utf8');
- indent = detectIndent(file).indent;
- } catch (err) {
- if (err.code !== 'ENOENT') {
- throw err;
- }
- }
- }
-
- const json = JSON.stringify(data, opts.replacer, indent);
-
- return writeFileAtomic.sync(fp, `${json}\n`, {mode: opts.mode});
-};
-
-module.exports = (fp, data, opts) => {
- return makeDir(path.dirname(fp), {fs})
- .then(() => init(main, fp, data, opts));
-};
-
-module.exports.sync = (fp, data, opts) => {
- makeDir.sync(path.dirname(fp), {fs});
- init(mainSync, fp, data, opts);
-};