Issues (2242)

node_modules/wrappy/wrappy.js (2 issues)

1
// Returns a wrapper function that returns a wrapped callback
2
// The wrapper function should do some stuff, and return a
3
// presumably different callback function.
4
// This makes sure that own properties are retained, so that
5
// decorations and such are not lost along the way.
6
module.exports = wrappy
7
function wrappy (fn, cb) {
8
  if (fn && cb) return wrappy(fn)(cb)
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
9
10
  if (typeof fn !== 'function')
11
    throw new TypeError('need wrapper function')
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
12
13
  Object.keys(fn).forEach(function (k) {
14
    wrapper[k] = fn[k]
15
  })
16
17
  return wrapper
18
19
  function wrapper() {
20
    var args = new Array(arguments.length)
21
    for (var i = 0; i < args.length; i++) {
22
      args[i] = arguments[i]
23
    }
24
    var ret = fn.apply(this, args)
25
    var cb = args[args.length-1]
26
    if (typeof ret === 'function' && ret !== cb) {
27
      Object.keys(cb).forEach(function (k) {
28
        ret[k] = cb[k]
29
      })
30
    }
31
    return ret
32
  }
33
}
34