Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelnisi/popfun
Remove last element from array, if it is a function
https://github.com/michaelnisi/popfun
Last synced: about 1 month ago
JSON representation
Remove last element from array, if it is a function
- Host: GitHub
- URL: https://github.com/michaelnisi/popfun
- Owner: michaelnisi
- License: mit
- Created: 2012-09-28T05:47:23.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-09-08T15:25:06.000Z (over 9 years ago)
- Last Synced: 2024-11-14T21:30:09.302Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 172 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# popfun - pop function
The **popfun** [Node.js](http://nodejs.org/) module removes the last element from an array if it is a function and returns it. This can be handy to fetch the callback from an arguments array (`[err, a1, a2, an, cb]`).
[![Build Status](https://secure.travis-ci.org/michaelnisi/popfun.png)](http://travis-ci.org/michaelnisi/popfun)
## Example
```js
var popfun = require('popfun')function echo () {
var args = Array.prototype.slice.call(arguments)
var callback = popfun(args)
if (callback) callback(null, args.join(' '))
}echo('hey', 'you', function (err, msg) {
console.log(msg)
})
```## Exports
### popfun(args)
- `args` Object to pop if last element is of type 'function'
This function can take any type. If it receives an array, it pops the last element, and returns the element; else it returns `null`.
## Installation
With [npm](https://npmjs.org/package/popfun) do:
```
npm install popfun
```## License
[MIT License](https://raw.github.com/michaelnisi/popfun/master/LICENSE)