Files
solana/explorer/src/utils.ts

31 lines
751 B
TypeScript
Raw Normal View History

2020-03-16 15:17:51 +08:00
export function findGetParameter(parameterName: string): string | null {
let result = null,
tmp = [];
window.location.search
.substr(1)
.split("&")
.forEach(function(item) {
tmp = item.split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
});
return result;
}
2020-03-19 22:31:05 +08:00
export function findPathSegment(pathName: string): string | null {
const segments = window.location.pathname.substr(1).split("/");
if (segments.length < 2) return null;
// remove all but last two segments
segments.splice(0, segments.length - 2);
if (segments[0] === pathName) {
return segments[1];
}
return null;
}
2020-03-19 22:31:05 +08:00
export function assertUnreachable(x: never): never {
throw new Error("Unreachable!");
}