本文整理汇总了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
}
}
示例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)
}
示例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))];
}
示例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}".` });
}
});
示例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
}
}
示例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;
}
示例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];
}
})
示例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];
}
})
示例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}`);
});
示例10: getNameByValue
getNameByValue(value: string): string | undefined {
return _.findKey(this.storage, storageValue => storageValue === value);
}