本文整理汇总了TypeScript中lodash/fp.isNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNumber函数的具体用法?TypeScript isNumber怎么用?TypeScript isNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNumber函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: get
Object.keys(sources).reduce<DetailItem[]>((accumulator, source) => {
const item = get(source, sources);
if (Array.isArray(item) || isString(item) || isNumber(item)) {
const field = path ? `${path}.${source}` : source;
category = field.split('.')[0];
if (isEmpty(category) && baseCategoryFields.includes(category)) {
category = 'base';
}
return [
...accumulator,
{
category,
field,
values: item,
originalValue: item,
} as DetailItem,
];
} else if (isObject(item)) {
return [
...accumulator,
...getDataFromHits(item, category || source, path ? `${path}.${source}` : source),
];
}
return accumulator;
}, []);
示例2: parseFloat
const convertToNumber = (value: object | number | boolean | string): number => {
if (isNumber(value)) {
return value;
} else if (isString(value)) {
return parseFloat(value);
} else {
return NaN;
}
};
示例3: if
export const parseQueryValue = (
value: string | number | object | undefined | null
): string | number => {
if (value == null) {
return '';
} else if (isObject(value)) {
return JSON.stringify(value);
} else if (isNumber(value)) {
return value;
}
return value.toString();
};
示例4: GraphQLScalarType
* serialize: gets invoked when serializing the result to send it back to a client.
*
* parseValue: gets invoked to parse client input that was passed through variables.
*
* parseLiteral: gets invoked to parse client input that was passed inline in the query.
*/
export const toBooleanArrayScalar = new GraphQLScalarType({
name: 'BooleanArray',
description: 'Represents value in detail item from the timeline who wants to more than one type',
serialize(value): boolean[] | null {
if (value == null) {
return null;
} else if (Array.isArray(value)) {
return convertArrayToBoolean(value) as boolean[];
} else if (isString(value) || isObject(value) || isNumber(value)) {
return [convertToBoolean(value)];
}
return [value];
},
parseValue(value) {
return value;
},
parseLiteral(ast) {
switch (ast.kind) {
case Kind.BOOLEAN:
return ast.value;
case Kind.INT:
return ast.value;
case Kind.FLOAT:
return ast.value;