How to use the lodash.map function in lodash

To help you get started, we’ve selected a few lodash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TryGhost / Ghost / core / server / lib / fs / read-csv.js View on Github external
.on('end', function () {
                // If CSV is single column - return all values including header
                var headers = _.keys(rows[0]), result = {}, columnMap = {};
                if (columnsToExtract.length === 1 && headers.length === 1) {
                    results = _.map(rows, function (value) {
                        result = {};
                        result[columnsToExtract[0].name] = value[headers[0]];
                        return result;
                    });
                } else {
                    // If there are multiple columns in csv file
                    // try to match headers using lookup value

                    _.map(columnsToExtract, function findMatches(column) {
                        _.each(headers, function checkheader(header) {
                            if (column.lookup.test(header)) {
                                columnMap[column.name] = header;
                            }
                        });
                    });

                    results = _.map(rows, function evaluateRow(row) {
                        var result = {};
                        _.each(columnMap, function returnMatches(value, key) {
                            result[key] = row[value];
                        });
                        return result;
                    });
                }
                resolve(results);
github FreeFeed / freefeed-server / data_transfer / transfer.js View on Github external
async _transferGroupFeeds(id){
    console.log("Processing feeds of group", id)

    let requiredFeedIds = {
      'RiverOfNews':   null,
      'Hides':         null,
      'Comments':      null,
      'Likes':         null,
      'Posts':         null
    }

    let groupFeedIds = await this.redis.hgetallAsync(`user:${id}:timelines`)
    _.merge(requiredFeedIds, groupFeedIds)

    return Promise.all(_.map(requiredFeedIds, async (feedId, feedName)=>{
      let feed = {
        name: feedName,
        userId: id
      }
      if (feedId){
        feed = await this.redis.hgetallAsync(`timeline:${feedId}`)
        feed.id = feedId
      }
      if(this.writeGroupFeeds){
        await this.pgAdapter.createTimeline(feed)
      }
    }))
  }
github lala010addict / Rich-Neighbors / server / api / campaign / campaign.model.js View on Github external
addressValidator.validate( address, addressValidator.match.streetAddress, function (err, exact, inexact) {
      console.log('input: ', address.toString())
      console.log('match: ', _.map(exact, function(a) {
        return a.toString();
      }));
      console.log('did you mean: ', _.map(inexact, function(a) {
        return a.toString();
      }));

      //access some props on the exact match
      var first = exact[0];
      console.log(first.streetNumber + ' '+ first.street);
    });
github mcfly-io / generator-mcfly / class / component.js View on Github external
prompting: function(done) {

        var that = this;

        var choices = _.map(this.clientModules, function(module) {
            return {
                name: module,
                value: module
            };
        });

        var prompts = [{
            name: 'modulename',
            type: 'list',
            choices: choices,
            when: function() {
                var result = !that.modulename || that.modulename.length <= 0;
                return result;
            },
            message: 'What is the name of your module ?',
            default: that.modulename || (choices && choices.length >= 1 ? choices[0].value : that.modulename),
github microsoft / fluent-ui-react / docs / src / components / ColorSchemes.tsx View on Github external
render: ({ name, themes, headers, stardust: { classes } }) => {
    if (themes.length === 0) return <>

    const colorSchemes = _.map(themes, theme => theme.siteVariables.colorScheme[name])

    const elements = _.flatMap(_.head(colorSchemes), (i, token) => [
      ,
      ..._.map(colorSchemes, (colorScheme, i) => (
github AndreaMinato / tailwind-heropatterns / index.js View on Github external
return function({ e, addUtilities }) {
    if (patterns.length === 0) patterns = Object.keys(heros);
    if (Object.keys(colors).length === 0) colors = defaultColors;
    if (Object.keys(opacity).length === 0) opacity = defaultOpacity;

    const newUtilities = _.map(opacity, (alpha, opacityName) => {
      return _.map(colors, (color, colorName) => {
        color = color.replace("#", "%23");
        return patterns.reduce((o, patternName) => {
          let className = `bg-hero-${patternName}`;
          if (colorName != "default") className += `-${colorName}`;
          if (opacityName != "default") className += `-${opacityName}`;
          className = `.${e(className)}`;

          if (!heros[patternName]) return Object.assign(o, {});
          return Object.assign(o, {
            [className]: {
              backgroundImage: heros[patternName]
                .replace("FILLCOLOR", color)
                .replace("FILLOPACITY", alpha)
            }
          });
github liqd / adhocracy3 / src / adhocracy_frontend / adhocracy_frontend / static / js / Packages / AngularHelpers / AngularHelpers.ts View on Github external
export var getFirstFormError = (form, element) => {
    var getErrorControllers = (ctrl) => {
        if (ctrl.hasOwnProperty("$modelValue")) {
            return [ctrl];
        } else {
            var childCtrls = _.flatten(_.values(ctrl.$error));
            return _.flatten(_.map(childCtrls, getErrorControllers));
        }
    };

    var errorControllers = getErrorControllers(form);
    var names = _.uniq(_.map(errorControllers, "$name"));
    var selector = _.map(names, (name) => "[name=\"" + name + "\"]").join(", ");

    return element.find(selector).first();
};
github khartec / waltz / waltz-ng / client / widgets / simple-stack-chart.js View on Github external
function calculateLayoutData(values = [], xScale) {
    let last = xScale(0);
    return _.map(values, v => {
        const width = v
            ? xScale(v)
            : 0;

        const d = {
            x: last,
            width
        };

        last += width;
        return d;
    });
}
github noobaa / noobaa-core / src / server / system_services / account_server.js View on Github external
const permission_list = account.allowed_buckets.permission_list;
        const allowed_buckets = {
            full_permission: full_permission
        };
        if (!full_permission) {
            if (!permission_list) {
                throw new RpcError('Cannot configure without permission_list when explicit permissions');
            }
            allowed_buckets.permission_list = _.map(permission_list, bucket => bucket.name);
        }
        info.allowed_buckets = allowed_buckets;
        info.default_pool = account.default_pool.name;
        info.can_create_buckets = account.allow_bucket_creation;
    }

    info.systems = _.compact(_.map(account.roles_by_system, function(roles, system_id) {
        var system = system_store.data.get_by_id(system_id);
        if (!system) {
            return null;
        }
        return {
            name: system.name,
            roles: roles
        };
    }));

    const credentials_cache = account.sync_credentials_cache || [];
    const external_connections = {
        count: credentials_cache.length
    };

    if (!_.isUndefined(include_connection_cache) && include_connection_cache) {
github elastic / timelion / server / parser / chain_runner.js View on Github external
function invoke (fnName, args) {
  var functionDef = functions[fnName];
  args = repositionArguments(functionDef, args);
  args = _.map(args, function (item) {

    if (_.isObject(item)) {
      switch (item.type) {
        case 'function':
          if (queryCache[getQueryCacheKey(item)]) {
            stats.queryCount++;
            return Promise.resolve(_.cloneDeep(queryCache[getQueryCacheKey(item)]));
          }
          return invoke(item.function, item.arguments);
        case 'reference':
          var reference = sheet[item.plot - 1][item.series - 1];
          return invokeChain(reference);
        case 'chain':
          return invokeChain(item);
        case 'chainList':
          return resolveChainList(item.list);