├── .travis.yml ├── index.js ├── .editorconfig ├── package.json ├── test.js ├── license └── readme.markdown /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - 0.10 5 | 6 | script: 7 | - npm test 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = function (fn) { 2 | return function (first) { 3 | return fn(first); 4 | }; 5 | }; 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "but", 3 | "version": "2.0.1", 4 | "description": "If only there was a way to pass along a callback with just a single argument.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": "https://github.com/bevacqua/but.git", 10 | "author": "Nicolas Bevacqua (http://bevacqua.io/)", 11 | "license": "MIT", 12 | "devDependencies": { 13 | "mocha": "^2.1.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var assert = require('assert'); 4 | var but = require('./'); 5 | var n = [1, 2, 3, 4, 5]; 6 | 7 | describe('a plain callback', function() { 8 | var nMappedPlain = n.map(parseInt); 9 | it('is terrible', function() { 10 | assert(isNaN(nMappedPlain.pop())); 11 | }) 12 | }); 13 | 14 | describe('a but callback', function() { 15 | it('is awesome', function() { 16 | var nMappedAwesome = n.map(but(parseInt)); 17 | assert(!isNaN(nMappedAwesome.pop())); 18 | }) 19 | }); 20 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2015 Nicolas Bevacqua 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /readme.markdown: -------------------------------------------------------------------------------- 1 | # but [![Build Status][1]][2] 2 | 3 | **But expands your functional horizons to the edge of the universe** 4 | 5 | > If only there was a way to pass along a callback with just a single argument. 6 | 7 | You know how you like chaining asynchronous function calls **but** sometimes weird arguments get in the way of your waterfall series with unpredictable arguments? 8 | 9 | How about attempting to `parseInt` in a `map` only to find out `map` spews three arguments? 10 | 11 | # NO MORE! 12 | 13 | ```shell 14 | npm install but --save 15 | ``` 16 | 17 | # Usage 18 | 19 | Functional arguments giving you headaches? 20 | 21 | ##### Before 22 | 23 | ```js 24 | n.map(function (val) { 25 | return parseInt(val); 26 | }); 27 | ``` 28 | 29 | ##### After 30 | 31 | ```js 32 | n.map(but(parseInt)); 33 | ``` 34 | 35 | Works on `.forEach` or any functional array method as well! Classy. 36 | 37 | ##### Before 38 | 39 | ```js 40 | n.forEach(function (val) { 41 | console.log(val); 42 | }); 43 | ``` 44 | 45 | ##### After 46 | 47 | ```js 48 | n.forEach(but(console.log.bind(console))); // you can omit bind on node.js 49 | ``` 50 | 51 | Mongoose being weird? 52 | 53 | ##### Before 54 | 55 | ```js 56 | async.waterfall([ 57 | function (next) { 58 | new User(model).save(function (err) { 59 | next(err); 60 | }); 61 | }, 62 | function (next) { 63 | // MOAR CODE 64 | } 65 | ]) 66 | ``` 67 | 68 | ##### After 69 | 70 | ```js 71 | async.waterfall([ 72 | function (next) { 73 | new User(model).save(but(next)); 74 | }, 75 | function (next) { 76 | // MOAR CODE 77 | } 78 | ]) 79 | ``` 80 | 81 | # Why? 82 | 83 | It had to be done. It is known. 84 | 85 | # License 86 | 87 | MIT 88 | 89 | [1]: https://travis-ci.org/bevacqua/but.png?branch=master 90 | [2]: https://travis-ci.org/bevacqua/but 91 | --------------------------------------------------------------------------------