当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.chunk函数代码示例

本文整理汇总了TypeScript中lodash.chunk函数的典型用法代码示例。如果您正苦于以下问题:TypeScript chunk函数的具体用法?TypeScript chunk怎么用?TypeScript chunk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了chunk函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getObjects

    /**
     * Load all objects with given uris
     * (use bulk loading instead of getting objects one by one)
     *
     * @method getObjects
     * @param {String} projectId id of the project
     * @param {Array} objectUris array of uris for objects to be loaded
     * @return {Array} array of loaded elements
     */
    public getObjects(projectId: string, objectUris: string[]): any {
        const LIMIT = 50;
        const uri = `/gdc/md/${projectId}/objects/get`;

        const objectsUrisChunks = chunk(objectUris, LIMIT);

        const promises = objectsUrisChunks.map((objectUrisChunk) => {
            const body = {
                get: {
                    items: objectUrisChunk
                }
            };

            return this.xhr.post(uri, { body })
                .then((r: ApiResponse) => {
                    if (!r.response.ok) {
                        throw new ApiResponseError(r.response.statusText, r.response, r.responseBody);
                    }

                    return r.getData();
                })
                .then((result: any) =>
                    _get(result, ['objects', 'items']).map((item: any) => {
                        if (item.visualizationObject) {
                            return {
                                visualizationObject: convertReferencesToUris(item.visualizationObject)
                            };
                        }
                        return item;
                    }));
        });

        return Promise.all(promises).then(flatten);
    }
开发者ID:gooddata,项目名称:gooddata-js,代码行数:43,代码来源:metadata.ts

示例2: mergeAverageDownloadsPerDay

    mergeAverageDownloadsPerDay(packages, (error, packages) => {
      if (error) return callback(error);

      logger.debug('updating with %d packages (%s)', packages.length, updates_only ? 'updates only' : 'all packages');
      var batches = _.chunk(packages, 500);
      async.eachSeries(batches, insertPackages, callback);
    });
开发者ID:chbrown,项目名称:npm-search-server,代码行数:7,代码来源:database.ts

示例3: dataExport

async function dataExport() {
    await db.connect()

    const tmpFile = "/tmp/owid_chartdata.sql"

    const variablesToExportQuery = `
        SELECT DISTINCT cd.variableId FROM chart_dimensions cd
        WHERE NOT EXISTS (select * from tags t join chart_tags ct on ct.tagId = t.id where ct.chartId=cd.chartId and t.name='Private')
    `

    const variableIds = (await db.query(variablesToExportQuery)).map((row: any) => row.variableId)

    console.log(`Exporting data for ${variableIds.length} variables to ${tmpFile}`)

    await exec(`rm -f ${tmpFile}`)

    let count = 0
    for (const chunk of _.chunk(variableIds, 100)) {
        await exec(`mysqldump --no-create-info ${DB_NAME} data_values --where="variableId IN (${chunk.join(",")})" >> ${tmpFile}`)

        count += chunk.length
        console.log(count)
    }

    await db.end()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:26,代码来源:exportChartData.ts

示例4: _getBulkItems

  async _getBulkItems(
    itemList: D2ItemFetchRequest[],
    platformSelection: number,
    mode: number
  ): Promise<D2ItemFetchResponse[]> {
    if (!itemList.length) {
      return Promise.resolve<D2ItemFetchResponse[]>([]);
    }

    // DTR admins requested we only make requests in batches of 10, and not in parallel
    const arrayOfArrays: D2ItemFetchRequest[][] = _.chunk(itemList, 10);

    const results: D2ItemFetchResponse[] = [];

    for (const arraySlice of arrayOfArrays) {
      const promiseSlice = dtrFetch(
        `https://db-api.destinytracker.com/api/external/reviews/fetch?platform=${platformSelection}&mode=${mode}`,
        arraySlice
      ).then(handleD2Errors, handleD2Errors);

      try {
        loadingTracker.addPromise(promiseSlice);

        const result = await promiseSlice;
        results.push(...result);
      } catch (error) {
        console.error(error);
      }
    }

    return results;
  }
开发者ID:w1cked,项目名称:DIM,代码行数:32,代码来源:d2-bulkFetcher.ts

示例5: getTripPhases

export function getTripPhases(tripString: string): TripPhase[] {
  const tripStages = tripString
    .replace('\t', '')
    .split('\n')
    .map(line => line.trim())
    .filter(line => line.length !== 0)
    .filter(
      line =>
        line.startsWith('Depart') ||
        line.startsWith('Board') ||
        line.startsWith('Arrive')
    )

  const transfers = _.chunk(tripStages, 3)
  return transfers.map(([departureStr, boardingStr, arrivalStr]) => {
    const [from, dTime, dTimeAmPm] = departureRE.exec(departureStr)!!.slice(1)
    const departureTimeStr = `${dTime} ${dTimeAmPm}`
    const departure = { from: from.trim(), at: departureTimeStr }

    const [trainNumber, towards] = boardRE.exec(boardingStr)!!.slice(1)
    const board = { trainNumber, towards }

    const [destination, aTime, aTimeAmPm] = arrivalRE
      .exec(arrivalStr)!!
      .slice(1)
    const arrivalTimeStr = `${aTime} ${aTimeAmPm}`
    const arrival = { destination: destination.trim(), at: arrivalTimeStr }

    const duration = getDuration(departureTimeStr, arrivalTimeStr)

    return { departure, board, arrival, duration }
  })
}
开发者ID:kengorab,项目名称:njt-api,代码行数:33,代码来源:njt-trip-manager.ts

示例6: createEnrollmentTokens

  public async createEnrollmentTokens(
    user: FrameworkUser,
    numTokens: number = 1
  ): Promise<string[]> {
    const tokens = [];
    const enrollmentTokensTtlInSeconds = this.framework.getSetting('enrollmentTokensTtlInSeconds');

    const enrollmentTokenExpiration = moment()
      .add(enrollmentTokensTtlInSeconds, 'seconds')
      .toJSON();
    const enrollmentTokenSecret = this.framework.getSetting('encryptionKey');

    while (tokens.length < numTokens) {
      const tokenData = {
        created: moment().toJSON(),
        expires: enrollmentTokenExpiration,
        randomHash: randomBytes(26).toString(),
      };

      tokens.push({
        expires_on: enrollmentTokenExpiration,
        token: signToken(tokenData, enrollmentTokenSecret),
      });
    }

    await Promise.all(
      chunk(tokens, 100).map(tokenChunk => this.adapter.insertTokens(user, tokenChunk))
    );

    return tokens.map(token => token.token);
  }
开发者ID:elastic,项目名称:kibana,代码行数:31,代码来源:tokens.ts

示例7:

export async function batchAndCombine<T, K>(lookupIds: Array<K>, dataFetch: (chunkLookupIds: Array<K>) => Promise<Array<T>>) {
  const chunkedIds = _.chunk(lookupIds, MAX_DB_CHUNK_SIZE);
  const result: Array<Array<T>> = [];

  for (const chunk of chunkedIds) result.push(await dataFetch(chunk));

  const fullResults = _.flatten(result);
  // sort results
  // limit results
  return fullResults;
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:11,代码来源:database.ts

示例8: sortColorsByHue

function sortColorsByHue(hexColors: string[]) {
  const hslColors = _.map(hexColors, hexToHsl);

  const sortedHSLColors = _.sortBy(hslColors, ['h']);
  const chunkedHSLColors = _.chunk(sortedHSLColors, PALETTE_ROWS);
  const sortedChunkedHSLColors = _.map(chunkedHSLColors, chunk => {
    return _.sortBy(chunk, 'l');
  });
  const flattenedZippedSortedChunkedHSLColors = _.flattenDeep(_.zip(...sortedChunkedHSLColors));

  return _.map(flattenedZippedSortedChunkedHSLColors, hslToHex);
}
开发者ID:CorpGlory,项目名称:grafana,代码行数:12,代码来源:colors.ts

示例9: sortColorsByHue

export function sortColorsByHue(hexColors) {
  const hslColors = _.map(hexColors, hexToHsl);

  let sortedHSLColors = _.sortBy(hslColors, ['h']);
  sortedHSLColors = _.chunk(sortedHSLColors, PALETTE_ROWS);
  sortedHSLColors = _.map(sortedHSLColors, chunk => {
    return _.sortBy(chunk, 'l');
  });
  sortedHSLColors = _.flattenDeep(_.zip(...sortedHSLColors));

  return _.map(sortedHSLColors, hslToHex);
}
开发者ID:acedrew,项目名称:grafana,代码行数:12,代码来源:colors.ts

示例10: parse

function parse(hex: string): number[] {
  switch (hex.length) {
    case 3:
    case 4:
      return hex.split('')
        .map((n) => `${n}${n}`)
        .map((n) => parseInt(n, 16));
    case 6:
    case 8:
      return _.chunk(_.range(0, hex.length), 2)
        .map(([i, j]) => `${hex[i]}${hex[j]}`)
        .map((n) => parseInt(n, 16));
    default:
      // Invalid value was passed
      return [];
  }
}
开发者ID:mozisan,项目名称:menthe,代码行数:17,代码来源:hex.ts


注:本文中的lodash.chunk函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。