vinyl-rw
v4.0.1
Published
A file-system aware vinyl file with first-class string support.
Downloads
51
Readme
vinyl-rw
An extended Vinyl class that defaults to working with strings and has the ability to read and write to the file system.
Install
$ npm install --save vinyl-rw
Usage
import File from 'vinyl-rw';
const foo = new File('foo.txt', 'Lorem ipsum.');
console.log(foo.path);
// -> '/Users/smoeller/repos/vinyl-rw/foo.txt'
console.log(foo.contents);
// -> 'Lorem ipsum.'
API
Extends the Vinyl API with the following:
new File(options, contents)
options
{String|Object}
- Path or options.contents
{String|Buffer|Stream}
- (default:null
) File contents.
.isString() : Boolean
Returns true
if file.contents
is a string.
.exists() : Promise
Sync: existsSync() : Boolean
Checks whether the file at file.path
exists.
new File('foo.txt')
.exists()
.then(x => console.log(x));
// -> true
.read([options]) : Promise
Sync: readSync([options]) : File
options
{String|Object}
- (default:'utf8'
) Encoding or options.
Reads the contents of file.path
into file.contents
.
new File('foo.txt')
.read()
.then(x => console.log(x.contents));
// -> 'Lorem ipsum.'
.write([options]) : Promise
Sync: writeSync([options]) : File
options
{String|Object}
- (default:'utf8'
) Encoding or options.
Writes file.contents
as the contents of file.path
.
new File('foo.txt', 'Lorem ipsum.')
.write()
.then(x => console.log(x.path));
// -> '/Users/smoeller/repos/vinyl-rw/foo.txt'
File.isRW(val) : Boolean
val
{Any}
- An object to inspect.
Returns true
if val
is a VinylRW file.
const vinyl = new Vinyl();
const file = new File();
console.log(File.isRW(vinyl));
// -> false
console.log(File.isRW(file));
// -> true
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 [email protected] (http://shannonmoeller.com)
Licensed under MIT