File tree Expand file tree Collapse file tree 4 files changed +38
-10
lines changed
Expand file tree Collapse file tree 4 files changed +38
-10
lines changed Original file line number Diff line number Diff line change @@ -34,15 +34,24 @@ var coffeeFile = new File({
3434});
3535```
3636
37- ### constructor(options)
37+ ### isVinyl
38+ When checking if an object is a vinyl file, you should not use instanceof. Use the isVinyl function instead.
3839
39- #### options.cwd
40+ ``` js
41+ var File = require (' vinyl' );
4042
41- Type: ` String ` < br >
42- Default: ` process.cwd() `
43+ var dummy = new File ({stuff});
44+ var notAFile = {};
4345
44- #### options.base
46+ File .isVinyl (dummy); // true
47+ File .isVinyl (notAFile); // false
48+ ```
4549
50+ ### constructor(options)
51+ #### options.cwd
52+ Type: ` String ` <br ><br >Default: ` process.cwd() `
53+
54+ #### options.base
4655Used for relative pathing. Typically where a glob starts.
4756
4857Type: ` String ` <br >
Original file line number Diff line number Diff line change @@ -16,16 +16,16 @@ function File(file) {
1616 var history = file . path ? [ file . path ] : file . history ;
1717 this . history = history || [ ] ;
1818
19- // TODO: should this be moved to vinyl-fs?
2019 this . cwd = file . cwd || process . cwd ( ) ;
2120 this . base = file . base || this . cwd ;
2221
23- // stat = fs stats object
24- // TODO: should this be moved to vinyl-fs?
22+ // stat = files stats object
2523 this . stat = file . stat || null ;
2624
2725 // contents = stream, buffer, or null if not read
2826 this . contents = file . contents || null ;
27+
28+ this . _isVinyl = true ;
2929}
3030
3131File . prototype . isBuffer = function ( ) {
@@ -133,6 +133,10 @@ File.prototype.inspect = function() {
133133 return '<File ' + inspect . join ( ' ' ) + '>' ;
134134} ;
135135
136+ File . isVinyl = function ( file ) {
137+ return file && file . _isVinyl === true ;
138+ } ;
139+
136140// virtual attributes
137141// or stuff with extra logic
138142Object . defineProperty ( File . prototype , 'contents' , {
Original file line number Diff line number Diff line change 11{
22 "name" : " vinyl" ,
33 "description" : " A virtual file format" ,
4- "version" : " 0.5.1 " ,
4+ "version" : " 0.5.2 " ,
55 "homepage" : " http://github.com/wearefractal/vinyl" ,
66 "repository" : " git://github.com/wearefractal/vinyl.git" ,
77 "author" : " Fractal <contact@wearefractal.com> (http://wearefractal.com/)" ,
2424 "lodash.templatesettings" : " ^3.1.0" ,
2525 "mocha" : " ^2.0.0" ,
2626 "rimraf" : " ^2.2.5" ,
27- "should" : " ^6 .0.0"
27+ "should" : " ^7 .0.0"
2828 },
2929 "scripts" : {
3030 "test" : " mocha && jshint lib" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,21 @@ var should = require('should');
88require ( 'mocha' ) ;
99
1010describe ( 'File' , function ( ) {
11+ describe ( 'isVinyl()' , function ( ) {
12+ it ( 'should return true on a vinyl object' , function ( done ) {
13+ var file = new File ( ) ;
14+ File . isVinyl ( file ) . should . equal ( true ) ;
15+ done ( ) ;
16+ } ) ;
17+ it ( 'should return false on a normal object' , function ( done ) {
18+ File . isVinyl ( { } ) . should . equal ( false ) ;
19+ done ( ) ;
20+ } ) ;
21+ it ( 'should return false on a null object' , function ( done ) {
22+ File . isVinyl ( { } ) . should . equal ( false ) ;
23+ done ( ) ;
24+ } ) ;
25+ } ) ;
1126 describe ( 'constructor()' , function ( ) {
1227 it ( 'should default cwd to process.cwd' , function ( done ) {
1328 var file = new File ( ) ;
You can’t perform that action at this time.
0 commit comments