UNPKG

@megalo/api

Version:

重新封装各个端中的API,由 megalo 统一对外抛出方法名。目前微信小程序端提供的 API 最为丰富,所以 API 名称以微信小程序为准。

39 lines (35 loc) 852 B
import adaptApi from './adaptedFactory'; import { getEnv, ENV_TYPE } from './env'; import { isNative } from '../../utils/index'; import { sharedNoPromiseApis, sharedNeedPromiseApis, } from './nativeApis'; const hasProxy = typeof Proxy !== 'undefined' && isNative(Proxy); function buf2hex(buffer) { const hexArr = Array.prototype.map.call( new Uint8Array(buffer), function (bit) { return ('00' + bit.toString(16)).slice(-2); } ); return hexArr.join(''); } function hex2buf(hex) { let view = new Uint8Array(hex.length / 2); for (let i = 0; i < hex.length; i += 2) { view[i / 2] = parseInt(hex.substring(i, i + 2), 16); } return view.buffer; } export { buf2hex, hex2buf, hasProxy, adaptApi, getEnv, ENV_TYPE, sharedNoPromiseApis, sharedNeedPromiseApis, };