How to use the map function from underscore

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

541
542
543
544
545
546
547
548
549
550
551
function sendDataDisconnectReason(ctx, conn, code, description) {
  sendData(ctx, conn, {type: "disconnectReason", code: code, description: description});
}


function sendReleaseLock(ctx, conn, userLocks) {
  sendData(ctx, conn, {type: "releaseLock", locks: _.map(userLocks, function(e) {
    return {
      block: e.block,
      user: e.user,
      time: Date.now(),
fork icon171
star icon146
watch icon32

+ 3 other calls in file

302
303
304
305
306
307
308
309
310
311
    return this.player.currentPrompt();
}

get currentButtons() {
    var buttons = this.currentPrompt().buttons;
    return _.map(buttons, button => button.text.toString());
}

/**
 * Lists cards selectable by the player during the action
fork icon18
star icon17
watch icon0

+ 3 other calls in file

255
256
257
258
259
260
261
262
263
264
isPageHeading: field.isPageHeading,
isWarning: field.isWarning,
warning: t(warningValue),
detail: detail ? detail : '',
hint: conditionalTranslate(getTranslationKey(field, key, 'hint')),
options: _.map(field.options, function (obj) {
  let selected = false;
  let label;
  let value;
  let toggle;
fork icon14
star icon13
watch icon12

160
161
162
163
164
165
166
167
168
169

readList( function( err, data ) {
    if( err )
        return callback( err );

    var items = _.map( data, function( row ) {

        var name = k.rdb.getField( row, opts.foreignName );
        if( opts.foreignBoldName )
            name = k.rdb.getField( row, opts.foreignBoldName ) + opts.foreignNameSeparator + name;
fork icon3
star icon9
watch icon1

+ 11 other calls in file

5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
 // Return a copy of the object without the blacklisted properties.
_.omit = function(obj, iteratee, context) {
  if (_.isFunction(iteratee)) {
    iteratee = _.negate(iteratee);
  } else {
    var keys = _.map(flatten(arguments, false, false, 1), String);
    iteratee = function(value, key) {
      return !_.contains(keys, key);
    };
  }
fork icon0
star icon1
watch icon1

+ 8 other calls in file

114
115
116
117
118
119
120
121
122
        this;
    }, y, this);
}

f3_outer() {
    underscore.map(x, function f3_inner() {
        this;
    }, this);
}
fork icon2
star icon0
watch icon2

+ 4 other calls in file

894
895
896
897
898
899
900
901
902
903
);
for (let i = 0; i < pathsArrayPromises.length; i++) {
    await pathsArrayPromises[i]();
}

const repoEntriesPromises = _.map(
    repoEntries,
    (entry) => () =>
        new Promise(async (resolve, reject) => {
            const entryPath = path.join(
fork icon0
star icon2
watch icon3

+ 7 other calls in file

396
397
398
399
400
401
402
403
404
405
  }
} else if (_.isArray(schema)) {
  if (_.isEmpty(schema)) {
    throw new InvalidSchemaError('unions must have at least 1 branch');
  }
  var branchTypes = _.map(schema, function(branchType) { return _parseSchema(branchType, schema, namespace); });
  return new Union(branchTypes, namespace);
} else {
  throw new InvalidSchemaError('unexpected Javascript type for schema: ' + (typeof schema));
}
fork icon0
star icon1
watch icon1

+ 2 other calls in file

37
38
39
40
41
42
43
44
45
46
// Order used types according to 'options.order'.
var orderedTypes = _.filter(options.order, function(type) {
	return options.types.indexOf(type) !== -1
})

var src = _.map(orderedTypes, function(type) {
	return templates[type]({
		url: urls[type],
		fontName: options.fontName
	})
fork icon0
star icon1
watch icon1

52
53
54
55
56
57
58
59
60
61
if (!options.files.length) return done(new Error('"options.files" is empty.'))

// We modify codepoints later, so we can't use same object from default options.
if (options.codepoints === undefined) options.codepoints = {}

options.names = _.map(options.files, options.rename)
if (options.cssDest === undefined) {
	options.cssDest = path.join(options.dest, options.fontName + '.css')
}
if (options.htmlDest === undefined) {
fork icon0
star icon1
watch icon1

351
352
353
354
355
356
357
358
359
360
  });
  print(0, "Total: " + grandTotal.toFixed(1));
};

var setupReport = function () {
  entries = _.map(_.keys(bucketTimes), JSON.parse);
  _.each(_.filter(entries, hasChildren), function (parent) {
    injectOtherTime(parent);
  });
};
fork icon0
star icon7
watch icon4

+ 5 other calls in file

461
462
463
464
465
466
467
468
469
470
const promises = [
    new Promise(async (resolve, reject) => {
        try {
            const roles = await repo.getRoleEntries({});
            Promise.all(
                _.map(roles, (role) => removeRole(role._id))
            )
                .then(() => {})
                .catch(console.error);
        } catch (err) {
fork icon0
star icon2
watch icon0

+ 9 other calls in file

729
730
731
732
733
734
735
736
737
738
//add members to group
socket.on('add-group-members', function (data, callback) {
  // ChatroomController.findChatRoom({ chatRoomId: data.chatRoomId }, function (err, chatGroupResponse) {
    ChatroomController.fineMyName(data, function (err, resp) { 
      ChatroomController.getUserNames(data, function (err,username) { 
     let roomUserIds = _.map(data.users, 'userId');
    data['isGroup'] = true;
    data['createLogs'] = false;
    data['addUsers'] = true;
    data['creator_name']=resp
fork icon0
star icon1
watch icon0

96
97
98
99
100
101
102
103
104
105
// Prints a package list in a nice format.
// Input is an array of objects with keys 'name' and 'description'.
exports.printPackageList = function (items, options) {
  options = options || {};

  var rows = _.map(items, function (item) {
    var name = item.name;
    var description = item.description || 'No description';
    return [name, description];
  });
fork icon0
star icon0
watch icon7

196
197
198
199
200
201
202
203
204
205
};

set.directories = _.map(json.directories, function (d) {
  return {
    absPath: d.absPath,
    include: _.map(d.include, reFromJSON),
    exclude: _.map(d.exclude, reFromJSON),
    contents: d.contents
  };
});
fork icon0
star icon0
watch icon10

+ 11 other calls in file

281
282
283
284
285
286
287
288
289
290
// - name (entry name, typically a command name)
// - body (contents of body, trimmed to end with a newline but no blank lines)
var loadHelp = function () {
  var ret = [];
  var raw = files.readFile(files.pathJoin(__dirname, 'help.txt'), 'utf8');
  return _.map(raw.split(/^>>>/m).slice(1), function (r) {
    var lines = r.split('\n');
    var name = lines.shift().trim();
    return {
      name: name,
fork icon0
star icon0
watch icon1

193
194
195
196
197
198
199
200
201
    return '{}';
  }
  var spacing = new Array(indent + 1).join(' ');
  // XXX prettyprint!
  return "{\n" +
    _.map(node, function (value, key) {
      return spacing + "  " + key + ": " + put(value, indent + 2);
    }).join(',\n') + "\n" + spacing + "}";
};
fork icon0
star icon0
watch icon2

+ 11 other calls in file

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
  return keys;
};

// Retrieve the values of an object's properties.
_.values = function(obj) {
  return _.map(obj, _.identity);
};

// Return a sorted list of the function names available on the object.
// Aliased as `methods`
fork icon0
star icon0
watch icon0

+ 7 other calls in file

9
10
11
12
13
14
15
16
17
18
19
module1.fn()
module2();
console.log(module3.message)
console.log(module3.arr)


const result = uns.map(module3.arr,(item)=>{
  return item*3
});
console.log(result)

fork icon0
star icon0
watch icon0

+ 9 other calls in file

54
55
56
57
58
59
60
61
62
63
if(!data || !data.attributes) {
    h = '无属性信息';
    return;
} else {
    h = '<table class="table table-striped table-bordered" style="margin-bottom:0;">' +
    _.map(data.fields, function(field) {
        if(data.attributes[field.key] == undefined){
            return '';
        }
        return '<tr><td>' + field.name + ': </td><td>' + data.attributes[field.key] + '</td></tr>';
fork icon0
star icon0
watch icon1

+ 2 other calls in file