Files
xo-stack/packages/stack/src/utils/misc.ts
T

42 lines
1000 B
TypeScript

import { binToHex } from '@bitauth/libauth';
// TODO: Put unsorted stuff in here and then try to sort them somewhere more sensible later.
export function getOutpointId(outpoint: {
outpointTransactionHash: Uint8Array;
outpointIndex: number;
}): string {
const outpointHashHex = binToHex(outpoint.outpointTransactionHash);
return `${outpointHashHex}:${outpoint.outpointIndex}`;
}
// TODO: Jason uses form timestampMs_entityId
export function generateActivityId() {
return Date.now().toString();
}
/**
* Checks if a URL has duplicate parameters.
*
* @param url - The URL to check
* @returns True if the URL has duplicate parameters, false otherwise
*/
export function hasDuplicateParams(url: string | URL): boolean {
if (typeof url === 'string') {
url = new URL(url);
}
const params = url.searchParams;
const seen = new Set<string>();
for (const [key] of params.entries()) {
if (seen.has(key)) {
return true;
}
seen.add(key);
}
return false;
}