How to use lodash - 10 common examples

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 jimivdw / grunt-mutation-testing / utils / ExclusionUtils.js View on Github external
function parseASTComments(astNode) {
    var comments = [];
    if(astNode && astNode.leadingComments) {
        _.forEach(astNode.leadingComments, function(comment) {
            if(comment.type === 'Block') {
                comments = comments.concat(comment.value.split('\n').map(function(commentLine) {
                    // Remove asterisks at the start of the line
                    return commentLine.replace(/^\s*\*\s*/g, '').trim();
                }));
            } else {
                comments.push(comment.value);
            }
        });
    }

    return comments;
}
github verdaccio / verdaccio / test / unit / modules / plugin / auth.spec.ts View on Github external
test('should skip empty array', () => {
        const config: Config = new AppConfig(_.cloneDeep(authPluginPassThrougConf));
        const auth: IAuth = new Auth(config);

        expect(auth).toBeDefined();

        const callback = jest.fn();
        const value = [ ];

        // @ts-ignore
        auth.authenticate(null, value, callback);
        expect(callback.mock.calls).toHaveLength(1);
        expect(callback.mock.calls[0][0]).toBeDefined();
        expect(callback.mock.calls[0][1]).toBeUndefined();
      });
github outlandishideas / kasia / test / connect / connectWpPost.js View on Github external
it('should render post title', () => {
      const query = { complete: true, OK: true, entities: [postJson.id] }
      state = merge({}, stateMultipleEntities, { wordpress: { queries: { 0: query } } })
      rendered.update() // Fake store update from completed request
      expect(rendered.html()).toEqual('<div>Architecto enim omnis repellendus</div>')
    })
  })
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 choerodon / agile-service-old / react / src / app / agile / containers / program / Board / BoardHome / components / BoardBody / Cell.js View on Github external
findCard = (id) => {
    const { data: { boardFeatures: issues } } = this.props;

    const issue = find(issues, { issueId: id });
    const index = findIndex(issues, { issueId: id });
    // console.log(id, issue, index);
    return {
      issue,
      index,
    };
  }
github algolia / youtube-captions-scraper / src / index.js View on Github external
// * ensure we have access to captions data
  if (!decodedData.includes('captionTracks'))
    throw new Error(`Could not find captions for video: ${videoID}`);

  const regex = /({"captionTracks":.*isTranslatable":(true|false)}])/;
  const [match] = regex.exec(decodedData);
  const { captionTracks } = JSON.parse(`${match}}`);

  const subtitle =
    find(captionTracks, {
      vssId: `.${lang}`,
    }) ||
    find(captionTracks, {
      vssId: `a.${lang}`,
    }) ||
    find(captionTracks, ({ vssId }) =&gt; vssId &amp;&amp; vssId.match(`.${lang}`));

  // * ensure we have found the correct subtitle lang
  if (!subtitle || (subtitle &amp;&amp; !subtitle.baseUrl))
    throw new Error(`Could not find ${lang} captions for ${videoID}`);

  const { data: transcript } = await axios.get(subtitle.baseUrl);
  const lines = transcript
    .replace('', '')
    .replace('', '')
    .split('')
    .filter(line =&gt; line &amp;&amp; line.trim())
    .map(line =&gt; {
      const startRegex = /start="([\d.]+)"/;
      const durRegex = /dur="([\d.]+)"/;

      const [, start] = startRegex.exec(line);
github trufflesuite / ganache-core / lib / provider.js View on Github external
let intermediary = function(err, result) {
    // clone result so that we can mutate the response without worrying about
    // that messing up assumptions the calling logic might have about us
    // mutating things
    result = _.cloneDeep(result);
    let response;
    if (Array.isArray(result)) {
      response = [];
      for (let i = 0; i &lt; result.length; i++) {
        response.push(self.reportErrorInResponse(payload[i], err, result[i]));
      }
    } else {
      response = self.reportErrorInResponse(payload, err, result);
    }

    if (self.options.verbose) {
      self.options.logger.log(
        " &lt;   " +
          JSON.stringify(response, null, 2)
            .split("\n")
            .join("\n &lt;   ")
github brochington / declarity / src / EntityWrapper_old.js View on Github external
function getRenderContent(entityClassInstance) {
    const content = entityClassInstance.render();
    // console.log('renderContent');
    // console.log(content);
    if (isNil(content)) return [];

    return isArray(content) ? content : [content];
}
github kupi-network / kupi-terminal / server / core_components / checkCcxt.js View on Github external
const checkOrderbook = async function(name) {
  // console.log('+-+-+-+')
  try {
    var data = await global.CHECKSTOCK[name].fetchOrderBook(global.CHECKSYMBOLS[name].symbols[0])
    // console.log(data)
    var isObject = _.isPlainObject(data)
    var isArray = _.isArray(data.bids)
    var isNumber = _.isNumber(data.bids[0][0])
    if (isObject && isArray && isNumber) {
      global.CHECKCCXT[name]['orderbook'] = 'ok'
    } else {
      global.CHECKCCXT[name]['orderbook'] = 'ok, but strange shema'
    }
  } catch(err) {
    global.CHECKCCXT[name]['orderbook'] = serializeError(err).message
  }
}
github apigee-127 / bagpipes / lib / helpers.js View on Github external
function getParameterValue(parameter, context) {

  var path = parameter.path || parameter;

  var value = (path[0] === '.') ? JSPath.apply(path, context) : path;

  //console.log('****', path, context, value);

  // Use the default value when necessary
  if (_.isUndefined(value)) { value = parameter.default; }

  return value;
}