/
index.js
36 lines (31 loc) · 874 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var _ = require("lodash");
// Detects whether fn is being called with a `this` value. If `this` is defined `this` is passed as the first argument to `fn`. Otherwise, `fn` is invoked normally.
function wrapLodashFn(fn) {
return function() {
"use strict";
var args;
var i;
var length;
if(typeof this === "undefined") {
return fn.apply(null, arguments);
} else {
length = arguments.length;
args = [this];
for(i = 0; i < length; i++) {
args.push(arguments[i]);
}
return fn.apply(null, args);
}
};
}
var wrappedLodash = _.pairs(_)
.filter(function(v) {
return typeof v[1] === "function";
})
.reduce(function(fns, pair) {
fns[pair[0]] = wrapLodashFn(pair[1]);
return fns;
}, {});
wrappedLodash.nodashWrap = wrapLodashFn;
wrappedLodash.lodash = _;
module.exports = wrappedLodash;