Skip to content

Commit 38986b9

Browse files
committed
migrate parseUrlParams to TypeScript (#3761)
1 parent 2f3cf9f commit 38986b9

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
import { p5Versions, currentP5Version } from '../../common/p5Versions';
22

3+
export interface ParsedUrlParams {
4+
version: string;
5+
sound: boolean;
6+
preload: boolean;
7+
shapes: boolean;
8+
data: boolean;
9+
}
10+
311
const DEFAULTS = {
412
sound: true,
513
preload: false,
614
shapes: false,
715
data: false
816
};
917

10-
function getVersionString(item) {
18+
function getVersionString(
19+
item: string | { version: string; label: string }
20+
): string {
1121
return typeof item === 'string' ? item : item.version;
1222
}
1323

14-
/**
15-
* Sorts version strings in descending order and returns the highest version
16-
* @param {string[]} versions - Array of version strings (e.g., ['1.11.2', '1.11.1'])
17-
* @returns {string} The highest version from the array
18-
*/
19-
function getNewestVersion(versions) {
24+
function getNewestVersion(versions: string[]): string {
2025
return versions.sort((a, b) => {
2126
const pa = a.split('.').map((n) => parseInt(n, 10));
2227
const pb = b.split('.').map((n) => parseInt(n, 10));
@@ -29,7 +34,7 @@ function getNewestVersion(versions) {
2934
})[0];
3035
}
3136

32-
function validateVersion(version) {
37+
function validateVersion(version: string | null): string {
3338
if (!version) return currentP5Version;
3439

3540
const ver = String(version).trim();
@@ -64,7 +69,7 @@ function validateVersion(version) {
6469
return currentP5Version;
6570
}
6671

67-
function validateBool(value, defaultValue) {
72+
function validateBool(value: string | null, defaultValue: boolean): boolean {
6873
if (!value) return defaultValue;
6974

7075
const v = String(value).trim().toLowerCase();
@@ -78,7 +83,7 @@ function validateBool(value, defaultValue) {
7883
return defaultValue;
7984
}
8085

81-
export function parseUrlParams(url) {
86+
export function parseUrlParams(url: string): ParsedUrlParams {
8287
const params = new URLSearchParams(
8388
new URL(url, 'https://dummy.origin').search
8489
);

0 commit comments

Comments
 (0)