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

TypeScript lodash.isFinite函数代码示例

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

本文整理汇总了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;
}
开发者ID:zthomae,项目名称:xanadu,代码行数:27,代码来源:parseGrid.ts


示例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;
}
开发者ID:zthomae,项目名称:xanadu,代码行数:26,代码来源:stats.ts


示例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]
    }
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:15,代码来源:Util.ts


示例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);
   }
 }
开发者ID:sogehige,项目名称:SogeBot,代码行数:35,代码来源:general.ts


示例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;
      }
    }
  });
开发者ID:zthomae,项目名称:xanadu,代码行数:56,代码来源:lobby.ts


示例6: evaluate

 private evaluate(val: string): any {
   let result;
   try {
     result = eval(val);
   } catch (e) {
     return 0;
   }
   if (!_.isFinite(result)) return 0;
   return result;
 }
开发者ID:bitjson,项目名称:copay,代码行数:10,代码来源:amount.ts


示例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;
	}
开发者ID:ajthinking,项目名称:react-diagrams,代码行数:11,代码来源:PortModel.ts


示例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
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:50,代码来源:Util.ts


示例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 + "'";
 });
开发者ID:gzq0616,项目名称:grafana,代码行数:17,代码来源:gfunc.ts


示例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}`);
     }
 });
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:17,代码来源:zero_ex.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript lodash.isFunction函数代码示例发布时间:2022-05-25
下一篇:
TypeScript lodash.isError函数代码示例发布时间: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