write-json-file
Advanced tools
Comparing version 1.0.0 to 1.1.0
23
index.js
'use strict'; | ||
var path = require('path'); | ||
var fs = require('graceful-fs'); | ||
var writeFileAtomic = require('write-file-atomic'); | ||
var sortKeys = require('sort-keys'); | ||
var objectAssign = require('object-assign'); | ||
var mkdirp = require('mkdirp'); | ||
var Promise = require('pinkie-promise'); | ||
@@ -9,2 +12,10 @@ var pify = require('pify'); | ||
function main(fn, fp, data, opts) { | ||
if (!fp) { | ||
throw new TypeError('Expected a filepath'); | ||
} | ||
if (data === undefined) { | ||
throw new TypeError('Expected data to stringify'); | ||
} | ||
opts = objectAssign({ | ||
@@ -27,3 +38,11 @@ indent: '\t', | ||
module.exports = main.bind(null, pify(writeFileAtomic, Promise)); | ||
module.exports.sync = main.bind(null, writeFileAtomic.sync); | ||
module.exports = function (fp, data, opts) { | ||
return pify(mkdirp, Promise)(path.dirname(fp), {fs: fs}).then(function () { | ||
return main(pify(writeFileAtomic, Promise), fp, data, opts); | ||
}); | ||
}; | ||
module.exports.sync = function (fp, data, opts) { | ||
mkdirp.sync(path.dirname(fp), {fs: fs}); | ||
main(writeFileAtomic.sync, fp, data, opts); | ||
}; |
{ | ||
"name": "write-json-file", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Stringify and write JSON to a file atomically", | ||
@@ -36,2 +36,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"graceful-fs": "^4.1.2", | ||
"mkdirp": "^0.5.1", | ||
"object-assign": "^4.0.1", | ||
@@ -38,0 +40,0 @@ "pify": "^1.1.0", |
@@ -5,3 +5,5 @@ # write-json-file [![Build Status](https://travis-ci.org/sindresorhus/write-json-file.svg?branch=master)](https://travis-ci.org/sindresorhus/write-json-file) | ||
Creates directories for you as needed. | ||
## Install | ||
@@ -8,0 +10,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4731
38
74
7
+ Addedgraceful-fs@^4.1.2
+ Addedmkdirp@^0.5.1
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)