86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
|
|
export function getImageUrl(url) {
|
|
return new URL(url, import.meta.url).href;
|
|
}
|
|
|
|
export function getPercentage(amount, goal) {
|
|
return ((Number(amount) / Number(goal)) * 100).toFixed(2);
|
|
}
|
|
|
|
|
|
export function compactNumber(number) {
|
|
return Intl.NumberFormat("en-US", {
|
|
notation: "compact",
|
|
maximumFractionDigits: 2,
|
|
}).format(parseInt(number));
|
|
}
|
|
|
|
|
|
export function formatNumber(number) {
|
|
const options = {
|
|
style: "decimal",
|
|
minimumFractionDigits: 0,
|
|
maximumFractionDigits: 0,
|
|
};
|
|
if (!number) {
|
|
return 0
|
|
}
|
|
const formattedWithOptions = number.toLocaleString("en-US", options);
|
|
return formattedWithOptions;
|
|
}
|
|
|
|
// input type bigint
|
|
export function formatBigIntDivision(nominator, denominator) {
|
|
const integer = (nominator / denominator).toString();
|
|
// pick how much digits after point to show
|
|
const fraction = (nominator % denominator).toString().substring(0,10);
|
|
// output type string
|
|
return integer + '.' + fraction;
|
|
}
|
|
|
|
export function getAddressShortName(address) {
|
|
// const address = "0x66422602B2f4885c57EE794174f98d9E4DDBBBC6";
|
|
const addressBegin = address.substring(0, 6);
|
|
const addressEnd = address.substring(address.length - 4, address.length)
|
|
return addressBegin + "..." + addressEnd;
|
|
}
|
|
|
|
|
|
export function numberWithCommas(x, ) {
|
|
x = x.toString();
|
|
var pattern = /(-?\d+)(\d{3})/;
|
|
while (pattern.test(x)) x = x.replace(pattern, "$1,$2");
|
|
return x;
|
|
}
|
|
|
|
export function getblocky(address) {
|
|
var blockiesData = blockies
|
|
.create({
|
|
seed: address.toLowerCase(),
|
|
size: 8,
|
|
scale: 4,
|
|
})
|
|
.toDataURL();
|
|
|
|
return blockiesData;
|
|
}
|
|
|
|
export function debounce(func, timeout = 300) {
|
|
let timer;
|
|
return (...args) => {
|
|
clearTimeout(timer);
|
|
timer = setTimeout(() => {
|
|
return func.apply(this, args);
|
|
}, timeout);
|
|
};
|
|
}
|
|
|
|
export function createDebounce() {
|
|
let timeout = null;
|
|
return function (fnc, delayMs) {
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(() => {
|
|
fnc();
|
|
}, delayMs || 500);
|
|
};
|
|
} |