Skip to content

Commit 59ae2fd

Browse files
committed
address review feedback
- Add JSDoc to parseUrlParams - Remove export from p5VersionStrings and copy its logic to test file - Fix invalid version test to use 'invalid-version' instead of '9.9.9'
1 parent 204b6fe commit 59ae2fd

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

client/utils/parseURLParams.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { parseUrlParams, p5VersionStrings } from './parseURLParams';
2-
import { currentP5Version } from '../../common/p5Versions';
1+
import { parseUrlParams } from './parseURLParams';
2+
import { p5Versions, currentP5Version } from '../../common/p5Versions';
3+
4+
function getVersionString(
5+
item: string | { version: string; label: string }
6+
): string {
7+
return typeof item === 'string' ? item : item.version;
8+
}
9+
10+
const p5VersionStrings = p5Versions.map(getVersionString);
311

412
describe('parseUrlParams', () => {
513
describe('default behavior', () => {
@@ -39,7 +47,7 @@ describe('parseUrlParams', () => {
3947
const good = parseUrlParams('https://example.com?version=1.4.0');
4048
expect(good.version).toBe('1.4.0');
4149

42-
const bad = parseUrlParams('https://example.com?version=9.9.9');
50+
const bad = parseUrlParams('https://example.com?version=invalid-version');
4351
expect(bad.version).toBe(currentP5Version);
4452
});
4553

client/utils/parseURLParams.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function getVersionString(
2121
return typeof item === 'string' ? item : item.version;
2222
}
2323

24-
export const p5VersionStrings = p5Versions.map(getVersionString);
24+
const p5VersionStrings = p5Versions.map(getVersionString);
2525

2626
function getNewestVersion(versions: string[]): string {
2727
return versions.sort((a, b) => {
@@ -83,6 +83,12 @@ function validateBool(value: string | null, defaultValue: boolean): boolean {
8383
return defaultValue;
8484
}
8585

86+
/**
87+
* Parses URL parameters for version and boolean flags.
88+
*
89+
* @param url - The URL string to parse.
90+
* @returns Parsed and validated URL parameters including version and library flags.
91+
*/
8692
export function parseUrlParams(url: string): ParsedUrlParams {
8793
const params = new URLSearchParams(
8894
new URL(url, 'https://dummy.origin').search

0 commit comments

Comments
 (0)