charms-js
Version:
TypeScript SDK for decoding Bitcoin transactions containing Charms data
33 lines (32 loc) • 868 B
JavaScript
export var AppType;
(function (AppType) {
AppType["NFT"] = "nft";
AppType["TOKEN"] = "token";
AppType["UNKNOWN"] = "unknown";
})(AppType || (AppType = {}));
// Determines app type from app string
export function getAppType(appString) {
if (!appString || typeof appString !== 'string') {
return AppType.UNKNOWN;
}
if (appString.startsWith('n/')) {
return AppType.NFT;
}
else if (appString.startsWith('t/')) {
return AppType.TOKEN;
}
else {
return AppType.UNKNOWN;
}
}
// Extracts app ID from app string format "n/[app_id]/..." or "t/[app_id]/..."
export function extractAppId(appString) {
if (!appString || typeof appString !== 'string') {
return '';
}
const parts = appString.split('/');
if (parts.length >= 2) {
return parts[1];
}
return appString;
}