Socket
Socket
Sign inDemoInstall

lazypipe

Package Overview
Dependencies
3
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.2.0

51

index.js

@@ -7,25 +7,46 @@ /*jshint node:true */

var validateStep = function(step) {
if(!step) {
throw new Error("Invalid call to lazypipe().pipe(): no stream creation function specified");
} else if(typeof step !== 'function') {
throw new Error("Invalid call to lazypipe().pipe(): argument is not a function.\n" +
" Remember not to call stream creation functions directly! e.g.: pipe(foo), not pipe(foo())");
}
},
validateSteps = function(steps) {
if(steps.length === 0) {
throw new Error("Tried to build a pipeline with no pipes!");
}
};
function lazypipe() {
var createPipeline = function(tasks) {
var createPipeline = function(steps) {
var build = function() {
if(tasks.length === 0) {
throw new Error("Tried to build a pipeline with no pipes!");
}
return combine.apply(null, tasks.map(function(t) {
validateSteps(steps);
return combine.apply(null, steps.map(function(t) {
return t.task.apply(null, t.args);
}));
};
build.pipe = function(task) {
if(!task) {
throw new Error("Invalid call to lazypipe().pipe(): no stream specified");
} else if(typeof task !== 'function') {
throw new Error("Invalid call to lazypipe().pipe(): stream is not a function");
build.appendStepsTo = function(otherSteps) {
return otherSteps.concat(steps);
};
build.pipe = function(step) {
validateStep(step);
if(step.appendStepsTo) {
// avoid creating nested pipelines
return createPipeline(step.appendStepsTo(steps));
} else {
return createPipeline(steps.concat({
task: step,
args: Array.prototype.slice.call(arguments, 1)
}));
}
return createPipeline(tasks.concat({
task: task,
args: Array.prototype.slice.call(arguments, 1)
}));
}
};
return build;
};
return createPipeline([]);

@@ -32,0 +53,0 @@ }

{
"name": "lazypipe",
"description": "Use to create an immutable, lazily initialized pipeline from a series of streams.",
"version": "0.1.4",
"version": "0.2.0",
"homepage": "https://github.com/OverZealous/lazypipe",

@@ -6,0 +6,0 @@ "repository": {

@@ -29,3 +29,3 @@ ![status](https://secure.travis-ci.org/OverZealous/lazypipe.png?branch=master)

var jsHintTasks = lazypipe()
// adding a pipeline step, notice the stream has not been initialized!
// adding a pipeline step, notice the stream function has not been called!
.pipe(jshint)

@@ -84,13 +84,22 @@ // adding a step with an argument

### `lazypipe().pipe(stream|fn, args...)`
### `lazypipe().pipe(fn, [args...])`
Creates a new lazy pipeline with all the previous steps, and the new step added to the end. Returns the new lazypipe.
* `stream` or `fn` - a stream initializer or function to call when the pipeline is created later. You can provide your own custom functions if necessary.
* `args` - Any remaining arguments are saved and passed into `stream` or `fn` when the pipeline is created.
* `fn` - a stream creation function to call when the pipeline is created later. You can either provide existing functions (such as gulp plugins), or provide your own custom functions if you want to manipulate the stream before creation.
* `args` - Any remaining arguments are saved and passed into `fn` when the pipeline is created.
### `lazypipe()()` *"Create"*
The arguments allows you to pass in configuration arguments when the pipeline is created, like this:
Calling the result of `pipe()` as a function creates a pipeline at that time. This can be used multiple times, and can even be called if the lazypipe was added to for other purposes.
```js
var pipeline = lazypipe().pipe(jsHint, jsHintOptions);
// now, when gulp.src().pipe(pipeline()) is called later, it's as if you did:
gulp.src().pipe(jsHint(jsHintOptions));
```
### `lazypipe()()` *"build"*
Calling the result of `pipe()` as a function builds the pipeline at that time. This can be used multiple times, and can even be called if the lazypipe was used to create different pipelines.
It returns a stream created using `stream-combiner`, where all the internal steps are processed sequentially, and the final result is passed on.

@@ -97,0 +106,0 @@

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