Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compose-function

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compose-function - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

LICENSE.md

31

index.js

@@ -1,12 +0,16 @@

"use strict";
'use strict';
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
Object.defineProperty(exports, '__esModule', {
value: true
});
exports['default'] = compose;
// istanbul ignore next
module.exports = compose;
var arityN = _interopRequire(require("arity-n"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _arityN = require('arity-n');
var _arityN2 = _interopRequireDefault(_arityN);
var compose2 = function (f, g) {
var compose2 = function compose2(f, g) {
return function () {

@@ -22,8 +26,8 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {

function compose() {
for (var _len = arguments.length, functions = Array(_len), _key = 0; _key < _len; _key++) {
functions[_key] = arguments[_key];
for (var _len2 = arguments.length, functions = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
functions[_key2] = arguments[_key2];
}
functions = functions.filter(function (fn) {
return typeof fn === "function";
return typeof fn === 'function';
});

@@ -35,6 +39,5 @@

if (functions.length <= 0) {
throw new Error("No functions passed");
throw new Error('No functions passed');
}
if (lastIdx >= 0 && functions[lastIdx]) {

@@ -44,3 +47,5 @@ arity = functions[lastIdx].length;

return arityN(functions.reduce(compose2), arity);
}
return (0, _arityN2['default'])(functions.reduce(compose2), arity);
}
module.exports = exports['default'];
{
"name": "compose-function",
"version": "2.0.0",
"version": "3.0.0",
"description": "Compose new functions f(g(x))",
"main": "index.js",
"scripts": {
"test": "gulp test"
"clean": "git reset && echo '/node_modules/' > .gitignore && git add .gitignore && git stash save --include-untracked --keep-index '`npm run clean` trash can' && git clean --force -d && git reset --hard && echo '\nclean: Uncommitted and ignored files have been moved to gitâ™s stash. To restore them run `git stash pop --quiet; git checkout .gitignore`.'",
"coverage": "rm -rf coverage && npm run test:transpile && cd .es5 && istanbul cover test.js && mv coverage ..",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
"develop": "nodangel --ignore node_modules --ignore coverage --exec 'npm run --silent test:lite'",
"prepublish": "npm run --silent clean && npm run transpile",
"patch-release": "npm version patch && npm publish && git push --follow-tags",
"minor-release": "npm version minor && npm publish && git push --follow-tags",
"major-release": "npm version major && npm publish && git push --follow-tags",
"test": "eslint --ignore-path .gitignore .; npm run test:transpile && node .es5/test.js | tap-spec",
"test:lite": "babel-node --optional es7.functionBind test.js | tap-spec",
"test:transpile": "rm -rf .es5 && babel --optional es7.functionBind test.js test/*.js --out-dir .es5 && babel module/*.js --out-dir .es5",
"transpile": "babel module --out-dir .",
"view-coverage": "echo 'Generating coverage reports…'; npm run coverage >/dev/null && echo '…done.' && opn ./coverage/lcov-report/index.html >/dev/null"
},

@@ -13,2 +25,8 @@ "repository": {

},
"files": [
"/*.js",
"/module/",
"/README.md",
"/LICENSE.md"
],
"keywords": [

@@ -26,13 +44,13 @@ "function",

"devDependencies": {
"chickencurry": "^1.0.2",
"expect.js": "^0.3.1",
"gulp": "^3.8.11",
"gulp-6to5": "^3.0.0",
"gulp-mocha": "^2.0.0",
"gulp-rename": "^1.2.0",
"gulp-run": "^1.6.6",
"gulp-sourcemaps": "^1.3.0",
"gulp-watch": "^4.1.1",
"mocha": "^2.1.0",
"mockery": "^1.4.0"
"babel": "^5.8.21",
"babel-eslint": "^4.0.10",
"coveralls": "^2.11.4",
"curry-this": "^3.0.2",
"es6-symbol": "^2.0.1",
"eslint": "^1.2.0",
"istanbul": "^0.3.18",
"nodangel": "1.3.8",
"opn-cli": "1.0.0",
"tap-spec": "^4.0.2",
"tape-catch": "1.0.4"
},

@@ -39,0 +57,0 @@ "dependencies": {

@@ -1,6 +0,17 @@

Compose-Function
================
<h1 align="center">Compose-Function</h1>
[![Build Status](https://travis-ci.org/stoeffel/compose-function.svg)](https://travis-ci.org/stoeffel/compose-function) [![npm version](https://badge.fury.io/js/compose-function.svg)](http://badge.fury.io/js/compose-function)
> Compose a new function from smaller functions `f(g(x))`
<p align="center">
<a href="#installation">Installation</a> |
<a href="#usage">Usage</a> |
<a href="#license">License</a>
<br><br>
<img align="center" height="300" src="http://33.media.tumblr.com/006dfad04f93ec5b3680ec7cdae3fafa/tumblr_n8kgl18uU41qcung4o1_1280.gif">
<br>
<sub>logo by <a href="http://justinmezzell.tumblr.com/">Justin Mezzell</a></sub>
<blockquote align="center">Compose a new function from smaller functions `f(g(x))`</blockquote>
</p>
[![Travis](https://img.shields.io/travis/stoeffel/compose-function.svg?style=flat-square)](https://travis-ci.org/stoeffel/compose-function)
[![npm](https://img.shields.io/npm/v/compose-function.svg?style=flat-square)](https://www.npmjs.com/package/compose-function)
[![Dependency Status](https://david-dm.org/stoeffel/compose-function.svg?style=flat-square)](https://david-dm.org/stoeffel/compose-function)
[![Coveralls](https://img.shields.io/coveralls/stoeffel/compose-function.svg?style=flat-square)](https://coveralls.io/github/stoeffel/compose-function)

@@ -15,8 +26,8 @@ Installation

### Basic usage
## Basic usage
```js
var compose = require('compose-function');
import compose from 'compose-function';
var composition = compose(sqr, add2); // sqr(add2(x))
const composition = compose(sqr, add2); // sqr(add2(x))

@@ -30,28 +41,42 @@ composition(2) // => 16

### with curry
## with curry
```js
var compose = require('compose-function');
var curry = require('chickencurry');
import compose from 'compose-function';
const { curry, _ } = require('curry-this')({Symbol:() => 'CURRY'});
function add(x, y) {
return x + y;
}
const add = (x, y) => x + y;
// add(6, sqr(add(2, x)))
compose(
curry(add, 6),
add::curry(6),
sqr,
curry(add, 2)
add::curry(2),
);
// or with the sweetjs macro
var myFunc = curry(add, 6) ...
sqr ...
curry(add, 2)
// map(filter(list, even), sqr)
compose(
curry(map, curry.__, sqr),
curry(filter, curry.__, even)
map::curry(_, sqr),
filter::curry(_, even),
)([1,2,3,4,5,6,7,8]) // => [4, 16, 36, 64]
```
### `::` huh?
If you’re wondering what the `::` thing means, you’d better read this excellent [overview](https://github.com/jussi-kalliokoski/trine/blob/5b735cbfb6b28ae94bac0446d9ecd5ce51fb149b/README.md#why) by [@jussi-kalliokoski](https://github.com/jussi-kalliokoski) or have a look at the [function bind syntax proposal](https://github.com/zenparsing/es-function-bind).
Or checkout the [curry-this docs][ct].
Related
----
* [curry-this][ct]
License
----
MIT © [Christoph Hermann](http://stoeffel.github.io)
[r]: http://ramdajs.com
[ct]: https://github.com/stoeffel/curry-this

@@ -1,89 +0,1 @@

var compose = require('./index.js'),
curry = require('chickencurry'),
mockery = require('mockery'),
expect = require('expect.js');
function zero() {
return 0;
}
function inc(x) {
return x + 1;
}
function add(x, y) {
return x + y;
}
function add2(x) {
return x + 2;
}
function sqr(x) {
return x * x;
}
function even(x) {
return x % 2 === 0;
}
function filter(list, where) {
var newList = [];
for (var i = 0; i < list.length; i++) {
if (where(list[i]))
newList.push(list[i]);
}
return newList;
}
function map(list, mapper) {
var newList = [];
for (var i = 0; i < list.length; i++) {
newList.push(mapper(list[i]));
}
return newList;
}
describe('compose-function', function() {
it('should compose a new function', function() {
expect(compose(inc)).to.be.a('function');
expect(compose(inc)(0)).to.equal(1);
expect(compose(inc, inc)(0)).to.equal(2);
expect(compose(add2, inc)(0)).to.equal(3);
expect(compose(inc, sqr)(2)).to.equal(5);
expect(compose(sqr, inc)(2)).to.equal(9);
expect(compose(add2, add2, sqr, inc, inc)(2)).to.equal(20);
expect(compose(inc, add)(2, 3)).to.equal(6);
expect(
compose(
curry(map, curry.__, sqr),
curry(filter, curry.__, even)
)([1, 2, 3, 4, 5, 6, 7, 8])
).to.eql([4, 16, 36, 64]);
expect(
compose(
compose(
curry(map, curry.__, sqr)
),
compose(
curry(filter, curry.__, even)
)
)([1, 2, 3, 4, 5, 6, 7, 8])
).to.eql([4, 16, 36, 64]);
});
it('should create a function with the same arity as the last function', function() {
expect(compose(inc, zero).length).to.equal(0);
expect(compose(inc, add2).length).to.equal(1);
expect(compose(inc, add).length).to.equal(2);
});
it('should fail if no function is passed', function() {
expect(compose.bind(1)).to.throwError();
expect(compose.bind(null)).to.throwError();
expect(compose.bind(undefined)).to.throwError();
});
});
import './test/test.js';
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc