Comparing version 0.0.0 to 0.1.0
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -6,20 +6,21 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
var _this = undefined; | ||
var tack = exports.tack = function tack(func) { | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var _tack = require('./tack'); | ||
return this === _this ? func.apply(undefined, args) // bound to the global obj | ||
: func.apply(undefined, [this].concat(args)) // bound to something intersting | ||
; | ||
}; | ||
}; | ||
Object.defineProperty(exports, 'tack', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_tack).default; | ||
} | ||
}); | ||
var compose = exports.compose = function compose(func) { | ||
return function (arg) { | ||
return this === _this ? func(arg) : this(func(arg)); | ||
}; | ||
}; | ||
var _compose = require('./compose'); | ||
Object.defineProperty(exports, 'compose', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_compose).default; | ||
} | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
{ | ||
"name": "tack-on", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"description": "Tack on functions to things that should have had them all along.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# tack-on | ||
[![Build Status](https://travis-ci.org/Alex-Aralis/yank-down.svg?branch=master)](https://travis-ci.org/Alex-Aralis/yank-down) [![codecov](https://codecov.io/gh/Alex-Aralis/tack-on/branch/master/graph/badge.svg)](https://codecov.io/gh/Alex-Aralis/tack-on) | ||
[![Build Status](https://travis-ci.org/Alex-Aralis/yank-down.svg?branch=master)](https://travis-ci.org/Alex-Aralis/yank-down) [![codecov](https://codecov.io/gh/Alex-Aralis/tack-on/branch/master/graph/badge.svg)](https://codecov.io/gh/Alex-Aralis/tack-on) [![npm version](https://badge.fury.io/js/tack-on.svg)](https://badge.fury.io/js/tack-on) [![dependencies](https://david-dm.org/alex-aralis/tack-on.svg)](https://www.npmjs.com/package/tack-on) | ||
Some neato functions inspired by the new [bind operator](https://babeljs.io/docs/plugins/transform-function-bind/) and functional programming. | ||
@@ -9,2 +10,6 @@ | ||
```javascript | ||
tack(func, injectPosition = 0, actionFunc?) | ||
``` | ||
### What? | ||
@@ -22,2 +27,33 @@ | ||
Tacked functions assume composing behavior when bound to functions. | ||
```javascript | ||
const succ = tack(n => n + 1); | ||
const pred = tack(n => n - 1); | ||
expect(succ::pred::succ::succ(0)).to.equal(2); | ||
``` | ||
The position `this` is inserted into can be specified. | ||
```javascript | ||
const toTriple = tack((a, b, c) => [a, b, c], 1); | ||
expect('middle'::toTriple('start', 'end')).to.equal(['start', 'middle', 'end']); | ||
``` | ||
A custom action function can be provided that will change the defaults for when to tack, when to compose and when to do call the original function. | ||
```javascript | ||
const f = tack( | ||
func => func(2), | ||
0, | ||
t => t !== undefined ? 'tack' : 'nothing' | ||
); | ||
// f will tack to functions instead of composing with them. | ||
expect(succ::f()).to.equal(3); | ||
``` | ||
## `compose` | ||
@@ -24,0 +60,0 @@ Make functions composable with the bind operator. `compose` assumes functions that take only one argument. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5453
7
57
74