Promise-based file-system adapter and transmogrifier.
Install
$ npm install --save spiff
Usage
The simplest usage of spiff
copies files from one location to another.
; ;
That's all well and good, but it's not very interesting. Let's change the files.
; // Replace all whitespace with a single space. ;
That did the trick. But look at all that code just to change one property. We can do better.
; // Replace all whitespace with a single space. ;
Now we're talking! But we're spitting out each file individually. Let's bundle them.
; // Replace all whitespace with a single space. // Concatenate multiple files into one. ;
async/await
The find
and read
functions return special type of Promise object called a ListPromise
. These lists provide a means of iterating through items with maximum concurrency, but are ultimately just Promises. Therefore, you can await the results.
{ await ; await ;}
See the ListPromise
documentation for more information on the available iteration methods.
API
file([options, [contents]]) : VinylRW
options
Object
cwd
String
(default:process.cwd()
) Current working directory.base
String
(default:cwd
) Base path from which to derive relative paths.path
String
File path.
contents
{String|Buffer|Stream}
- (default:null
) File contents.
Creates a new VinylRW
file.
;
find(glob, [options]) : ListPromise<VinylRW>
glob
String|Array<String>
options
Object
Options forglobby
.
Finds files matching a glob pattern and provides them as a Promise-aware list of VinylRW
objects. Does not read file contents into memory.
;
read(glob, [options]) : ListPromise<VinylRW>
glob
String|Array<String>
options
Null|String|Object
If null or a string, value is used as the encoding when reading. If an object, options forglobby
andfs.readFile
.encoding
{String}
(default:'utf8'
) File encoding. Set tonull
to use Buffers instead of Strings.
Finds files matching a glob pattern and provides them as a Promise-aware list of VinylRW
objects that can be mapped, filtered, reduced, and sorted. Reads file contents into memory.
// text files ; // special encoding ; // binary files ;
remove(glob) : Promise
glob
String|Array<String>
Permanently deletes files and directories.
;
write([dir, [options]]) : Function
dir
String
(default:file.base
) Optional alternate directory in which to write a file. By default, files will be saved to their current.path
value.options
Object
Options forfs.writeFile
.
Returns a callback that accepts a VinylRW
file and writes it to the file system, optionally in a different location.
callback(fileObj) : VinylRW
fileObj
VinylRW
TheVinylRW
file to be written.
Writes a file to the file system based on the file's path property. Returns the file so that you may continue iterating after writing.
;
Contribute
Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.
Test
$ npm test
© Shannon Moeller me@shannonmoeller.com (http://shannonmoeller.com)
Licensed under MIT