TypeScript web3 isAddress示例

说明

typescript web3 isaddress示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: TypeScript

命名空间/包名称: web3

示例#1
文件: assert.ts 项目: linki/0x.js

     const isBigNumber = _.isObject(value) && value.isBigNumber;
     this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
 },
 isUndefined(value: any, variableName?: string): void {
     this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value));
 },
 isString(variableName: string, value: string): void {
     this.assert(_.isString(value), this.typeAssertionMessage(variableName, 'string', value));
 },
 isHexString(variableName: string, value: string): void {
     this.assert(_.isString(value) && HEX_REGEX.test(value),
         this.typeAssertionMessage(variableName, 'HexString', value));
 },
 isETHAddressHex(variableName: string, value: string): void {
     const web3 = new Web3();
     this.assert(web3.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
     this.assert(
         web3.isAddress(value) && !web3.isChecksumAddress(value),
         `Checksummed addresses are not supported. Convert ${variableName} to lower case before passing`,
     );
 },
 doesBelongToStringEnum(variableName: string, value: string,
                        stringEnum: any /* There is no base type for every string enum */): void {
     const doesBelongToStringEnum = !_.isUndefined(stringEnum[value]);
     const enumValues = _.keys(stringEnum);
     const enumValuesAsStrings = _.map(enumValues, enumValue => `'${enumValue}'`);
     const enumValuesAsString = enumValuesAsStrings.join(', ');
     assert.assert(
         doesBelongToStringEnum,
         `Expected ${variableName} to be one of: ${enumValuesAsString}, encountered: ${value}`,
     );

示例#2
文件: web3_wrapper.ts 项目: linki/0x.js

 public isAddress(address: string): boolean {
     return this.web3.isAddress(address);
 }

展开阅读全文