当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.isInteger函数代码示例

本文整理汇总了TypeScript中lodash.isInteger函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isInteger函数的具体用法?TypeScript isInteger怎么用?TypeScript isInteger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isInteger函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

const estimateTransactionSize = function(params) {
  if (!_.isInteger(params.nP2shInputs) || params.nP2shInputs < 0) {
    throw new Error('expecting positive nP2shInputs');
  }
  if (!_.isInteger(params.nP2pkhInputs) || params.nP2pkhInputs < 0) {
    throw new Error('expecting positive nP2pkhInputs to be numeric');
  }
  if (!_.isInteger(params.nP2shP2wshInputs) || params.nP2shP2wshInputs < 0) {
    throw new Error('expecting positive nP2shP2wshInputs to be numeric');
  }
  if ((params.nP2shInputs + params.nP2shP2wshInputs) < 1) {
    throw new Error('expecting at least one nP2shInputs or nP2shP2wshInputs');
  }
  if (!_.isInteger(params.nOutputs) || params.nOutputs < 1) {
    throw new Error('expecting positive nOutputs');
  }


  const estimatedSize = VirtualSizes.txP2shInputSize * params.nP2shInputs +
  VirtualSizes.txP2shP2wshInputSize * (params.nP2shP2wshInputs || 0) +
  VirtualSizes.txP2pkhInputSizeUncompressedKey * (params.nP2pkhInputs || 0) +
  VirtualSizes.txP2pkhOutputSize * params.nOutputs +
  // if the tx contains at least one segwit input, the tx overhead is increased by 1
  VirtualSizes.txOverheadSize + (params.nP2shP2wshInputs > 0 ? 1 : 0);

  return estimatedSize;
};
开发者ID:BitGo,项目名称:BitGoJS,代码行数:27,代码来源:transactionBuilder.ts

示例2: generateAddress

  /**
   * Generate an address for a wallet based on a set of configurations
   * @param keychains Array of objects with xpubs
   * @param threshold Minimum number of signatures
   * @param chain Derivation chain
   * @param index Derivation index
   * @returns {{chain: number, index: number, coin: number, coinSpecific: {outputScript}}}
   */
  generateAddress({ keychains, threshold, chain, index }) {
    let signatureThreshold = 2;
    if (_.isInteger(threshold)) {
      signatureThreshold = threshold;
      if (signatureThreshold <= 0) {
        throw new Error('threshold has to be positive');
      }
      if (signatureThreshold > keychains.length) {
        throw new Error('threshold cannot exceed number of keys');
      }
    }

    let derivationChain = 0;
    if (_.isInteger(chain) && chain > 0) {
      derivationChain = chain;
    }

    let derivationIndex = 0;
    if (_.isInteger(index) && index > 0) {
      derivationIndex = index;
    }

    const path = 'm/0/0/' + derivationChain + '/' + derivationIndex;
    // do not modify the original argument
    const keychainCopy = _.cloneDeep(keychains);
    const userKey = keychainCopy.shift();
    const aspKeyIds = keychainCopy.map((key) => key.aspKeyId);
    const derivedUserKey = prova.HDNode.fromBase58(userKey.pub).hdPath().deriveKey(path).getPublicKeyBuffer();

    const provaAddress = new prova.Address(derivedUserKey, aspKeyIds, this.network);
    provaAddress.signatureCount = signatureThreshold;

    const addressDetails: any = {
      chain: derivationChain,
      index: derivationIndex,
      coin: this.getChain(),
      coinSpecific: {
        outputScript: provaAddress.toScript().toString('hex')
      }
    };

    try {
      addressDetails.address = provaAddress.toString();
    } catch (e) {
      // non-(n-1)/n signature count
      addressDetails.address = null;
    }

    return addressDetails;
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:58,代码来源:rmg.ts

示例3: ulog2

export function ulog2(n: number): number {
  if (n === 0 ) return 0;
  const x = n < 0 ? Math.abs(n) : n;
  const xprime = Math.log2(x);
  const xprimeprime = isInteger(n) ? Math.floor(xprime) : xprime;
  return n < 0 ? -xprimeprime : xprimeprime;
}
开发者ID:hychen,项目名称:hycheck,代码行数:7,代码来源:utils.ts

示例4: normalizeAddress

 /**
  * Construct a full, normalized address from an address and destination tag
  */
 public normalizeAddress({ address, destinationTag }): string {
   if (!_.isString(address)) {
     throw new InvalidAddressError('invalid address details');
   }
   if (_.isInteger(destinationTag)) {
     return `${address}?dt=${destinationTag}`;
   }
   return address;
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:12,代码来源:xrp.ts

示例5: function

Blockchain.prototype.getTransactionByInput = function(params, callback) {
  params = params || {};
  common.validateParams(params, ['txid'], [], callback);
  if (!_.isInteger(params.vout)) {
    throw new Error('invalid vout - number expected');
  }
  return this.bitgo.get(this.bitgo.url('/tx/input/' + params.txid + '/' + params.vout))
  .result()
  .nodeify(callback);
};
开发者ID:BitGo,项目名称:BitGoJS,代码行数:10,代码来源:blockchain.ts

示例6: co

    return co(function *getRecoveryFeePerBytes() {
      const recoveryFeeUrl = this.getRecoveryFeeRecommendationApiBaseUrl();

      const publicFeeDataReq = this.bitgo.get(recoveryFeeUrl);
      publicFeeDataReq.forceV1Auth = true;
      const publicFeeData = yield publicFeeDataReq.result();

      if (_.isInteger(publicFeeData.hourFee)) {
        return publicFeeData.hourFee;
      } else {
        return 100;
      }
    }).call(this);
开发者ID:BitGo,项目名称:BitGoJS,代码行数:13,代码来源:btc.ts

示例7: constructor

    constructor(opts: i.ClientOptions) {
        super(opts);
        const {
            hostUrl,
            clientId,
            clientType,
            serverName,
            socketOptions= {},
            connectTimeout,
        } = opts;

        if (!isString(hostUrl)) {
            throw new Error('Messenger.Client requires a valid hostUrl');
        }

        if (!isString(clientId)) {
            throw new Error('Messenger.Client requires a valid clientId');
        }

        if (!isString(clientType)) {
            throw new Error('Messenger.Client requires a valid clientType');
        }

        if (!isString(serverName)) {
            throw new Error('Messenger.Client requires a valid serverName');
        }

        if (!isInteger(connectTimeout)) {
            throw new Error('Messenger.Client requires a valid connectTimeout');
        }

        const options: SocketIOClient.ConnectOpts = Object.assign({}, socketOptions, {
            autoConnect: false,
            forceNew: true,
            perMessageDeflate: false,
            query: { clientId, clientType },
            timeout: connectTimeout
        });

        // @ts-ignore
        this.socket = new SocketIOClient(hostUrl, options);

        this.hostUrl = hostUrl;
        this.connectTimeout = connectTimeout;
        this.clientId = clientId;
        this.clientType = clientType;
        this.serverName = serverName;
        this.available = false;
        this.ready = false;
        this.serverShutdown = false;
    }
开发者ID:jeffmontagna,项目名称:teraslice,代码行数:51,代码来源:client.ts

示例8: function

gameSchema.path('game_type').validate(async function() {

	const ipdb = this.ipdb ? this.ipdb.number : null;

	// only check if not an original game.
	if (this.game_type !== 'og' && (!ipdb || (!isInteger(ipdb) && !(isString(ipdb) && validator.isInt(ipdb))))) {
		this.invalidate('ipdb.number', 'IPDB Number is mandatory for recreations and must be a positive integer.');
		return true;
	}

	if (this.game_type !== 'og' && this.isNew) {
		const game = await state.models.Game.findOne({ 'ipdb.number': ipdb }).exec();
		if (game) {
			this.invalidate('ipdb.number', 'The game "' + game.title + '" is already in the database and cannot be added twice.');
		}
		return true;
	}
	return true;
});
开发者ID:freezy,项目名称:node-vpdb,代码行数:19,代码来源:game.schema.ts

示例9: catch

 recipients.forEach(function(recipient) {
   if (_.isString(recipient.address)) {
     try {
       bitcoin.address.fromBase58Check(recipient.address);
     } catch (e) {
       throw new Error('invalid bitcoin address: ' + recipient.address);
     }
     if (!!recipient.script) {
       // A script was provided as well - validate that the address corresponds to that
       if (bitcoin.address.toOutputScript(recipient.address, bitcoin.getNetwork())
       .toString('hex') !== recipient.script) {
         throw new Error('both script and address provided but they did not match: ' + recipient.address + ' ' + recipient.script);
       }
     }
   }
   if (!_.isInteger(recipient.amount) || recipient.amount < 0) {
     throw new Error('invalid amount for ' + recipient.address + ': ' + recipient.amount);
   }
   totalOutputAmount += recipient.amount;
 });
开发者ID:BitGo,项目名称:BitGoJS,代码行数:20,代码来源:transactionBuilder.ts


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