UNPKG

@tronlink/core

Version:

The library serves as a core module within TronLink Extension, which provides low-level wallet functionality for both Tron and Ethereum networks, primary features includes account generation and transaction signing

37 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serialize = serialize; exports.transformHeader = transformHeader; exports.promiseTimeout = promiseTimeout; exports.isAbsoluteURL = isAbsoluteURL; function serialize(obj) { const str = []; for (const p in obj) { if (Object.prototype.hasOwnProperty.call(obj, p)) { str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p])); } } return str.join('&'); } function transformHeader(headers) { const keys = Array.from(headers.keys()); return keys.reduce((prev, key) => { prev[key] = headers.get(key); return prev; }, {}); } function promiseTimeout(ms, promise) { // Create a promise that rejects in <ms> milliseconds const timeout = new Promise((resolve, reject) => { const id = setTimeout(() => { clearTimeout(id); reject('Timeout'); }, ms); }); // Returns a race between our timeout and the passed in promise return Promise.race([promise, timeout]); } function isAbsoluteURL(url) { return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url); } //# sourceMappingURL=utils.js.map