file-system
Advanced tools
Comparing version 2.0.0 to 2.1.0
{ | ||
"name": "file-system", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Strengthen the ability of file system", | ||
"main": "index.js", | ||
"main": "file-system.js", | ||
"scripts": { | ||
@@ -20,4 +20,4 @@ "test": "mocha test" | ||
"node file", | ||
"base64", | ||
"mkdir" | ||
"mkdir", | ||
"rmdir" | ||
], | ||
@@ -24,0 +24,0 @@ "author": "douzi <liaowei08@gmail.com>", |
121
README.md
@@ -6,7 +6,7 @@ # file-system — Simplified file system | ||
```js | ||
var file = require('file-system'); | ||
var fs = require('file-system'); | ||
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) {}) | ||
fs.mkdir('1/2/3/4/5', [mode], function(err) {}); | ||
fs.mkdirSync('1/2/3/4/5', [mode]); | ||
fs.writeFile('path/test.txt', 'aaa', function(err) {}) | ||
``` | ||
@@ -20,32 +20,38 @@ | ||
## API | ||
### file.fs | ||
### .fs | ||
file extend node fs origin methods, and overwrite some methods with next list chart | ||
if you want to use origin method, choose file.fs[method] | ||
```js | ||
var file = require('file-system'); | ||
var fs = require('fs'); | ||
file.readFile === fs.readFile // true | ||
``` | ||
file.existsSync === file.fs.existsSync // true | ||
file.fs.mkdirSync // orign method | ||
``` | ||
### file.mkdir | ||
### .mkdir | ||
The api is same as node's mkdir | ||
### file.mkdirSync | ||
### .mkdirSync | ||
The api is same as node's mkdir | ||
### file.writeFile | ||
### .writeFile | ||
The api is same as node's writeFile | ||
### file.writeFileSync | ||
### .writeFileSync | ||
The api is same as node's writeFile | ||
### file.fileMatch | ||
### .fileMatch | ||
The api equal [file-match](https://github.com/douzi8/file-match) | ||
### file.copyFile | ||
### .copyFile(srcpath, destpath, options) | ||
Asynchronously copy a file into newpath | ||
``` | ||
file.copyFile('deom.png', 'dest/demo.png', { | ||
done: function() { | ||
* {string} ``srcpath`` required | ||
* {string} ``destpath`` required | ||
* {object} ``options`` | ||
* {string} ``options.encoding`` [options.encoding=utf8] | ||
* {function} ``options.done(err)`` | ||
* {function} ``options.process(content)`` | ||
The process argument must return processed content | ||
```js | ||
fs.copyFile('deom.png', 'dest/demo.png', { | ||
done: function(err) { | ||
console.log('done'); | ||
@@ -56,7 +62,7 @@ } | ||
### file.copyFileSync | ||
Copy a file into newpath | ||
### .copyFileSync(srcpath, destpath, options) | ||
The api same as copyFile, but it's synchronous | ||
```js | ||
file.copyFileSync('demo.png', 'dest/demo.png'); | ||
file.copyFileSync('demo.css', 'dest/demo.css', { | ||
fs.copyFileSync('demo.png', 'dest/demo.png'); | ||
fs.copyFileSync('demo.css', 'dest/demo.css', { | ||
process: function(contents) { | ||
@@ -68,10 +74,13 @@ return contents; | ||
### file.recurse | ||
### .recurse(dirpath, filter, callback) | ||
Recurse into a directory, executing callback for each file and folder. | ||
if the filename is undefiend, the callback is for folder, otherwise for file. | ||
And you can pass filter params for filter file. | ||
* {string} ``dirpath`` required | ||
* {string|array|function} ``filter`` | ||
If the filter is function, executing callback for all files and folder | ||
* {function} ``callback(filepath, filename)`` | ||
```js | ||
file.recurse('path', function(filepath, filename) { }); | ||
fs.recurse('path', function(filepath, filename) { }); | ||
file.recurse('path', [ | ||
fs.recurse('path', [ | ||
'*.css', | ||
@@ -90,3 +99,3 @@ '**/*.js', | ||
// Only using files | ||
file.recurse('path', function(filepath, filename) { | ||
fs.recurse('path', function(filepath, filename) { | ||
if (!filename) return; | ||
@@ -97,10 +106,10 @@ }); | ||
### file.recurseSync | ||
Same as recurse, but it is synchronous | ||
### .recurseSync(dirpath, filter, callback) | ||
The api is same as recurse, but it is synchronous | ||
```js | ||
file.recurseSync('path', function(filepath, filename) { | ||
fs.recurseSync('path', function(filepath, filename) { | ||
}); | ||
file.recurseSync('path', ['**/*.js', 'path/**/*.html'], function(filepath, filename) { | ||
fs.recurseSync('path', ['**/*.js', 'path/**/*.html'], function(filepath, filename) { | ||
@@ -110,23 +119,30 @@ }); | ||
### file.rmdirSync | ||
### .rmdirSync(dirpath) | ||
Recurse into a directory, remove all of the files and folder in this directory. | ||
```js | ||
file.rmdirSync('path'); | ||
fs.rmdirSync('path'); | ||
``` | ||
### file.copySync | ||
### .copySync(dirpath, destpath, options) | ||
Recurse into a directory, copy all files into dest. | ||
Pass options filter params to filter files. | ||
if you want to change the dest filepath, process callback return { contents: '', filepath: ''}, | ||
otherwise only change contents. | ||
* {string} ``dirpath`` required | ||
* {string} ``destpath`` required | ||
* {object} ``options`` | ||
* {string|array} ``options.filter`` | ||
* {function} ``options.process(contents, filepath)`` | ||
If custom the destpath, return object, otherwise return content | ||
* {string|array} ``options.noProcess`` | ||
```js | ||
file.copySync('path', 'dest', { clear: true }); | ||
fs.copySync('path', 'dest', { clear: true }); | ||
file.copySync('src', 'dest/src'); | ||
fs.copySync('src', 'dest/src'); | ||
file.copySync('src', 'dest/src', { filter: ['*.js', 'path/**/*.css'] }); | ||
fs.copySync('src', 'dest/src', { filter: ['*.js', 'path/**/*.css'] }); | ||
file.copySync('path', 'dest', { | ||
fs.copySync('path', 'dest', { | ||
noProcess: '**/*.{jpg, png}', // Don't process images | ||
process: function(contents, filepath) { | ||
// only process file content | ||
return contents; | ||
// or custom destpath | ||
return { | ||
@@ -140,19 +156,8 @@ contents: '', | ||
//Handler self files | ||
file.copySync('path', 'path', { filter: ['*.html.js'], process: function(contents, filepath) {} }); | ||
fs.copySync('path', 'path', { filter: ['*.html.js'], process: function(contents, filepath) {} }); | ||
``` | ||
options | ||
* filter | ||
* process | ||
* noProcess | ||
### file.base64 | ||
Read image file, callback with base64 data | ||
```js | ||
file.base64('img.png', function(err, data) { | ||
}); | ||
``` | ||
### file.base64Sync | ||
```js | ||
var base64 = file.base64Sync('img.png'); | ||
``` | ||
### .base64 | ||
Deprecated, move to [base64](https://github.com/douzi8/base64-img#base64filename-callback) | ||
### .base64Sync | ||
Deprecated, move to [base64Sync](https://github.com/douzi8/base64-img#base64syncfilename) |
var assert = require("assert"); | ||
var file = require('../index'); | ||
var file = require('../file-system'); | ||
var fs = require('fs'); | ||
@@ -4,0 +4,0 @@ var path = require('path'); |
var assert = require("assert"); | ||
var file = require('../index'); | ||
var file = require('../file-system'); | ||
var fs = require('fs'); | ||
@@ -4,0 +4,0 @@ var path = require('path'); |
var assert = require("assert"); | ||
var file = require('../index'); | ||
var file = require('../file-system'); | ||
var path = require('path'); | ||
@@ -4,0 +4,0 @@ var fs = require('fs'); |
var assert = require("assert"); | ||
var file = require('../index'); | ||
var file = require('../file-system'); | ||
var path = require('path'); | ||
@@ -4,0 +4,0 @@ var fs = require('fs'); |
var assert = require("assert"); | ||
var file = require('../index'); | ||
var file = require('../file-system'); | ||
var fs = require('fs'); | ||
@@ -4,0 +4,0 @@ var path = require('path'); |
var assert = require("assert"); | ||
var file = require('../index'); | ||
var file = require('../file-system'); | ||
var fs = require('fs'); | ||
@@ -4,0 +4,0 @@ var path = require('path'); |
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
155
29192
12
811