Skip to content

Commit

Permalink
Add a locationDomain utility function.
Browse files Browse the repository at this point in the history
Part of #45.
  • Loading branch information
jkomoros committed Jul 22, 2023
1 parent d361251 commit 318dc68
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import {

export const PACKED_SEED_REFERENCE_DELIMITER = '#';

//e.g. 'komoroske.com' or 'localhost'
export type URLDomain = string;

export const locationDomain = (location : SeedPacketAbsoluteLocation) : URLDomain => {
if (isLocalLocation(location)) return 'localhost';
const url = new URL(location);
return url.hostname;
};

export const isLocalLocation = (location : SeedPacketAbsoluteLocation) : boolean => {
if (location.startsWith('http://') || location.startsWith('https://')) return false;
return true;
Expand Down

0 comments on commit 318dc68

Please sign in to comment.