fsify
Advanced tools
Comparing version 2.0.4 to 3.0.0
@@ -7,2 +7,14 @@ # Changelog | ||
## [3.0.0] - 2018-08-25 | ||
### Changed | ||
- Improved JSDoc annotation | ||
- Removed `prepublish` script from `package.json` | ||
- Only support Node.js 8+ | ||
### Fixed | ||
- Assert parameter order in tests | ||
## [2.0.4] - 2017-08-08 | ||
@@ -9,0 +21,0 @@ |
{ | ||
"name": "fsify", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"authors": [ | ||
@@ -35,19 +35,16 @@ "Tobias Reich <tobias@electerious.com>" | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"test": "nyc node_modules/mocha/bin/_mocha", | ||
"prepublish": "npm test" | ||
"test": "nyc node_modules/mocha/bin/_mocha" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.1", | ||
"coveralls": "^2.13.1", | ||
"nyc": "^11.1.0", | ||
"mocha": "^3.5.0", | ||
"uuid": "^3.1.0" | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.0", | ||
"nyc": "^12.0.1", | ||
"mocha": "^5.1.1", | ||
"uuid": "^3.2.1" | ||
}, | ||
"dependencies": { | ||
"del": "^3.0.0", | ||
"is-path-inside": "^1.0.0", | ||
"is-plain-obj": "^1.1.0", | ||
"once": "^1.4.0", | ||
"pify": "^3.0.0" | ||
"is-path-inside": "^2.0.0", | ||
"is-plain-obj": "^1.1.0" | ||
} | ||
} |
# fsify | ||
[![Travis Build Status](https://travis-ci.org/electerious/fsify.svg?branch=master)](https://travis-ci.org/electerious/fsify) [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/q5eqc7vv8ndyx2ib?svg=true)](https://ci.appveyor.com/project/electerious/fsify) [![Coverage Status](https://coveralls.io/repos/github/electerious/fsify/badge.svg?branch=master)](https://coveralls.io/github/electerious/fsify?branch=master) [![Dependencies](https://david-dm.org/electerious/fsify.svg)](https://david-dm.org/electerious/fsify#info=dependencies) | ||
[![Travis Build Status](https://travis-ci.org/electerious/fsify.svg?branch=master)](https://travis-ci.org/electerious/fsify) [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/q5eqc7vv8ndyx2ib?svg=true)](https://ci.appveyor.com/project/electerious/fsify) [![Coverage Status](https://coveralls.io/repos/github/electerious/fsify/badge.svg?branch=master)](https://coveralls.io/github/electerious/fsify?branch=master) [![Dependencies](https://david-dm.org/electerious/fsify.svg)](https://david-dm.org/electerious/fsify#info=dependencies) [![Greenkeeper badge](https://badges.greenkeeper.io/electerious/fsify.svg)](https://greenkeeper.io/) | ||
@@ -140,3 +140,3 @@ Convert an array of objects into a persistent or temporary directory structure. | ||
```js | ||
const fs = require('fs') | ||
const fs = require('fs') | ||
const fsify = require('fsify')() | ||
@@ -201,3 +201,3 @@ | ||
- `{Promise}({Array})` A promise that resolves a structure. Equal to the input structure, but parsed and with a absolute path as the name. | ||
- `{Promise<Array>}` A promise that resolves a structure. Equal to the input structure, but parsed and with a absolute path as the name. | ||
@@ -204,0 +204,0 @@ ## Structure |
@@ -11,9 +11,9 @@ 'use strict' | ||
* @param {Boolean} persistent | ||
* @returns {Promise} Returns the following properties if resolved: {Array}. | ||
* @returns {Promise<Array>} Original structure passed to the function. | ||
*/ | ||
module.exports = function(structure = [], bin, persistent) { | ||
return new Promise((resolve, reject) => { | ||
return new Promise((resolve) => { | ||
if (persistent===false) { | ||
if (persistent === false) { | ||
@@ -20,0 +20,0 @@ const flattenedStructure = flatten(structure) |
@@ -19,3 +19,3 @@ 'use strict' | ||
if (isDirectory===true) { | ||
if (isDirectory === true) { | ||
@@ -22,0 +22,0 @@ entries = [ |
'use strict' | ||
const isPlainObj = require('is-plain-obj') | ||
const isPlainObj = require('is-plain-obj') | ||
const isDirectory = require('./isDirectory') | ||
const isFile = require('./isFile') | ||
const isFile = require('./isFile') | ||
@@ -11,17 +11,13 @@ /** | ||
* @param {Object} entry - An object that represents a directory or file. | ||
* @returns {Object} entry - Parsed entry. | ||
*/ | ||
module.exports = function(entry) { | ||
if (isPlainObj(entry)===false) { | ||
if (isPlainObj(entry) === false) { | ||
throw new Error(`Each entry of 'structure' must be an object`) | ||
} | ||
const name = entry.name | ||
const type = entry.type | ||
const contents = entry.contents | ||
const mode = entry.mode | ||
const encoding = entry.encoding | ||
const flag = entry.flag | ||
const { name, type, contents, mode, encoding, flag } = entry | ||
if (typeof name!=='string') { | ||
if (typeof name !== 'string') { | ||
throw new Error(`Each directory and file must have a 'name'`) | ||
@@ -31,5 +27,5 @@ } | ||
const _isDirectory = isDirectory(type) | ||
const _isFile = isFile(type) | ||
const _isFile = isFile(type) | ||
if (_isDirectory===false && _isFile===false) { | ||
if (_isDirectory === false && _isFile === false) { | ||
throw new Error(`Each entry must have a known 'type'`) | ||
@@ -39,12 +35,12 @@ } | ||
return { | ||
name : name, | ||
type : type, | ||
contents : contents, | ||
mode : mode, | ||
encoding : encoding, | ||
flag : flag, | ||
isDirectory : _isDirectory, | ||
isFile : _isFile | ||
name: name, | ||
type: type, | ||
contents: contents, | ||
mode: mode, | ||
encoding: encoding, | ||
flag: flag, | ||
isDirectory: _isDirectory, | ||
isFile: _isFile | ||
} | ||
} |
'use strict' | ||
const path = require('path') | ||
const once = require('once') | ||
const isPlainObj = require('is-plain-obj') | ||
const path = require('path') | ||
const isPlainObj = require('is-plain-obj') | ||
const parseStructure = require('./parseStructure') | ||
const writeStructure = require('./writeStructure') | ||
const binStructure = require('./binStructure') | ||
const cleanup = require('./cleanup') | ||
const binStructure = require('./binStructure') | ||
const cleanup = require('./cleanup') | ||
@@ -24,3 +23,3 @@ /** | ||
* @param {?Array} structure - Array of objects containing information about a directory or file. | ||
* @returns {Promise} Returns the following properties if resolved: {Array}. | ||
* @returns {Promise<Array>} Parsed structure. | ||
*/ | ||
@@ -31,3 +30,3 @@ const main = function(structure = []) { | ||
if (Array.isArray(structure)===false) { | ||
if (Array.isArray(structure) === false) { | ||
throw new Error(`'structure' must be an array`) | ||
@@ -63,5 +62,5 @@ } | ||
main.DIRECTORY = module.exports.DIRECTORY | ||
main.FILE = module.exports.FILE | ||
main.FILE = module.exports.FILE | ||
if (isPlainObj(opts)===false) { | ||
if (isPlainObj(opts) === false) { | ||
throw new Error(`'opts' must be an object, null or undefined`) | ||
@@ -71,5 +70,5 @@ } | ||
opts = Object.assign({ | ||
cwd : process.cwd(), | ||
persistent : true, | ||
force : false | ||
cwd: process.cwd(), | ||
persistent: true, | ||
force: false | ||
}, opts) | ||
@@ -81,3 +80,3 @@ | ||
// Add cleanup listener when files shouldn't be persistent | ||
if (opts.persistent===false) process.addListener('exit', main.cleanup) | ||
if (opts.persistent === false) process.addListener('exit', main.cleanup) | ||
@@ -95,2 +94,2 @@ return main | ||
module.exports.DIRECTORY = 'directory' | ||
module.exports.FILE = 'file' | ||
module.exports.FILE = 'file' |
@@ -14,3 +14,3 @@ 'use strict' | ||
if (type===DIRECTORY) return true | ||
if (type === DIRECTORY) return true | ||
@@ -17,0 +17,0 @@ return false |
@@ -14,3 +14,3 @@ 'use strict' | ||
if (type===FILE) return true | ||
if (type === FILE) return true | ||
@@ -17,0 +17,0 @@ return false |
'use strict' | ||
const path = require('path') | ||
const path = require('path') | ||
const isPathInside = require('is-path-inside') | ||
const get = require('./get') | ||
const get = require('./get') | ||
@@ -13,3 +13,3 @@ /** | ||
* @param {Function} parseStructure - Function that parses an array that represents a directory structure. | ||
* @returns {Promise} Returns the following properties if resolved: {Object}. | ||
* @returns {Promise<Object>} Parsed entry. | ||
*/ | ||
@@ -27,13 +27,13 @@ module.exports = function(entry, cwd, parseStructure) { | ||
if (absolutePath===cwd) { | ||
if (absolutePath === cwd) { | ||
throw new Error(`Entry name points to the same path as the surrounding structure`) | ||
} | ||
if (isPathInside(absolutePath, cwd)===false) { | ||
if (isPathInside(absolutePath, cwd) === false) { | ||
throw new Error(`Entry name points to a path outside the cwd`) | ||
} | ||
if (isDirectory===true) { | ||
if (isDirectory === true) { | ||
if (contents!=null && Array.isArray(contents)===false) { | ||
if (contents != null && Array.isArray(contents) === false) { | ||
throw new Error(`Entry type is 'directory' and 'contents' must be an array, null or undefined`) | ||
@@ -49,5 +49,5 @@ } | ||
if (isFile===true) { | ||
if (isFile === true) { | ||
if (Array.isArray(contents)===true) { | ||
if (Array.isArray(contents) === true) { | ||
throw new Error(`Entry type is 'file', but 'contents' is an array and should be a string or a buffer`) | ||
@@ -54,0 +54,0 @@ } |
@@ -10,3 +10,3 @@ 'use strict' | ||
* @param {String} cwd - Directory to start from. | ||
* @returns {Promise} Returns the following properties if resolved: {Array}. | ||
* @returns {Promise<Array>} Parsed structure. | ||
*/ | ||
@@ -13,0 +13,0 @@ module.exports = function(structure = [], cwd) { |
'use strict' | ||
const fs = require('fs') | ||
const pify = require('pify') | ||
const util = require('util') | ||
const fs = require('fs') | ||
@@ -16,5 +16,5 @@ /** | ||
return pify(fs.mkdir)(path, mode) | ||
.catch((err) => { if (err.code!=='EEXIST') throw err }) | ||
return util.promisify(fs.mkdir)(path, mode) | ||
.catch((err) => { if (err.code !== 'EEXIST') throw err }) | ||
} |
'use strict' | ||
const get = require('./get') | ||
const get = require('./get') | ||
const writeDirectory = require('./writeDirectory') | ||
const writeFile = require('./writeFile') | ||
const writeFile = require('./writeFile') | ||
@@ -12,3 +12,3 @@ /** | ||
* @param {Function} writeStructure - Function that converts an array into a directory structure. | ||
* @returns {Promise} Returns the following properties if resolved: {Object}. | ||
* @returns {Promise<Object>} Original entry passed to the function. | ||
*/ | ||
@@ -21,3 +21,3 @@ module.exports = function(entry, writeStructure) { | ||
if (isDirectory===true) { | ||
if (isDirectory === true) { | ||
@@ -31,3 +31,3 @@ return writeDirectory(name, mode) | ||
if (isFile===true) { | ||
if (isFile === true) { | ||
@@ -34,0 +34,0 @@ return writeFile(name, contents, encoding, mode, flag) |
'use strict' | ||
const fs = require('fs') | ||
const pify = require('pify') | ||
const util = require('util') | ||
const fs = require('fs') | ||
@@ -18,3 +18,3 @@ /** | ||
return pify(fs.writeFile)(path, data, { | ||
return util.promisify(fs.writeFile)(path, data, { | ||
encoding, | ||
@@ -21,0 +21,0 @@ mode, |
@@ -9,3 +9,3 @@ 'use strict' | ||
* @param {?Array} structure - Array of objects containing information about a directory or file. | ||
* @returns {Promise} Returns the following properties if resolved: {Array}. | ||
* @returns {Promise<Array>} Original structure passed to the function. | ||
*/ | ||
@@ -12,0 +12,0 @@ module.exports = function(structure = []) { |
Sorry, the diff of this file is not supported yet
24810
3
19
317
+ Addedis-path-inside@2.1.0(transitive)
- Removedonce@^1.4.0
- Removedpify@^3.0.0
Updatedis-path-inside@^2.0.0