vinyl
Advanced tools
Comparing version 1.0.0 to 1.1.0
116
index.js
@@ -13,5 +13,7 @@ var path = require('path'); | ||
function File(file) { | ||
if (!file) file = {}; | ||
if (!file) { | ||
file = {}; | ||
} | ||
// record path change | ||
// Record path change | ||
var history = file.path ? [file.path] : file.history; | ||
@@ -23,6 +25,6 @@ this.history = history || []; | ||
// stat = files stats object | ||
// Stat = files stats object | ||
this.stat = file.stat || null; | ||
// contents = stream, buffer, or null if not read | ||
// Contents = stream, buffer, or null if not read | ||
this.contents = file.contents || null; | ||
@@ -45,3 +47,3 @@ | ||
// TODO: should this be moved to vinyl-fs? | ||
// TODO: Should this be moved to vinyl-fs? | ||
File.prototype.isDirectory = function() { | ||
@@ -55,3 +57,3 @@ return this.isNull() && this.stat && this.stat.isDirectory(); | ||
deep: opt, | ||
contents: true | ||
contents: true, | ||
}; | ||
@@ -61,3 +63,3 @@ } else if (!opt) { | ||
deep: true, | ||
contents: true | ||
contents: true, | ||
}; | ||
@@ -69,3 +71,3 @@ } else { | ||
// clone our file contents | ||
// Clone our file contents | ||
var contents; | ||
@@ -84,8 +86,8 @@ if (this.isStream()) { | ||
history: this.history.slice(), | ||
contents: contents | ||
contents: contents, | ||
}); | ||
// clone our custom properties | ||
// Clone our custom properties | ||
Object.keys(this).forEach(function(key) { | ||
// ignore built-in fields | ||
// Ignore built-in fields | ||
if (key === '_contents' || key === 'stat' || | ||
@@ -102,4 +104,8 @@ key === 'history' || key === 'path' || | ||
File.prototype.pipe = function(stream, opt) { | ||
if (!opt) opt = {}; | ||
if (typeof opt.end === 'undefined') opt.end = true; | ||
if (!opt) { | ||
opt = {}; | ||
} | ||
if (typeof opt.end === 'undefined') { | ||
opt.end = true; | ||
} | ||
@@ -118,4 +124,6 @@ if (this.isStream()) { | ||
// isNull | ||
if (opt.end) stream.end(); | ||
// Check if isNull | ||
if (opt.end) { | ||
stream.end(); | ||
} | ||
return stream; | ||
@@ -127,7 +135,7 @@ }; | ||
// use relative path if possible | ||
// Use relative path if possible | ||
var filePath = (this.base && this.path) ? this.relative : this.path; | ||
if (filePath) { | ||
inspect.push('"'+filePath+'"'); | ||
inspect.push('"' + filePath + '"'); | ||
} | ||
@@ -143,3 +151,3 @@ | ||
return '<File '+inspect.join(' ')+'>'; | ||
return '<File ' + inspect.join(' ') + '>'; | ||
}; | ||
@@ -151,4 +159,4 @@ | ||
// virtual attributes | ||
// or stuff with extra logic | ||
// Virtual attributes | ||
// Or stuff with extra logic | ||
Object.defineProperty(File.prototype, 'contents', { | ||
@@ -163,10 +171,14 @@ get: function() { | ||
this._contents = val; | ||
} | ||
}, | ||
}); | ||
// TODO: should this be moved to vinyl-fs? | ||
// TODO: Should this be moved to vinyl-fs? | ||
Object.defineProperty(File.prototype, 'relative', { | ||
get: function() { | ||
if (!this.base) throw new Error('No base specified! Can not get relative.'); | ||
if (!this.path) throw new Error('No path specified! Can not get relative.'); | ||
if (!this.base) { | ||
throw new Error('No base specified! Can not get relative.'); | ||
} | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not get relative.'); | ||
} | ||
return path.relative(this.base, this.path); | ||
@@ -176,3 +188,3 @@ }, | ||
throw new Error('File.relative is generated from the base and path attributes. Do not modify it.'); | ||
} | ||
}, | ||
}); | ||
@@ -182,9 +194,13 @@ | ||
get: function() { | ||
if (!this.path) throw new Error('No path specified! Can not get dirname.'); | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not get dirname.'); | ||
} | ||
return path.dirname(this.path); | ||
}, | ||
set: function(dirname) { | ||
if (!this.path) throw new Error('No path specified! Can not set dirname.'); | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not set dirname.'); | ||
} | ||
this.path = path.join(dirname, path.basename(this.path)); | ||
} | ||
}, | ||
}); | ||
@@ -194,20 +210,44 @@ | ||
get: function() { | ||
if (!this.path) throw new Error('No path specified! Can not get basename.'); | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not get basename.'); | ||
} | ||
return path.basename(this.path); | ||
}, | ||
set: function(basename) { | ||
if (!this.path) throw new Error('No path specified! Can not set basename.'); | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not set basename.'); | ||
} | ||
this.path = path.join(path.dirname(this.path), basename); | ||
} | ||
}, | ||
}); | ||
// Property for getting/setting stem of the filename. | ||
Object.defineProperty(File.prototype, 'stem', { | ||
get: function() { | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not get stem.'); | ||
} | ||
return path.basename(this.path, this.extname); | ||
}, | ||
set: function(stem) { | ||
if (!this.path) { | ||
throw new Error('No PassThrough specified! Can not set stem.'); | ||
} | ||
this.path = path.join(path.dirname(this.path), stem + this.extname); | ||
}, | ||
}); | ||
Object.defineProperty(File.prototype, 'extname', { | ||
get: function() { | ||
if (!this.path) throw new Error('No path specified! Can not get extname.'); | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not get extname.'); | ||
} | ||
return path.extname(this.path); | ||
}, | ||
set: function(extname) { | ||
if (!this.path) throw new Error('No path specified! Can not set extname.'); | ||
if (!this.path) { | ||
throw new Error('No path specified! Can not set extname.'); | ||
} | ||
this.path = replaceExt(this.path, extname); | ||
} | ||
}, | ||
}); | ||
@@ -220,11 +260,13 @@ | ||
set: function(path) { | ||
if (typeof path !== 'string') throw new Error('path should be string'); | ||
if (typeof path !== 'string') { | ||
throw new Error('path should be string'); | ||
} | ||
// record history only when path changed | ||
// Record history only when path changed | ||
if (path && path !== this.path) { | ||
this.history.push(path); | ||
} | ||
} | ||
}, | ||
}); | ||
module.exports = File; |
var isStream = require('./isStream'); | ||
module.exports = function(stream) { | ||
if (!isStream(stream)) return; | ||
if (!isStream(stream)) { | ||
return; | ||
} | ||
var streamType = stream.constructor.name; | ||
// avoid StreamStream | ||
if (streamType === 'Stream') streamType = ''; | ||
// Avoid StreamStream | ||
if (streamType === 'Stream') { | ||
streamType = ''; | ||
} | ||
return '<'+streamType+'Stream>'; | ||
return '<' + streamType + 'Stream>'; | ||
}; |
@@ -5,2 +5,2 @@ var Stream = require('stream').Stream; | ||
return !!o && o instanceof Stream; | ||
}; | ||
}; |
{ | ||
"name": "vinyl", | ||
"description": "A virtual file format", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "http://github.com/gulpjs/vinyl", | ||
@@ -20,6 +20,9 @@ "repository": "git://github.com/gulpjs/vinyl.git", | ||
"buffer-equal": "0.0.1", | ||
"eslint": "^1.7.3", | ||
"eslint-config-gulp": "^2.0.0", | ||
"event-stream": "^3.1.0", | ||
"istanbul": "^0.3.0", | ||
"istanbul-coveralls": "^1.0.1", | ||
"jshint": "^2.4.1", | ||
"jscs": "^2.3.5", | ||
"jscs-preset-gulp": "^1.0.0", | ||
"lodash.templatesettings": "^3.1.0", | ||
@@ -31,3 +34,5 @@ "mocha": "^2.0.0", | ||
"scripts": { | ||
"test": "mocha && jshint lib", | ||
"lint": "eslint . && jscs *.js lib/ test/", | ||
"pretest": "npm run lint", | ||
"test": "mocha", | ||
"coveralls": "istanbul cover _mocha && istanbul-coveralls" | ||
@@ -34,0 +39,0 @@ }, |
@@ -1,2 +0,3 @@ | ||
# vinyl [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status](https://david-dm.org/wearefractal/vinyl.png?theme=shields.io)](https://david-dm.org/wearefractal/vinyl) | ||
# vinyl [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] | ||
## Information | ||
@@ -167,2 +168,23 @@ <table><tr><td>Package</td><td>vinyl</td></tr><tr><td>Description</td><td>A virtual file format</td></tr><tr><td>Node Version</td><td>>= 0.9</td></tr></table> | ||
### stem | ||
Gets and sets stem (filename without suffix) for the file path. | ||
Example: | ||
```javascript | ||
var file = new File({ | ||
cwd: "/", | ||
base: "/test/", | ||
path: "/test/file.coffee" | ||
}); | ||
console.log(file.stem); // file | ||
file.stem = 'foo'; | ||
console.log(file.stem); // foo | ||
console.log(file.path); // /test/foo.coffee | ||
` | ||
``` | ||
### extname | ||
@@ -191,7 +213,7 @@ Gets and sets path.extname for the file path. | ||
[npm-image]: https://badge.fury.io/js/vinyl.png | ||
[travis-url]: https://travis-ci.org/wearefractal/vinyl | ||
[travis-image]: https://travis-ci.org/wearefractal/vinyl.png?branch=master | ||
[travis-url]: https://travis-ci.org/gulpjs/vinyl | ||
[travis-image]: https://travis-ci.org/gulpjs/vinyl.png?branch=master | ||
[coveralls-url]: https://coveralls.io/r/wearefractal/vinyl | ||
[coveralls-image]: https://coveralls.io/repos/wearefractal/vinyl/badge.png | ||
[depstat-url]: https://david-dm.org/wearefractal/vinyl | ||
[depstat-image]: https://david-dm.org/wearefractal/vinyl.png | ||
[depstat-url]: https://david-dm.org/gulpjs/vinyl | ||
[depstat-image]: https://david-dm.org/gulpjs/vinyl.png |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
14241
248
218
12
1