當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lodash.findKey函數代碼示例

本文整理匯總了TypeScript中lodash.findKey函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript findKey函數的具體用法?TypeScript findKey怎麽用?TypeScript findKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了findKey函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getMatchRequest

/**
 * 返回匹配的請求後綴和請求類型
 * ① 通過擴展名匹配,優先返回與擴展名匹配的`後綴`和`請求類型`
 * ② 未匹配到,默認是`.js 後綴` 和`REQUEST_JS 請求類型`
 *
 * @param {string} request
 * @param {RequestType} [requestType]
 * @returns {{exts: string[], requestType: RequestType}}
 */
function getMatchRequest (request: string, requestType?: RequestType): {lookupExts: string[], requestType: RequestType} {
  let ext = path.extname(request)
  let exts: string[] = []

  // 非白名單內的擴展名,默認通過 requestType 來獲取 ext 擴展名
  if (ext) {
    ext = _.findKey(config.ext, value => value === ext) ? ext : ''
  }

  if (!ext && !requestType) {
    throw new Error(`Ext 和 RequestType 不能同時為空`)
  }

  if (ext && requestType) {
    if (getRequestType(ext) !== requestType) {
      throw new Error(`Ext 和 RequestType 同時存在,但通過 Ext 找到的 RequestType 與實際的不符合`)
    }
  } else if (!ext && requestType) {
    exts = [
      ...exts,
      ...getRequestLookupExts(requestType)
    ]
  } else if (ext && !requestType) {
    requestType = getRequestType(ext)
  }

  if (!requestType) {
    throw new Error('沒有找到匹配的 RequestType,請確認是否將 Ext 與 RequestType 進行關聯')
  }

  return {
    lookupExts: exts,
    requestType
  }
}
開發者ID:bbxyard,項目名稱:bbxyard,代碼行數:44,代碼來源:resolveDep.ts

示例2: parse

export function parse(
  schema: JSONSchema | JSONSchema4Type,
  options: Options,
  rootSchema = schema as JSONSchema,
  keyName?: string,
  isSchema = true,
  processed: Processed = new Map<JSONSchema | JSONSchema4Type, AST>(),
  usedNames = new Set<string>()
): AST {

  // If we've seen this node before, return it.
  if (processed.has(schema)) {
    return processed.get(schema)!
  }

  const definitions = getDefinitions(rootSchema)
  const keyNameFromDefinition = findKey(definitions, _ => _ === schema)

  // Cache processed ASTs before they are actually computed, then update
  // them in place using set(). This is to avoid cycles.
  // TODO: Investigate alternative approaches (lazy-computing nodes, etc.)
  let ast = {} as AST
  processed.set(schema, ast)
  const set = (_ast: AST) => Object.assign(ast, _ast)

  return isSchema
    ? parseNonLiteral(schema as SchemaSchema, options, rootSchema, keyName, keyNameFromDefinition, set, processed, usedNames)
    : parseLiteral(schema, keyName, keyNameFromDefinition, set)
}
開發者ID:bcherny,項目名稱:json-schema-to-typescript,代碼行數:29,代碼來源:parser.ts

示例3: formatType

 private formatType(status: string): NotificationType {
   const types = {
     error: ['firing', 'active'],
     info: ['suppressed', 'unprocessed'],
     success: ['resolved']
   };
   return NotificationType[_.findKey(types, (type) => type.includes(status))];
 }
開發者ID:ceph,項目名稱:ceph,代碼行數:8,代碼來源:prometheus-alert-formatter.ts

示例4: function

PluginManager.registerPreexecPlugin(async function (job: Job): Promise<void> {
    const input = job.prompt.value;
    const key = _.findKey(await Aliases.all(), value => value === input);

    if (key && key.length < input.length) {
        /* tslint:disable:no-unused-expression */
        new Notification("Alias Reminder", { body: `You have an alias "${key}" for "${input}".` });
    }
});
開發者ID:Culttm,項目名稱:black-screen,代碼行數:9,代碼來源:AliasSuggestions.ts

示例5: constructor

  /**
   * Creates an instance of RequestExtend.
   * @param {Request.Options} options
   * @memberof RequestExtend
   */
  constructor (options: Request.Options) {
    super(options)

    // 通過擴展名,取得key值
    let key = _.findKey(config.ext, value => value === this.ext)
    if (key) {
      // 通過 key 值,設置實例中對應字段的真值,其餘都為假值
      this[`is${changeCase.pascalCase(key)}`] = true
    }
  }
開發者ID:bbxyard,項目名稱:bbxyard,代碼行數:15,代碼來源:Request.ts

示例6: adjacentEdges

 adjacentEdges() {
   // find an edge with this as a source
   const v2 = parseInt(
     _.findKey(this.polyhedron.edgeToFaceGraph()[this.index])!,
   );
   const e0 = new Edge(this, this.polyhedron.vertices[v2]);
   let e = e0;
   const result = [];
   let count = 0;
   do {
     count++;
     result.push(e);
     e = e.prev().twin();
     if (count > 10) throw new Error('we done messed up');
   } while (!e.equals(e0));
   return result;
 }
開發者ID:tessenate,項目名稱:polyhedra-viewer,代碼行數:17,代碼來源:Vertex.ts

示例7:

      .map(target => {
        if (target.id && target.id.length > 0 && target.expression && target.expression.length > 0) {
          return [target];
        }

        const variableIndex = _.keyBy(templateSrv.variables, 'name');
        const dimensionKey = _.findKey(target.dimensions, v => {
          const variableName = templateSrv.getVariableName(v);
          return templateSrv.variableExists(v) && !_.has(scopedVars, variableName) && variableIndex[variableName].multi;
        });

        if (dimensionKey) {
          const multiVariable = variableIndex[templateSrv.getVariableName(target.dimensions[dimensionKey])];
          return this.getExpandedVariables(target, dimensionKey, multiVariable, templateSrv);
        } else {
          return [target];
        }
      })
開發者ID:johntdyer,項目名稱:grafana,代碼行數:18,代碼來源:datasource.ts

示例8: return

      .map(target => {
        const dimensionKey = _.findKey(target.dimensions, v => {
          return templateSrv.variableExists(v) && !_.has(scopedVars, templateSrv.getVariableName(v));
        });

        if (dimensionKey) {
          const multiVariable = _.find(templateSrv.variables, variable => {
            return (
              templatingVariable.containsVariable(target.dimensions[dimensionKey], variable.name) && variable.multi
            );
          });
          const variable = _.find(templateSrv.variables, variable => {
            return templatingVariable.containsVariable(target.dimensions[dimensionKey], variable.name);
          });
          return this.getExpandedVariables(target, dimensionKey, multiVariable || variable, templateSrv);
        } else {
          return [target];
        }
      })
開發者ID:acedrew,項目名稱:grafana,代碼行數:19,代碼來源:datasource.ts

示例9: findKey

    myZWave.onValueChange(function(node, commandClass, value) {
      if (node.nodeId === 3) {
        Logger.error(
          "ERROR: Main switch is now probably ignored by OpenZWave. Exiting process so it can be restarted."
        );

        throw "Main switch erroneously ignored. Exiting!";
      }

      const lightName = findKey(lights, function(light) {
        return light.id === node.nodeId;
      });

      if (!lightName) {
        Logger.error(`Unknown light with nodeId ${node.nodeId}. Command class: ${commandClass}, value: "${value}"`);

        return;
      } else if (!lights[lightName]) {
        Logger.error(
          `Unknown light with name "${lightName}" (id: ${
            node.nodeId
          }). Command class: ${commandClass}, value: "${value}"`
        );

        return;
      }

      if (!lights[lightName].values) {
        lights[lightName].values = {};
      }
      lights[lightName].values[commandClass] = value;

      Logger.debug(`Received value change from ${node.nodeId}`);

      const valueToString = `${value.value_id}, ${value.label}`;
      Logger.debug(`New value for node ${node.nodeId}: ${valueToString}`);
    });
開發者ID:lmeijvogel,項目名稱:my_node_openzwave,代碼行數:37,代碼來源:Main.ts

示例10: getNameByValue

 getNameByValue(value: string): string | undefined {
     return _.findKey(this.storage, storageValue => storageValue === value);
 }
開發者ID:Alubatm,項目名稱:black-screen,代碼行數:3,代碼來源:Aliases.ts


注:本文中的lodash.findKey函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。