Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed Aug 25, 2014
0 parents commit efba29e
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
node_modules
coverage
11 changes: 11 additions & 0 deletions .travis.yml
@@ -0,0 +1,11 @@
language: node_js

notifications:
email:
on_success: never
on_failure: change

node_js:
- "0.10"

after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
@@ -0,0 +1,35 @@
# Invoke

[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Gittip][gittip-image]][gittip-url]

Functional utility for creating a function that will invoke the same method on every passed in object.

## Installation

```
npm install util-invoke --save
```

## Usage

```javascript
var children = [1, 2, 3, true];

children.map(invoke('toString')); //=> ['1', '2', '3', 'true']
```

## License

MIT

[npm-image]: https://img.shields.io/npm/v/util-invoke.svg?style=flat
[npm-url]: https://npmjs.org/package/util-invoke
[travis-image]: https://img.shields.io/travis/blakeembrey/invoke.svg?style=flat
[travis-url]: https://travis-ci.org/blakeembrey/invoke
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/invoke.svg?style=flat
[coveralls-url]: https://coveralls.io/r/blakeembrey/invoke?branch=master
[gittip-image]: https://img.shields.io/gittip/blakeembrey.svg?style=flat
[gittip-url]: https://www.gittip.com/blakeembrey
15 changes: 15 additions & 0 deletions invoke.js
@@ -0,0 +1,15 @@
var __slice = Array.prototype.slice;

/**
* Automatically invoke a predefined method on every passed in object.
*
* @param {String} method
* @return {Function}
*/
module.exports = function (method /*, ...args */) {
var args = __slice.call(arguments, 1);

return function (obj /*, ..args */) {
return obj[method].apply(obj, args.concat(__slice.call(arguments, 1)));
};
};
32 changes: 32 additions & 0 deletions package.json
@@ -0,0 +1,32 @@
{
"name": "util-invoke",
"version": "1.0.0",
"description": "Functional utility for invoking the same method on every call.",
"main": "invoke.js",
"scripts": {
"test": "istanbul cover _mocha -- -R spec"
},
"repository": {
"type": "git",
"url": "git://github.com/blakeembrey/invoke.git"
},
"keywords": [
"invoke",
"method",
"functional"
],
"author": {
"name": "Blake Embrey",
"email": "hello@blakeembrey.com",
"url": "http://blakeembrey.me"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/blakeembrey/invoke/issues"
},
"homepage": "https://github.com/blakeembrey/invoke",
"devDependencies": {
"istanbul": "^0.3.0",
"mocha": "^1.21.4"
}
}
14 changes: 14 additions & 0 deletions test.js
@@ -0,0 +1,14 @@
/* global describe, it */
var invoke = require('./');
var assert = require('assert');

describe('invoke', function () {
it('should invoke the method', function () {
var children = [1, 2, 3, true];

assert.deepEqual(
children.map(invoke('toString', 10)),
['1', '2', '3', 'true']
);
});
});

0 comments on commit efba29e

Please sign in to comment.