Skip to content

Commit

Permalink
Deprecated project - renamed shimstack
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jul 1, 2015
1 parent 8afd747 commit 17c0c29
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 124 deletions.
33 changes: 3 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,7 @@
# middlestack.js

# Middleware for functions
# DEPRECATED

## Current status
This project has been renamed `shimstack`.

[![NPM version](https://img.shields.io/npm/v/middlestack.svg)](https://www.npmjs.com/package/middlestack)
[![Build Status](https://img.shields.io/travis/overlookmotel/middlestack/master.svg)](http://travis-ci.org/overlookmotel/middlestack)
[![Dependency Status](https://img.shields.io/david/overlookmotel/middlestack.svg)](https://david-dm.org/overlookmotel/middlestack)
[![Dev dependency Status](https://img.shields.io/david/dev/overlookmotel/middlestack.svg)](https://david-dm.org/overlookmotel/middlestack)
[![Coverage Status](https://img.shields.io/coveralls/overlookmotel/middlestack/master.svg)](https://coveralls.io/r/overlookmotel/middlestack)

## Usage

## Tests

Use `npm test` to run the tests. Use `npm run cover` to check coverage.

## Changelog

See changelog.md

## Issues

If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/middlestack/issues

## Contribution

Pull requests are very welcome. Please:

* ensure all tests pass before submitting PR
* add an entry to changelog
* add tests for new features
* document new functionality/API additions in README
Please use [shimstack](https://www.npmjs.com/package/shimstack) instead.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
## 0.1.2

* Error name capitalized

## Next

* Deprecated project - renamed `shimstack`
86 changes: 1 addition & 85 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,88 +2,4 @@
// middlestack module
// --------------------

// modules
var util = require('util'),
co = require('co-bluebird'),
isGeneratorFn = require('is-generator').fn,
_ = require('lodash');

// exports
var middlestack = module.exports = function(obj, methodName, options, fn) {
// conform arguments
if (typeof methodName == 'function') {
fn = methodName;
methodName = undefined;
options = undefined;
} else if (typeof methodName == 'object') {
fn = options;
options = methodName;
methodName = undefined;
} else if (typeof options == 'function') {
fn = options;
options = undefined;
}

// conform options
options = _.extend({
// name: undefined
lastArg: false
}, options || {});

// get method
var method = (methodName ? obj[methodName] : obj);
if (typeof method != 'function') throw new middlestack.Error('You can only middlestack a function');

// if not already stackified, middlestack method
if (!method.__middlestack) method = convertToStack(method, obj, methodName);

// get function name
if (options.name === undefined && fn.name) options.name = fn.name;

// co-ify generators
if (isGeneratorFn(fn)) fn = co.wrap(fn);

// add fn to stack
method.__middlestack.stack.push({fn: fn, name: options.name, lastArg: options.lastArg});

return method;
};

function convertToStack(origMethod, obj, methodName) {
// create stackified function
var method = function() {
var _this = this,
stack = method.__middlestack.stack,
i = 0;

var next = function() {
if (i == stack.length) return method.__middlestack.final.apply(_this, arguments);

var item = stack[i];
i++;

var args = Array.prototype.slice.call(arguments);
args[item.lastArg ? args.length : item.fn.length - 1] = next;

return item.fn.apply(_this, args);
};

return next.apply(this, arguments);
};

method.__middlestack = {stack: [], final: origMethod};

// write stackified method to obj
if (methodName) obj[methodName] = method;

// return stackified method
return method;
}

middlestack.Error = function(message) {
var tmp = Error.call(this, message);
tmp.name = this.name = 'MiddlestackError';
this.message = tmp.message;
Error.captureStackTrace(this, this.constructor);
};
util.inherits(middlestack.Error, Error);
module.exports = require('shimstack');
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "middlestack",
"version": "0.1.2",
"description": "Middleware for functions",
"description": "DEPRECATED",
"main": "./lib/",
"author": {
"name": "Overlook Motel"
Expand All @@ -14,9 +14,7 @@
"url": "https://github.com/overlookmotel/middlestack/issues"
},
"dependencies": {
"co-bluebird": "0.0.2",
"is-generator": "1.0.0",
"lodash": "3.8.0"
"shimstack": "*"
},
"devDependencies": {
"mocha": "^2.2.4",
Expand All @@ -26,11 +24,6 @@
"coveralls": "^2.11.2"
},
"keywords": [
"middleware",
"function",
"functions",
"shim",
"stack"
],
"scripts": {
"test": "make test",
Expand Down

0 comments on commit 17c0c29

Please sign in to comment.