npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vinyl-accumulate

v1.4.1

Published

Accumulates input vinyls and appends them to the output.

Downloads

81

Readme

vinyl-accumulate v1.4.1

CircleCI codecov js-standard-style

Accumulates input files in a stream and appends them to the output.

Install

npm intall vinyl-accumulate

Usage

Create gulpfile.js like the below:

const gulp = require('gulp')
const frontMatter = require('gulp-front-matter')
const accumulate = require('vinyl-accumulate')

gulp.src('src/**/*.md')
  .pipe(frontMatter())
  .pipe(accumulate('index.html'))
  .pipe(anyTransform())
  .pipe(gulp.dest('dest'))

Then all the input files are accumulated into one file called index.html (The contents is empty) at accumulated node. The output file has .files property which is the array of the all input files.

For example, you can use it like the below:

gulp.src('src/**/*.md')
  .pipe(frontMatter())
  .pipe(accumulate('index.html'))
  .pipe(through2.obj((file, enc, cb) => {
    file.files.forEach(inputFile => {
      // Concatenates all the input file's contents.
      file.contents = Buffer.concat([file.contents, inputFile.contents])
    })

    cb(null, file)
  }))
  .pipe(gulp.dest('dest'))

Then you get dest/index.html whose contents is the concatenation of src/**/*.md.

Passes all the input files

There is another API called accumulate.through:

gulp.src('src/**/*.md')
  .pipe(frontMatter())
  .pipe(accumulate.through())
  .pipe(anyTransform)
  .pipe(gulp.dest('dest'))

accumulate.through() passes through all the input files but appending all the input files to each file at the property .files.

Sort the accumulated files

Pass the sort function to sort option and the result is sorted by it.

gulp.src('src/**/*.md')
  .pipe(frontMatter())
  .pipe(accumulate.through({sort: (x, y) => x.frontMatter.date - y.frontMatter.date}))
  .pipe(anyTransform)
  .pipe(gulp.dest('dest'))

The above example sorts the output files in the ascending order of the date front-matter property.

Accumulate vinyls over a stream without the end

By default, vinyl-accumulate emits the output when the input stream ends. (This is fine when you works with gulp because streams always end in gulp.) If you need to use this module with streams without end like in bulbo, you need to use debounce options. It debounces the input stream with the given debounceDuration (default: 500ms) and outputs after that duration.

const bulbo = require('bulbo')

bulbo.asset('src/**/*.md')
  .pipe(frontMatter())
  .pipe(accumulate.through({debounce: true})
  .pipe(anyTransform)

API

const accumulate = require('vinyl-accumulate')

accumulate(filename, options)

Accumulates the input files and outputs an empty file with the collected files appended.

  • @param {string} filename The filename
  • @param {string} [options.property] The name of the property of accumulated files. Default is files.
  • @param {boolean} [options.debounce] If true, then this stream debounces the input, accumulates them while they are streaming continuously and finally outputs it when the stream stops streaming for a while (= debounceDuration). If false, it accumulates all the files until the end of the stream and output only once at the end. Default is false. This option is useful when you handle the vinyl stream which never ends (like in bulbo).
  • @param {number} [options.debounceDuration] The duration of debounce in milliseconds. This only has effects when debounce option is true. Default is 500.
  • @param {Function} [options.sort] The sort function. If given, the accumulated files are sorted by this function. Optional.
  • @param {Function} [options.filter] The filter function. If given, the accumulated files are filtered by this function. Optional.

accumulate.through(options)

Passes through all the input. Appends accumulated files to each file at the given property name (default 'files')

  • @param {boolean} debounce If true then it debounce the inputs and outputs after debounceDuration. If false, it only outputs at the end of the stream. Default is false
  • @param {number} debounceDuration The duration of the debounce. This takes effects only when debounce option is true.
  • @param {string} options.property The property to set the file list
  • @param {Function} [options.sort] The sort function. If given, the accumulated files are sorted by this function. Optional.
  • @param {Function} [options.filter] The filter function. If given, the accumulated files are filtered by this function. Optional.

accumulate.src(glob, options)

Create vinyl stream from the given glob pattern. Appends accumulated files to each of them.

  • @param {string} glob The glob pattern. Required.
  • @param {boolean} debounce If true then it debounce the inputs and outputs after debounceDuration. If false, it only outputs at the end of the stream. Default is false
  • @param {number} debounceDuration The duration of the debounce. This takes effects only when debounce option is true.
  • @param {string} options.property The property to set the file list
  • @param {Function} [options.sort] The sort function. If given, the accumulated files are sorted by this function. Optional.
  • @param {Function} [options.filter] The filter function. If given, the accumulated files are filtered by this function. Optional.

History

  • 2016-10-30 v1.4.0 Added filter option.
  • 2016-10-29 v1.3.0 Added src method.
  • 2016-10-23 v1.2.0 Added sort option.

License

MIT