Skip to content

Commit

Permalink
updates in: .gitignore, .eslintrc, readme. JSDocs and version for bro…
Browse files Browse the repository at this point in the history
…wsers
  • Loading branch information
pawelzny committed Jul 16, 2016
1 parent 7c0521a commit ff640bb
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@
"no-delete-var": ["error"],
"no-label-var": ["error"],
"no-undefined": ["error"],
"no-unused-vars": ["warn", {
"args": "after-used"
}],
"no-unused-vars": 0,
"array-bracket-spacing": ["warn", "never"],
"block-spacing": ["warn", "never"],
"brace-style": ["warn", "1tbs", {
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ jspm_packages

# Optional REPL history
.node_repl_history

# IDE directories
.vscode
.idea
.settings
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# last-callback v1.0.1
# last-callback v 1.0.3

## Description

Get and call last given argument if is a function. You do not need to check last argument manually any more.
All you need to do is to pass arguments array to this little module, then call it, or bind with `this` context.
Last-callback always return a function with build in validation. Last not callable argument will be omitted without throwing any exception.
Last-callback always return function with built in validation. Last non callable argument will be ignored without throwing any exception.

last-callback is compatybile with ES5 and latest.
last-callback is compatible with ES5 and latest.

[![npm](https://img.shields.io/npm/l/last-callback.svg?maxAge=2592000)]()
[![npm](https://img.shields.io/npm/dt/last-callback.svg?maxAge=2592000)]()
Expand All @@ -18,7 +18,7 @@ last-callback is compatybile with ES5 and latest.

NodeJS >= 4.4.0

## Instalation
## installation

with NPM:

Expand All @@ -32,15 +32,15 @@ last-callback respects: bind, call, and apply methods;

### ES6 Style

If you are using `NodeJS >= 6.2` You should definitly use __ES6 style__ with spread operators.
If you are using `NodeJS >= 6.2` You should definitely use __ES6 style__ with spread operators.

```javascript
const lastCallback = require('last-callback');

function myFunc (param1) {
function myFunc (param) {
let callback = lastCallback(...arguments);

callback(param1);
callback(param);
}

myFunc('test value', function (param) {
Expand All @@ -56,10 +56,10 @@ If you are still using `NodeJS < 6.2.0`, i.e. `NodeJS 4.4.7 LTS`, you can use __
```javascript
var lastCallback = require('last-callback');

function myFunc (param1) {
function myFunc (param) {
var callback = lastCallback.apply(null, arguments);

callback(param1);
callback(param);
}

myFunc('test value', function (param) {
Expand All @@ -72,12 +72,12 @@ myFunc('test value', function (param) {
```javascript
var lastCallback = require('last-callback');

function myFunc (param1) {
function myFunc (param) {
var callback = lastCallback.apply(null, arguments);

this.contextVariable = 'this is my context';

callback.call(this, param1); // bind context if you need it
callback.call(this, param); // bind context if you need it
}

myFunc('test value', function (param) {
Expand All @@ -88,33 +88,33 @@ myFunc('test value', function (param) {

### Recursive callback

You can use recursive callbacks if needed.
You can use recursive callback if needed.

```javascript
const lastCallback = require('last-callback');

let
iterator = 1,
iteration = 1,
limit = 5;

function myFunc (iterator) {
function myFunc (iteration) {
let callback = lastCallback(...arguments);

callback(iterator);
callback(iteration);
}

function recursiveCallabck (iterator) {
if (iterator === limit) {
function recursiveCallabck (iteration) {
if (iteration >= limit) {
return;
}

console.log(iterator);
console.log(iteration);

iterator += 1;
recursiveCallabck(iterator);
iteration += 1;
recursiveCallabck(iteration);
}

myFunc(iterator, recursiveCallabck);
myFunc(iteration, recursiveCallabck);
// console log:
// 1
// 2
Expand Down
29 changes: 29 additions & 0 deletions browser/last-callback.v1.0.3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Last callback selects last passed argument.
* If this last argument is a function, it will be invoke with
* given context, and arguments.
*
* Last callback returns safe function ready to call.
* Basicly last-callback it's a wrapper around your callback function.
*
* @function last-callback
* @author Paweł Zadrożny <[email protected]> (https://pawelzny.com/)
* @copyright Paweł Zadrożny 2016
* @license MIT
* @version 1.0.3
*
* @example
* var callback = lastCallback.apply(null, arguments); // set callback
* callback.apply(this, arguments); // invoke callback with arguments
*
* @returns {Function} callback wrapper
*/
function lastCallback () {
var last = arguments[arguments.length - 1];

return function callback () {
if (typeof last === 'function') {
last.apply(this, arguments);
}
};
}
1 change: 1 addition & 0 deletions browser/last-callback.v1.0.3.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function lastCallback(){var n=arguments[arguments.length-1];return function(){"function"==typeof n&&n.apply(this,arguments)}}
21 changes: 18 additions & 3 deletions last-callback.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
/**
* Get last argument and call if it is a function.
* Last callback selects last passed argument.
* If this last argument is a function, it will be invoke with
* given context, and arguments.
*
* @returns {Function}
* Last callback returns safe function ready to call.
* Basicly last-callback it's a wrapper around your callback function.
*
* @module last-callback
* @author Paweł Zadrożny <[email protected]> (https://pawelzny.com/)
* @copyright Paweł Zadrożny 2016
* @license MIT
* @version 1.0.3
*
* @example
* const callback = lastCallback(...arguments); // set callback
* callback(...arguments); // invoke callback with arguments
*
* @returns {Function} callback wrapper
*/
module.exports = function lastCallback () {
var last = arguments[arguments.length -1];
var last = arguments[arguments.length - 1];

return function callback () {
if (typeof last === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "last-callback",
"version": "1.0.2",
"version": "1.0.3",
"author": "Paweł Zadrożny <[email protected]> (http://pawelzny.com/npm/env)",
"description": "Get and call last given argument if is a function.",
"keywords": [
Expand Down

0 comments on commit ff640bb

Please sign in to comment.