import { HttpHeaders } from '@dripjs/types' ; import { endpoints } from '../rest/types' ; import { Config , RateLimit } from '../types' ; export function getRateLimit ( headers ) { return { remaining : Number ( headers [ 'x-ratelimit-remaining' ] ) , reset : Number ( headers [ 'x-ratelimit-reset' ] ) , limit : Number ( headers [ 'x-ratelimit-limit' ] ) , } ; } param params export function getChannelName ( params ) { let subStr = `${ params . endPoint }` ; if ( params . pair ) { if ( params . pair instanceof Array ) { const channels = [ ] ; for ( const p of params . pair ) { channels . push ( `${ params . endPoint }:${ p }` ) ; } return channels ; } subStr = `${ params . endPoint }:${ params . pair }` ; } return subStr ; } param cfg export function getRestApiUrl ( cfg ) { if ( cfg . apiUrl ) { return cfg . apiUrl ; } if ( cfg . testnet ) { return endpoints . testnet ; } return endpoints . production ; } /**
 * 判断是否为node.js环境
 */ export function isNodeJs ( ) { return typeof process === 'object' && typeof process . versions === 'object' && typeof process . versions . node !== 'undefined' ; }