How to use the findWhere function from underscore

Find comprehensive JavaScript underscore.findWhere code examples handpicked from public code repositorys.

89
90
91
92
93
94
95
96
97
98
var dir = appConfig.STORY + "/" + content.localData.code

if (fs.existsSync(dir) && _.findWhere(localMap, {
	"identifier": content.identifier
})) {
	var localContent = _.findWhere(localMap, {
		"identifier": content.identifier
	})
	if (content.localData.pkgVersion !== localContent.localData.pkgVersion) {
		asyncTask.push(function (callback) {
fork icon76
star icon6
watch icon8

+ 5 other calls in file

382
383
384
385
386
387
388
389
390
391
deviceService.getDeviceByName(id, service, subservice, function (error, ngsiDevice) {
    if (error) {
        callback(error);
    } else {
        for (let i = 0; i < attributes.length; i++) {
            const lazyAttribute = _.findWhere(ngsiDevice.lazy, { name: attributes[i] });
            const command = _.findWhere(ngsiDevice.commands, { name: attributes[i] });
            let attributeType = 'string';

            if (command) {
fork icon74
star icon56
watch icon23

32
33
34
35
36
37
38
39
40
41
const compiled = {};
const templateCache = {};

function maxlength(field) {
  const validation = field.validate || [];
  const ml = _.findWhere(validation, { type: 'maxlength' }) || _.findWhere(validation, { type: 'exactlength' });
  if (ml) {
    return _.isArray(ml.arguments) ? ml.arguments[0] : ml.arguments;
  }
  return null;
fork icon14
star icon13
watch icon12

36
37
38
39
40
41
42
43
44
45
46
47
  return done(null, returnList);
};


exports.findByName = function(name, done) {
  var _ = require('underscore');
  var returnList = _.findWhere(admins, {name: name});
  return done(null, returnList);
};


exports.getRandomAdmin = function(done) {
fork icon1
star icon0
watch icon8

+ 4 other calls in file

187
188
189
190
191
192
193
194
195
196
  return;
}

spinner.succeed('Tags loaded');
const tags = JSON.parse(body).tags;
const defaultTag = _.findWhere(tags, { id: prefs.importer.tag });
const defaultTagName = defaultTag ? defaultTag.name : 'No tag';

inquirer.prompt([
  {
fork icon0
star icon0
watch icon1

163
164
165
166
167
168
169
170
171
172

PouchDB('testdb', function (err, db) {
  db.gql(query, function (err, actual) {
    if (!err) {
      var intersection = expected.filter(function (n) {
        return _.findWhere(actual.rows, n) !== undefined;
      });
      intersection.should.have.length(expected.length);
      actual.rows.should.have.length(expected.length);
      done();
fork icon0
star icon0
watch icon1

+ 6 other calls in file

186
187
188
189
190
191
192
193
194
195
var toolIsopack = new isopack.Isopack;
toolIsopack.initFromPath(
  latestReleaseToolPackage,
  tropohouse.default.packagePath(latestReleaseToolPackage,
                                 latestReleaseToolVersion));
var toolRecord = _.findWhere(toolIsopack.toolsOnDisk,
                             {arch: archinfo.host()});

// XXX maybe we shouldn't throw from this background thing
// counter: this is super weird and should never ever happen.
fork icon0
star icon0
watch icon2

+ 3 other calls in file

51
52
53
54
55
56
57
58
59
};

var ipAddress = function () {
  var netroute = require('netroute');
  var info = netroute.getInfo();
  var defaultRoute = _.findWhere(info.IPv4 || [], { destination: "0.0.0.0" });
  if (! defaultRoute) {
    return null;
  }
fork icon0
star icon0
watch icon7

+ 3 other calls in file

180
181
182
183
184
185
186
187
188
189
var toolUnipackage = new unipackage.Unipackage;
toolUnipackage.initFromPath(
  latestReleaseToolPackage,
  tropohouse.default.packagePath(latestReleaseToolPackage,
                                 latestReleaseToolVersion));
var toolRecord = _.findWhere(toolUnipackage.toolsOnDisk,
                             {arch: archinfo.host()});

// XXX maybe we shouldn't throw from this background thing
// counter: this is super weird and should never ever happen.
fork icon0
star icon0
watch icon2