Socket
Socket
Sign inDemoInstall

vinyl

Package Overview
Dependencies
3
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.2.0

7

CHANGELOG.md
## Change Log
### upcoming (2016/01/15 08:53 +00:00)
### v1.1.1 (2016/01/18 23:23 +00:00)
- [3990e00](https://github.com/gulpjs/vinyl/commit/3990e007b004c809a53670c00566afb157fa56b6) 1.1.1
- [2d3e984](https://github.com/gulpjs/vinyl/commit/2d3e98447a42285b593e1b261984b87b171e7313) chore: add NPM script for changelog (@T1st3)
- [f70c395](https://github.com/gulpjs/vinyl/commit/f70c395085fc3952cf72c061c851f5b0d4676030) docs: add CHANGELOG.md (@T1st3)
- [#74](https://github.com/gulpjs/vinyl/pull/74) Fix isVinyl for falsy values (@erikkemperman)

@@ -58,4 +61,4 @@ - [3e8b132](https://github.com/gulpjs/vinyl/commit/3e8b132cd87bf5ab536ff7a4c6d660e33f5990b4) Fix isVinyl for falsy values (@erikkemperman)

- [#48](https://github.com/gulpjs/vinyl/pull/48) Update docs for `path` and `history` (@jmm)
- [231f32a](https://github.com/gulpjs/vinyl/commit/231f32a375aa9147d0a41ffd1ace773c45e66ee5) Document `path`. (@jmm)
- [93df183](https://github.com/gulpjs/vinyl/commit/93df18374b62de32c76862baf73e92f33b04882a) Document `options.history`. (@jmm)
- [231f32a](https://github.com/gulpjs/vinyl/commit/231f32a375aa9147d0a41ffd1ace773c45e66ee5) Document `path`. (@jmm)
- [2ed6a01](https://github.com/gulpjs/vinyl/commit/2ed6a012c03a78b46f9d41034969898a15fdfe15) Correct `options.path` default value docs. (@jmm)

@@ -62,0 +65,0 @@ - [edf1ecb](https://github.com/gulpjs/vinyl/commit/edf1ecb0698f355e137f9361a9a9a2581ca485e5) Document `history`. (@jmm)

@@ -12,3 +12,9 @@ var path = require('path');

var builtInFields = [
'_contents', 'contents', 'stat', 'history', 'path', 'base', 'cwd',
];
function File(file) {
var self = this;
if (!file) {

@@ -32,2 +38,9 @@ file = {};

this._isVinyl = true;
// Set custom properties
Object.keys(file).forEach(function(key) {
if (self.constructor.isCustomProp(key)) {
self[key] = file[key];
}
});
}

@@ -53,2 +66,4 @@

File.prototype.clone = function(opt) {
var self = this;
if (typeof opt === 'boolean') {

@@ -78,3 +93,3 @@ opt = {

var file = new File({
var file = new this.constructor({
cwd: this.cwd,

@@ -89,10 +104,6 @@ base: this.base,

Object.keys(this).forEach(function(key) {
// Ignore built-in fields
if (key === '_contents' || key === 'stat' ||
key === 'history' || key === 'path' ||
key === 'base' || key === 'cwd') {
return;
if (self.constructor.isCustomProp(key)) {
file[key] = opt.deep ? clone(self[key], true) : self[key];
}
file[key] = opt.deep ? clone(this[key], true) : this[key];
}, this);
});
return file;

@@ -149,2 +160,6 @@ };

File.isCustomProp = function(key) {
return builtInFields.indexOf(key) === -1;
};
File.isVinyl = function(file) {

@@ -224,3 +239,3 @@ return (file && file._isVinyl === true) || false;

if (!this.path) {
throw new Error('No PassThrough specified! Can not set stem.');
throw new Error('No path specified! Can not set stem.');
}

@@ -227,0 +242,0 @@ this.path = path.join(path.dirname(this.path), stem + this.extname);

{
"name": "vinyl",
"description": "A virtual file format",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "http://github.com/gulpjs/vinyl",

@@ -6,0 +6,0 @@ "repository": "git://github.com/gulpjs/vinyl.git",

@@ -35,2 +35,14 @@ # 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]

### isCustomProp
Vinyl checks if a property is not managed internally, such as `sourceMap`. This is than used in `constructor(options)` when setting, and `clone()` when copying properties.
```js
var File = require('vinyl');
File.isCustomProp('sourceMap'); // true
File.isCustomProp('path'); // false -> internal getter/setter
```
Read more in [Extending Vinyl](#extending-vinyl).
### constructor(options)

@@ -65,2 +77,12 @@ #### options.cwd

#### options.{custom}
Any other option properties will just be assigned to the new File object.
```js
var File = require('vinyl');
var file = new File({foo: 'bar'});
file.foo === 'bar'; // true
```
### isBuffer()

@@ -146,3 +168,2 @@ Returns true if file.contents is a Buffer.

console.log(file.path); // /specs/file.coffee
`
```

@@ -168,3 +189,2 @@

console.log(file.path); // /test/file.js
`
```

@@ -190,3 +210,2 @@

console.log(file.path); // /test/foo.coffee
`
```

@@ -212,5 +231,34 @@

console.log(file.path); // /test/file.js
`
```
## Extending Vinyl
When extending Vinyl into your own class with extra features, you need to think about a few things.
When you have your own properties that are managed internally, you need to extend the static `isCustomProp` method to return `false` when one of these properties is queried.
```js
const File = require('vinyl');
const builtInProps = ['foo', '_foo'];
class SuperFile extends File {
constructor(options) {
super(options);
this._foo = 'example internal read-only value';
}
get foo() {
return this._foo;
}
static isCustomProp(name) {
return super.isCustomProp(name) && builtInProps.indexOf(name) === -1;
}
}
```
This makes properties `foo` and `_foo` ignored when cloning, and when passed in options to `constructor(options)` so they don't get assigned to the new object.
Same goes for `clone()`. If you have your own internal stuff that needs special handling during cloning, you should extend it to do so.
[npm-url]: https://npmjs.org/package/vinyl

@@ -220,5 +268,5 @@ [npm-image]: https://badge.fury.io/js/vinyl.svg

[travis-image]: https://travis-ci.org/gulpjs/vinyl.svg?branch=master
[coveralls-url]: https://coveralls.io/r/wearefractal/vinyl
[coveralls-image]: https://coveralls.io/repos/wearefractal/vinyl/badge.svg
[coveralls-url]: https://coveralls.io/github/gulpjs/vinyl
[coveralls-image]: https://coveralls.io/repos/github/gulpjs/vinyl/badge.svg
[depstat-url]: https://david-dm.org/gulpjs/vinyl
[depstat-image]: https://david-dm.org/gulpjs/vinyl.svg
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc