file-system
Advanced tools
Comparing version
45
index.js
@@ -24,3 +24,3 @@ /** | ||
callback: util.noop | ||
} | ||
}; | ||
} | ||
@@ -47,2 +47,3 @@ } | ||
* fs.mkdir('1/2/3/4/5', 511); | ||
* fs.mkdir('path/2/3', function(err) {}); | ||
* ``` | ||
@@ -98,3 +99,3 @@ */ | ||
create(filepath); | ||
} | ||
}; | ||
@@ -126,3 +127,3 @@ /** | ||
}); | ||
} | ||
}; | ||
@@ -150,2 +151,38 @@ /** | ||
}); | ||
} | ||
}; | ||
/** | ||
* @description | ||
* Same as writeFile, but it is synchronous | ||
*/ | ||
exports.writeFileSync = function(filename, data, options) { | ||
var dirname = path.dirname(filename); | ||
exports.mkdirSync(dirname); | ||
fs.writeFile(filename, data, options); | ||
}; | ||
/** | ||
* @description | ||
* Recurse into a directory, executing callback for each file. | ||
* and it is asynchronous | ||
* @example | ||
* file.recurse('path', function(filepath, filename) { }); | ||
*/ | ||
exports.recurse = function(dirpath, callback) { | ||
fs.readdir(dirpath, function(err, files) { | ||
if (err) return callback(err); | ||
files.forEach(function(filename) { | ||
var filepath = path.join(dirpath, filename); | ||
fs.stat(filepath, function(err, stats) { | ||
if (stats.isDirectory()) { | ||
exports.recurse(filepath, callback); | ||
} else { | ||
callback(filepath, filename); | ||
} | ||
}); | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "file-system", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Strengthen the ability of file system", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha test" | ||
}, | ||
@@ -15,5 +15,7 @@ "repository": { | ||
"file", | ||
"ecursive", | ||
"recursive", | ||
"recurse", | ||
"fs", | ||
"maker" | ||
"maker", | ||
"node file" | ||
], | ||
@@ -25,3 +27,8 @@ "author": "douzi <liaowei08@gmail.com>", | ||
}, | ||
"homepage": "https://github.com/douzi8/file-system" | ||
"homepage": "https://github.com/douzi8/file-system", | ||
"devDependencies": { | ||
"grunt": "^0.4.5", | ||
"grunt-contrib-jshint": "^0.10.0", | ||
"mocha": "^2.0.1" | ||
} | ||
} |
## file-system | ||
Strengthen the ability of file system. | ||
This module make file opertaion apis simple, you don't need to care the dir exits. and the api is same as node's filesystem. This is no exists time cost. | ||
This module make file opertaion apis simple, you don't need to care the dir exits. and the api is same as node's filesystem. This is no exists time cost for this plugin. | ||
```js | ||
var file = require('file-system'); | ||
file.mkdir('1/2/3/4/5'); | ||
file.mkdirSync('1/2/3/4/5', [mode], function(err) {}); | ||
file.mkdir('1/2/3/4/5', [mode], function(err) {}); | ||
file.mkdirSync('1/2/3/4/5', [mode]); | ||
file.writeFile('path/test.txt', 'aaa', function(err) {}) | ||
@@ -26,2 +26,11 @@ ``` | ||
### file.writeFile | ||
The api is same as node's writeFile | ||
The api is same as node's writeFile | ||
### file.writeFileSync | ||
The api is same as node's writeFile | ||
### file.recurse | ||
Recurse into a directory, executing callback for each file. | ||
```js | ||
file.recurse('path', function(filepath, filename) { }); | ||
``` |
@@ -21,3 +21,3 @@ var util = require('util'); | ||
for (var key in source) { | ||
var value = source[key]; | ||
value = source[key]; | ||
if (Array.isArray(value)) { | ||
@@ -56,3 +56,3 @@ if (!Array.isArray(target[key])) { | ||
return typeof value === 'function'; | ||
} | ||
}; | ||
@@ -69,3 +69,3 @@ exports.hrtime = function(time) { | ||
} | ||
} | ||
}; | ||
@@ -72,0 +72,0 @@ exports.path = {}; |
Sorry, the diff of this file is not supported yet
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
10364
69.76%8
60%330
71.88%0
-100%35
34.62%3
Infinity%3
200%