• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript lodash.entries函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: makeBidirectional

/**
 * Populate a graph with inverse operations.
 */
function makeBidirectional(graph: FullGraph) {
  const result: FullGraph = {};
  for (let [source, operations] of _.entries(graph)) {
    for (let [operation, sinks] of _.entries(operations)) {
      for (let sink of sinks) {
        const sinkValue = sink.value;
        if (!sinkValue) {
          continue;
        }
        if (!result[sinkValue]) {
          result[sinkValue] = {};
        }
        const reverseOp = getInverseOperation(operation);
        if (!result[sinkValue][reverseOp]) {
          result[sinkValue][reverseOp] = [];
        }
        if (sinkValue === source) {
          continue;
        }
        const newValue = { ...sink, value: source };
        if (operation === 'gyrate' && sink.direction) {
          newValue.direction = 'back';
        }
        result[sinkValue][reverseOp].push(newValue);
      }
    }
  }
  return graphMerge(result, graph);
}
开发者ID:tessenate,项目名称:polyhedra-viewer,代码行数:32,代码来源:operationGraph.ts


示例2: insertRequisiteTree

export function insertRequisiteTree(modules: Module[], prerequisites: PrereqTreeMap): Module[] {
  // Find modules which this module fulfill the requirements for
  const fulfillModulesMap: { [moduleCode: string]: Set<ModuleCode> } = {};
  for (const module of modules) {
    fulfillModulesMap[module.moduleCode] = new Set();
  }

  for (const [moduleCode, prereqs] of entries(prerequisites)) {
    for (const fulfillsModule of flattenTree(prereqs)) {
      if (fulfillModulesMap[fulfillsModule]) {
        // Since module requires fulfillsModule, that means fulfillsModule
        // fulfills the requirements for module
        fulfillModulesMap[fulfillsModule].add(moduleCode);
      }
    }
  }

  for (const module of modules) {
    const { moduleCode } = module;

    if (prerequisites[moduleCode]) {
      module.prereqTree = prerequisites[moduleCode];
    }

    if (fulfillModulesMap[moduleCode].size > 0) {
      module.fulfillRequirements = Array.from(fulfillModulesMap[moduleCode]);
    }
  }

  return modules;
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:31,代码来源:index.ts


示例3: nextBreakpoint

function nextBreakpoint(size: Breakpoint): number | null | undefined {
  const breakpointEntries = entries(breakpoints);
  const nextBreakpointIndex =
    breakpointEntries.findIndex(([breakpoint]) => breakpoint === size) + 1;
  if (nextBreakpointIndex >= breakpointEntries.length) return null;
  return breakpointEntries[nextBreakpointIndex][1];
}
开发者ID:nusmodifications,项目名称:nusmods,代码行数:7,代码来源:css.ts


示例4: run

  async run(input: Input) {
    this.logger.info(`Collating venues for ${this.academicYear} semester ${this.semester}`);

    // Insert module code and flatten lessons
    const venueLessons: LessonWithModuleCode[] = flatMap(input, (module) =>
      module.semesterData.timetable.map(
        (lesson: RawLesson): LessonWithModuleCode => ({
          ...lesson,
          moduleCode: module.moduleCode,
        }),
      ),
    );

    const venues = extractVenueAvailability(venueLessons);

    // Get a mapping of module code to module title to help with module aliasing
    const moduleCodeToTitle: { [moduleCode: string]: ModuleTitle } = {};
    input.forEach((module) => {
      moduleCodeToTitle[module.moduleCode] = module.module.title;
    });

    // Merge dual-coded modules and extract the aliases generated for use later
    const allAliases: ModuleAliases = {};
    for (const venue of values(venues)) {
      for (const availability of venue) {
        const { lessons, aliases } = mergeDualCodedModules(availability.classes);
        availability.classes = lessons;

        // Merge the alias mappings
        for (const [moduleCode, alias] of entries(aliases)) {
          // Only add the modules as alias if they have the same title
          const title = moduleCodeToTitle[moduleCode];
          const filteredAliases = Array.from(alias).filter(
            (module) => title === moduleCodeToTitle[module],
          );

          if (filteredAliases.length) {
            allAliases[moduleCode] = union(
              allAliases[moduleCode] || new Set(),
              new Set(filteredAliases),
            );
          }
        }
      }
    }

    // Save the results
    const outputAliases = mapValues(allAliases, (moduleCodes) => Array.from(moduleCodes));
    const venueList = Object.keys(venues);

    await Promise.all([
      this.io.venueInformation(this.semester, venues),
      this.io.venueList(this.semester, venueList),
      this.aliasCache.write(mapValues(outputAliases, (set): string[] => Array.from(set))),
    ]);

    return { venues, aliases: allAliases };
  }
开发者ID:nusmodifications,项目名称:nusmods,代码行数:58,代码来源:CollateVenues.ts


示例5: createStatementForTable

function createStatementForTable(tableName: string, model: SequelizeModel): string {
  const attributeStrings: string[] = []
  for (const [columnName, attribute] of entries((model as any).rawAttributes)) {
    attributeStrings.push(`${columnName}: ${convertAttribute(attribute as ISequelizeAttribute)}`)
  }

  const stringifiedAttributes = `{\n${attributeStrings.join(',\n')}\n}`
  return `queryInterface.createTable('${tableName}', ${stringifiedAttributes})`
}
开发者ID:patrickhulce,项目名称:klay,代码行数:9,代码来源:migration.ts


示例6: computeIncrementalMigrations

async function computeIncrementalMigrations(
  models: SequelizeModel[],
  connection: sequelize.Sequelize,
): Promise<IMigrationRequest[]> {
  const tablesResult: any[][] = await connection.query('show tables')
  const tablesInDb = new Set(tablesResult[0].map(row => values(row)[0]))
  const migrations: IMigrationRequest[] = []

  for (const model of models) {
    const tableName = model.getTableName() as string
    if (tablesInDb.has(tableName)) {
      const columnsResult: any[][] = await connection.query(`show columns from ${tableName}`)
      const indexesResult: any[][] = await connection.query(`show indexes from ${tableName}`)
      const columnsInDb = new Set(columnsResult[0].map(row => row.Field))
      const indexesInDb = new Set(indexesResult[0].map(row => row.Key_name))

      // see https://github.com/sequelize/sequelize/blob/b505723927305960003dae2a8b64e1f291a5f927/lib/model.js#L795-L808
      const columnsInKiln = (model as any).rawAttributes
      for (const [columnName, column] of entries(columnsInKiln)) {
        if (!columnsInDb.has(columnName)) {
          migrations.push({
            tableName,
            columnName,
            type: MigrationType.ADD_COLUMN,
            sequelizeData: column as ISequelizeAttribute,
          })
        }
      }

      const indexesInKiln = (model as any).options.indexes as ISequelizeIndex[]
      for (const index of indexesInKiln) {
        if (!indexesInDb.has(index.name)) {
          migrations.push({
            tableName,
            type: MigrationType.ADD_INDEX,
            sequelizeData: index,
          })
        }
      }
    } else {
      migrations.push({
        tableName,
        type: MigrationType.CREATE_TABLE,
        sequelizeData: model,
      })
    }
  }

  return migrations
}
开发者ID:patrickhulce,项目名称:klay,代码行数:50,代码来源:migration.ts


示例7: getIdFromPathMatch

  async getIdFromPathMatch(config: IMultiProjectConfig): Promise<string | undefined> {
    const { ctx } = this.e;

    for (const [ key, value ] of lodash.entries(config.projects)) {
      const id = key;

      if (value && value.root) {
        const projectDir = path.resolve(this.rootDirectory, value.root);

        if (ctx.execPath.startsWith(projectDir)) {
          debug(`Project id from path match: ${strong(id)}`);
          return id;
        }
      }
    }
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:16,代码来源:index.ts


示例8: buildPaths

export function buildPaths(router: IRouter, cache?: ISwaggerSchemaCache): IKeyedPaths {
  const paths: IKeyedPaths = {}

  const routeGroups = groupBy(router.routes, 'path')
  for (const [routePath, routeGroup] of entries(routeGroups)) {
    const path: swagger.Path = {}
    for (const route of routeGroup) {
      path[route.method] = buildOperation(route, cache)
    }

    const modifiedRoutePath = routePath.replace(/(.)\/$/, '$1')
    paths[modifiedRoutePath] = path
  }

  return paths
}
开发者ID:patrickhulce,项目名称:klay,代码行数:16,代码来源:paths.ts


示例9: createRouter

export function createRouter(
  routerOptions: IRouterOptions,
  kilnModel?: IKilnModel,
  executor?: IDatabaseExecutor,
): IRouter {
  const router = express.Router()

  const paramHandlers: IRouteParams = {}

  const routes: IRouterRoute[] = map(routerOptions.routes, (typeOrOption, key) => {
    const [method, path] = key.split(' ')
    const routeOptions = typeof typeOrOption === 'string' ? {type: typeOrOption} : typeOrOption
    const route = createRouteOrActionRoute(routeOptions, routerOptions, kilnModel, executor)

    for (const [name, handler] of entries(route.paramHandlers)) {
      const existing = paramHandlers[name] || handler
      modelAssertions.ok(
        isEqual(existing.model.spec, handler.model.spec),
        `incompatible params model for ${name}`,
      )

      paramHandlers[name] = handler
    }

    return {
      path,
      method: method.toLowerCase() as HTTPMethod,
      options: routeOptions,
      kilnModel,
      ...route,
    }
  })

  for (const [name, handler] of entries(paramHandlers)) {
    router.param(name, handler)
  }

  for (const route of routes) {
    router[route.method](route.path, route.middleware)
  }

  return {router, routes}
}
开发者ID:patrickhulce,项目名称:klay,代码行数:43,代码来源:create-router.ts


示例10: printConfig

  printConfig(ctx: ConfigContext, v: any): void {
    const { global, json } = ctx;

    if (json) {
      process.stdout.write(this.jsonStringify(v));
    } else {
      if (global && v && typeof v === 'object') {
        const columns = lodash.entries(v)
          .map(([k, v]) => [k, this.sanitizeEntry(k, v)])
          .map(([k, v]) => [strong(k), util.inspect(v, { colors: chalk.enabled })]);

        columns.sort((a, b) => strcmp(a[0], b[0]));

        this.env.log.rawmsg(columnar(columns, {}));
      } else {
        this.env.log.rawmsg(util.inspect(v, { depth: Infinity, colors: chalk.enabled }));
      }
    }
  }
开发者ID:driftyco,项目名称:ionic-cli,代码行数:19,代码来源:get.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.eq函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.endsWith函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap