Add basic #includes helper for arrays
This commit is contained in:
parent
6c5208577a
commit
28415f0b74
|
@ -35,7 +35,7 @@ var Adaptor = module.exports = function Adaptor(opts) {
|
|||
this.details = {};
|
||||
|
||||
_.each(opts, function(opt, name) {
|
||||
if (!~["robot", "name", "adaptor", "events"].indexOf(name)) {
|
||||
if (!_.includes(["robot", "name", "adaptor", "events"], name)) {
|
||||
this.details[name] = opt;
|
||||
}
|
||||
}, this);
|
||||
|
|
|
@ -39,7 +39,7 @@ var Driver = module.exports = function Driver(opts) {
|
|||
_.each(opts, function(opt, name) {
|
||||
var banned = ["robot", "name", "connection", "driver", "events"];
|
||||
|
||||
if (!~banned.indexOf(name)) {
|
||||
if (!_.includes(banned, name)) {
|
||||
this.details[name] = opt;
|
||||
}
|
||||
}, this);
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
var Logger = require("./logger");
|
||||
var Logger = require("./logger"),
|
||||
_ = require("./utils/helpers");
|
||||
|
||||
// Explicitly these modules here, so Browserify can grab them later
|
||||
require("./test/loopback");
|
||||
|
@ -102,7 +103,7 @@ var Registry = module.exports = {
|
|||
for (var name in this.data) {
|
||||
var repo = this.data[name];
|
||||
|
||||
if (repo[entry] && ~repo[entry].indexOf(value)) {
|
||||
if (repo[entry] && _.includes(repo[entry], value)) {
|
||||
return repo.module;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,3 +202,11 @@ extend(H, {
|
|||
partial: partial,
|
||||
partialRight: partialRight
|
||||
});
|
||||
|
||||
function includes(arr, value) {
|
||||
return !!~arr.indexOf(value);
|
||||
}
|
||||
|
||||
extend(H, {
|
||||
includes: includes
|
||||
});
|
||||
|
|
|
@ -277,4 +277,16 @@ describe("Helpers", function() {
|
|||
expect(fn).to.be.calledWith("one", "two", "three");
|
||||
});
|
||||
});
|
||||
|
||||
describe("#includes", function() {
|
||||
it("checks if an array includes a value", function() {
|
||||
var fn = _.includes;
|
||||
|
||||
var arr = [1, "2", 3];
|
||||
|
||||
expect(fn(arr, 1)).to.be.eql(true);
|
||||
expect(fn(arr, "2")).to.be.eql(true);
|
||||
expect(fn(arr, {})).to.be.eql(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue