Skip to content

Commit

Permalink
Move URLDomain type to types.ts
Browse files Browse the repository at this point in the history
Part of #45.
  • Loading branch information
jkomoros committed Jul 22, 2023
1 parent 318dc68 commit 609d225
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import {
SeedPacketLocation,
SeedPacketRelativeLocation,
SeedReference,
URLDomain,
packedSeedReference,
seedPacketRelativeLocation
} from './types.js';

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);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ export const requiredSeedReference = z.object({

export type AbsoluteSeedReference = z.infer<typeof requiredSeedReference>;

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

//we want a regexp, and z.string().url() does not use a URL so just munge one
const urlRegExp = new RegExp('((http(s)?:\\/\\/)?(www\\.)?(([a-zA-Z\\d-]+\\.)+[a-zA-Z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-zA-Z\\d%_.~+]*)*(\\?[;&a-zA-Z\\d%_.~+=-]*)?(\\#[-a-zA-Z\\d_]*)?)');
const seedPacketAbsoluteLocationRegExp = new RegExp('(' + urlRegExp.source + ')|(' + absoluteLocalLocationRegExp.source + ')');
Expand Down

0 comments on commit 609d225

Please sign in to comment.