swtc-chains
Version:
swtc chain information
95 lines • 2.63 kB
JavaScript
import { ZERO, CHAINS } from "./constants";
export function funcGetChain(chain_or_token) {
const chains = CHAINS.filter(chain => chain.code.toLowerCase() === chain_or_token.toLowerCase() ||
chain.currency.toUpperCase() === chain_or_token.toUpperCase());
return chains.length === 1 ? chains[0] : undefined;
}
export function funcSeqEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
}
return true;
}
function isSequence(val) {
return val.length !== undefined;
}
export function funcConcatArgs(...args) {
const ret = [];
args.forEach(arg => {
if (isSequence(arg)) {
for (const e of arg) {
ret.push(e);
}
}
else {
ret.push(arg);
}
});
return ret;
}
export function funcHexToBytes(hex) {
const bytes = [];
for (let c = 0; c < hex.length; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return bytes;
}
export function funcBytesToHex(bytes) {
const hex = [];
for (const byte of bytes) {
const current = byte < 0 ? byte + 256 : byte;
hex.push((current >>> 4).toString(16));
hex.push((current & 0xf).toString(16));
}
return hex.join("").toUpperCase();
}
export function funcHexToString(h) {
const a = [];
let i = 0;
if (h.length % 2) {
a.push(String.fromCharCode(parseInt(h.substring(0, 1), 16)));
i = 1;
}
for (; i < h.length; i += 2) {
a.push(String.fromCharCode(parseInt(h.substring(i, i + 2), 16)));
}
return a.join("");
}
export function funcStringToHex(s) {
let result = "";
for (const e of s) {
const b = e.charCodeAt(0);
result += b < 16 ? "0" + b.toString(16) : b.toString(16);
}
return result;
}
export function funcString2Hex(s) {
let result = funcStringToHex(s);
if (result.length < 64) {
result += ZERO.substr(result.length);
}
return result;
}
export function funcNumber2Hex(n) {
n = n.toString(16);
return ZERO.substr(0, 64 - n.length) + n;
}
export function funcHex2Number(h) {
return parseInt(h, 16);
}
export function funcIsEmpty(value) {
const type = typeof value;
if ((value !== null && type === "object") || type === "function") {
const properties = Object.keys(value);
if (properties.length === 0 || properties.size === 0) {
return true;
}
}
return !value;
}
//# sourceMappingURL=functions.js.map