Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including vinyl-properties with all npm packages installed. Try it out:

var vinylProperties = require("vinyl-properties")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

vinyl-properties v2.0.0

Collect vinyl file properties in a stream

vinyl-properties

NPM version Build Status Coverage Status devDependency Status

Collect vinyl file properties in a stream

const gulp = require('gulp');
const vinylProperties = require('vinyl-properties');

gulp.task('default', () => {
  const props = vinylProperties('relative');

  return gulp.src(['foo.js', 'bar.js'])
    .pipe(props)
    .pipe(gulp.dest('dist'))
    .on('finish', () => {
      props.relative; //=> ['foo.js', 'bar.js']
    });
});

Installation

Use npm.

npm install vinyl-properties

API

const vinylProperties = require('vinyl-properties');

vinylProperties(properties)

properties: String or Array of String (the names of properties you want to collect)
Return: Object (stream.Transform)

Every time the stream reads a vinyl file object, it pushes the value of vinyl properties you specified to the stream's properties in the same names, and pushes all of them to the files property.

gulp.task('default', () => {
  const props = vinylProperties(['path', 'contents']);

  return gulp.src('*.txt')
    .pipe(props)
    .pipe(gulp.dest('dist'))
    .on('finish', () => {
      props.path; //=> ['file0.txt', 'file1.txt', ...]
      props.contents; //=> [<Buffer ... >, <Buffer ... >, ...]
      props.files; /*=>
                     [
                       {
                         path: 'file0.txt',
                         contents: <Buffer ... >
                       },
                       {
                         path: 'file1.txt',
                         contents: <Buffer ... >
                       },
                       ...
                     ]
                   */
    });
});

License

Copyright (c) 2015 Shinnosuke Watanabe

Licensed under the MIT License.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free