本文整理汇总了TypeScript中lodash.isFinite函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isFinite函数的具体用法?TypeScript isFinite怎么用?TypeScript isFinite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isFinite函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: validateGrid
export function validateGrid(grid: Cell.Cell[][], startingPosition: Cell.Position): ValidationResult {
if (!_.some(_.flatten(grid), cell => Cell.isRoom(cell) && Cell.isTreasureRoom(cell))) {
return 'There is no treasure room';
}
if (!_.isFinite(startingPosition.row) || !_.isFinite(startingPosition.col)) {
return 'The starting position is malformed';
}
const srow = startingPosition.row;
const scol = startingPosition.col;
const withinGrid = 0 <= srow && srow < grid.length &&
0 <= scol && scol < grid[ 0 ].length;
if (!withinGrid) {
return 'The starting position is invalid';
}
const startCell = grid[ startingPosition.row ][ startingPosition.col ];
if (!(Cell.isRoom(startCell) && Cell.isPassageRoom(startCell))) {
return 'The starting position must be a passage room';
}
return true;
}
示例2: partialStatsToCompleteStats
export function partialStatsToCompleteStats(partial: PartialStats): Stats {
const ret: Stats = {
health: 0,
strength: 0,
intelligence: 0,
agility: 0
};
if (partial.health !== undefined && _.isFinite(partial.health)) {
ret.health = partial.health;
}
if (partial.intelligence !== undefined && _.isFinite(partial.intelligence)) {
ret.intelligence = partial.intelligence;
}
if (partial.strength !== undefined && _.isFinite(partial.strength)) {
ret.strength = partial.strength;
}
if (partial.agility !== undefined && _.isFinite(partial.agility)) {
ret.agility = partial.agility;
}
return ret;
}
示例3: domainExtent
export function domainExtent(numValues: number[], scaleType: 'linear' | 'log'): [number, number] {
const filterValues = scaleType === 'log' ? numValues.filter(v => v > 0) : numValues
const [minValue, maxValue] = extent(filterValues)
if (minValue !== undefined && maxValue !== undefined && isFinite(minValue) && isFinite(maxValue)) {
if (minValue !== maxValue) {
return [minValue, maxValue]
} else {
// Only one value, make up a reasonable default
return scaleType === 'log' ? [minValue/10, minValue*10] : [minValue-1, maxValue+1]
}
} else {
return scaleType === 'log' ? [1, 100] : [-1, 1]
}
}
示例4: setValue
public async setValue(opts: CommandOptions) {
// get value so we have a type
const splitted = opts.parameters.split(' ');
const pointer = splitted.shift();
let newValue = splitted.join(' ');
if (!pointer) {
return sendMessage(`$sender, settings does not exists`, opts.sender);
}
const currentValue = await get(global, pointer, undefined);
if (typeof currentValue !== 'undefined') {
if (isBoolean(currentValue)) {
newValue = newValue.toLowerCase().trim();
if (['true', 'false'].includes(newValue)) {
set(global, pointer, newValue === 'true');
sendMessage(`$sender, ${pointer} set to ${newValue}`, opts.sender);
} else {
sendMessage('$sender, !set error: bool is expected', opts.sender);
}
} else if (isNumber(currentValue)) {
if (isFinite(Number(newValue))) {
set(global, pointer, Number(newValue));
sendMessage(`$sender, ${pointer} set to ${newValue}`, opts.sender);
} else {
sendMessage('$sender, !set error: number is expected', opts.sender);
}
} else if (isString(currentValue)) {
set(global, pointer, newValue);
sendMessage(`$sender, ${pointer} set to '${newValue}'`, opts.sender);
} else {
sendMessage(`$sender, ${pointer} is not supported settings to change`, opts.sender);
}
} else {
sendMessage(`$sender, ${pointer} settings not exists`, opts.sender);
}
}
示例5: switch
configComponents.forEach(component => {
const [ key, value ] = component.split('=');
const lKey = key.toLowerCase();
switch (lKey[ 0 ]) {
case 'c': {
if (primordialCharacter.className === 'None') {
const chosenCharacterClass = _.find(Character.CHARACTER_CLASS_NAMES, (name) => {
return Helpers.isApproximateString(value, name);
});
if (chosenCharacterClass) {
primordialCharacter.className = chosenCharacterClass;
} else {
log.push(`Unrecognized character class: ${value}`);
}
}
break;
}
case 'a': {
if (primordialCharacter.allegiance === 'None') {
const chosenAllegiance = _.find(Character.ALLEGIANCES, (allegiance) => {
return Helpers.isApproximateString(value, allegiance);
});
if (chosenAllegiance) {
primordialCharacter.allegiance = chosenAllegiance;
} else {
log.push(`Unrecognized allegiance: ${value}`);
}
}
break;
}
case 'm': {
updatedNumModifiers = true;
if (primordialCharacter.numModifiers === 0) {
const chosenNumModifiers = _.parseInt(value, 10);
if (_.isFinite(chosenNumModifiers) && chosenNumModifiers >= 0) {
primordialCharacter.numModifiers = chosenNumModifiers;
} else {
log.push(`Bad number of modifiers: ${value}`);
}
break;
}
}
default: {
log.push(`Unrecognized key: ${key}`);
break;
}
}
});
示例6: evaluate
private evaluate(val: string): any {
let result;
try {
result = eval(val);
} catch (e) {
return 0;
}
if (!_.isFinite(result)) return 0;
return result;
}
示例7: createLinkModel
public createLinkModel(): LinkModel | null {
if (_.isFinite(this.maximumLinks)) {
var numberOfLinks: number = _.size(this.links);
if (this.maximumLinks === 1 && numberOfLinks >= 1) {
return _.values(this.links)[0];
} else if (numberOfLinks >= this.maximumLinks) {
return null;
}
}
return null;
}
示例8: formatValue
export function formatValue(value: number, options: { numDecimalPlaces?: number, unit?: string }): string {
const noTrailingZeroes = true
const numDecimalPlaces = defaultTo(options.numDecimalPlaces, 2)
const unit = defaultTo(options.unit, "")
const isNoSpaceUnit = unit[0] === "%"
let output: string = value.toString()
const absValue = Math.abs(value)
if (!isNoSpaceUnit && absValue >= 1e6) {
if (!isFinite(absValue))
output = "Infinity"
else if (absValue >= 1e12)
output = formatValue(value / 1e12, extend({}, options, { unit: "trillion", numDecimalPlaces: 2 }))
else if (absValue >= 1e9)
output = formatValue(value / 1e9, extend({}, options, { unit: "billion", numDecimalPlaces: 2 }))
else if (absValue >= 1e6)
output = formatValue(value / 1e6, extend({}, options, { unit: "million", numDecimalPlaces: 2 }))
} else {
const targetDigits = Math.pow(10, -numDecimalPlaces)
if (value !== 0 && Math.abs(value) < targetDigits) {
if (value < 0)
output = `>-${targetDigits}`
else
output = `<${targetDigits}`
} else {
const rounded = precisionRound(value, numDecimalPlaces)
output = format(`,`)(rounded)
}
if (noTrailingZeroes) {
// Convert e.g. 2.200 to 2.2
const m = output.match(/(.*?[0-9,-]+.[0-9,]*?)0*$/)
if (m) output = m[1]
if (output[output.length - 1] === ".")
output = output.slice(0, output.length - 1)
}
}
if (unit === "$" || unit === "ÂŁ")
output = unit + output
else if (isNoSpaceUnit) {
output = output + unit
} else if (unit.length > 0) {
output = output + " " + unit
}
return output
}
示例9: if
const parameters = _.map(this.params, (value, index) => {
let paramType;
if (index < this.def.params.length) {
paramType = this.def.params[index].type;
} else if (_.get(_.last(this.def.params), 'multiple')) {
paramType = _.get(_.last(this.def.params), 'type');
}
// param types that should never be quoted
if (_.includes(['value_or_series', 'boolean', 'int', 'float', 'node'], paramType)) {
return value;
}
// param types that might be quoted
if (_.includes(['int_or_interval', 'node_or_tag'], paramType) && _.isFinite(+value)) {
return _.toString(+value);
}
return "'" + value + "'";
});
示例10: Error
_.each(args, (arg, i) => {
const isNumber = _.isFinite(arg);
if (isNumber) {
argTypes.push(SolidityTypes.uint8);
} else if (_.isObject(arg) && (arg as BigNumber.BigNumber).isBigNumber) {
argTypes.push(SolidityTypes.uint256);
args[i] = new BN(arg.toString(), 10);
} else if (ethUtil.isValidAddress(arg)) {
argTypes.push(SolidityTypes.address);
} else if (_.isString(arg)) {
argTypes.push(SolidityTypes.string);
} else if (_.isBoolean(arg)) {
argTypes.push(SolidityTypes.bool);
} else {
throw new Error(`Unable to guess arg type: ${arg}`);
}
});