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

mac

v0.4.0

Published

A tiny library designed to parallel or series chain streams, promises or functions with callbacks.

Downloads

94

Readme

mac

"Never break the chain." - Fleetwood Mac

A tiny library designed to parallel or series chain streams, promises or functions with callbacks.

Installing

npm install mac

Including

var mac = require('mac');

Usage

Mac is designed to work with any combination of streams, promises or functions that define a single argument and will ensure that they are called in parallel or series. Since Mac returns a function that defines a callback, you can pass it into itself. The function that is returned when called begins executing the Mac chain.

Streams

Working with streams allows it to work with a multitude of libraries, most notably of these is probably Gulp, but it can be used with any sort of stream.

The following would ensure that your JS is transpiled from ES6 to ES5 and when that is finished it would then minify the dist.

var js = mac.series(
  gulp.src('src/*.js').pipe(gulpBabelify).dest('dist'),
  gulp.src('dist/*.js').pipe(gulpUglify).dest('dist')
);

If you want to run some tasks in paralell you can do that too. For example, if you wanted to take your JavaScript task and run it in parallel with your Less task, go for it:

var dist = mac.parallel(
  js,
  gulp.src('src/*.less').pipe(gulpLess).dest('dist')
);

Gulp is probably the shining example of this as most people will know it, but it can work with any stream that emits the finish event.

Promises

If you wanted to run two fetch (returns a promise, see: https://github.com/github/fetch) requests ensuring the first one is called before the second one:

mac.series(
  fetch('some/endpoint'),
  fetch('something/else')
);

Functions

If you wanted to execute a series of functions ensuring one finishes before the other, you should define a single argument. This argument is a callback that you call in order to say that you're done doing whatever you're doing. Once called, it will proceed to the next.

mac.series(
  function (done) {
    setTimeout(done, 100);
  },

  function (done) {
	  updateSomething();
	  done();
  }
);

If your task doesn't need to report back, then you don't have to define a callback and call it and it will be called and passed through.

mac.series(
  function (done) {
	  setTimeout(done, 100);
  },

  function () {
	  updateSomething();
  }
);

Build Example

The following is what an ES6 and Less project build might look like. It breaks each part down into separate functions that can be run individually, or batched using the main dist module. I chose not to require all the dependencies to reduce cruft, so just assume they're there.

// tasks/dist/babelify.js

module.exports = function () {
  return gulp.src('src/*.js')
    .pipe(gulpBabelify)
    .pipe(gulp.dest('dist'));
};

// tasks/dist/uglify.js

module.exports = function () {
  return gulp.src('dist/*.js')
    .pipe(gulpUglify)
    .pipe(gulp.dest('dist'));
};

// tasks/dist/js.js

module.exports = function () {
  return mac.series(
    require('./babelify'),
    require('./uglify')
  );
};

// tasks/dist/less.js

module.exports = function () {
  return gulp.src('src/*.less')
    .pipe(gulpLess)
    .pipe(gulp.dist('dist'));
};

// tasks/dist/cssmin.js

module.exports = function () {
  return gulp.src('dist/*.css')
    .pipe(gulpCssmin)
    .pipe(gulp.dist('dist'));
};

// tasks/dist/css.js

module.exports = mac.series(
  require('./less'),
  require('./cssmin')
);

// tasks/dist.js

module.exports = mac.parallel(
  require('./dist/css'),
  require('./dist/js')
);