Skip to content

Commit

Permalink
doc: add isValidASCIIURL and toPunycodeURL jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwand committed Jan 10, 2025
1 parent e4823ae commit 0a08f1e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/pages/confirmations/utils/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export const isPermitSignatureRequest = (request?: Confirmation) => {
return PRIMARY_TYPES_PERMIT.includes(primaryType);
};

export const isValidASCIIURL = (urlString?: string) => {
/**
* @param urlString - The URL to check
* @returns True if the URL hostname contains only ASCII characters, false otherwise. The URL is still valid if the path contains non-ASCII characters.
*/
export const isValidASCIIURL = (urlString?: string): boolean => {
try {
return urlString?.includes(new URL(urlString).host);

Check failure on line 78 in ui/pages/confirmations/utils/confirm.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Type 'boolean | undefined' is not assignable to type 'boolean'.
} catch (exp: unknown) {
Expand All @@ -80,7 +84,13 @@ export const isValidASCIIURL = (urlString?: string) => {
}
};

export const toPunycodeURL = (urlString: string) => {
/**
* Converts the URL to Punycode
*
* @param urlString - The URL to convert
* @returns The Punycode URL
*/
export const toPunycodeURL = (urlString: string): string | undefined => {
try {
const url = new URL(urlString);
const isWithoutEndSlash = url.pathname === '/' && !urlString.endsWith('/');
Expand Down

0 comments on commit 0a08f1e

Please sign in to comment.