Skip to content

Commit 9c114c3

Browse files
authored
chore: fix type exports (#167)
1 parent 3a9ec38 commit 9c114c3

File tree

2 files changed

+12
-39
lines changed

2 files changed

+12
-39
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
deno-version: vx.x.x
1616
- name: Typecheck
1717
run: deno check src/
18+
- run: deno publish --dry-run
1819
- name: Unit Test
1920
run: deno test src/
2021
- name: e2e Test

src/utils.ts

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,11 @@ export function roundIfNumeric<T extends string | number | undefined>(
2929
// deno-lint-ignore no-explicit-any
3030
return Math.round(num) as any;
3131
}
32-
export const setParamIfDefined = (
33-
url: URL,
34-
key: string,
35-
value?: string | number,
36-
deleteExisting?: boolean,
37-
roundValue?: boolean,
38-
) => {
39-
if (value) {
40-
if (roundValue) {
41-
value = roundIfNumeric(value);
42-
}
43-
url.searchParams.set(key, value.toString());
44-
} else if (deleteExisting) {
45-
url.searchParams.delete(key);
46-
}
47-
};
48-
49-
export const setParamIfUndefined = (
50-
url: URL,
51-
key: string,
52-
value: string | number,
53-
) => {
54-
if (!url.searchParams.has(key)) {
55-
url.searchParams.set(key, value.toString());
56-
}
57-
};
58-
59-
export const getNumericParam = (url: URL, key: string) => {
60-
const value = Number(url.searchParams.get(key));
61-
return isNaN(value) ? undefined : value;
62-
};
6332

6433
/**
6534
* Given a URL object, returns path and query params
6635
*/
67-
export const toRelativeUrl = (url: URL) => {
36+
export const toRelativeUrl = (url: URL): string => {
6837
const { pathname, search } = url;
6938
return `${pathname}${search}`;
7039
};
@@ -73,34 +42,37 @@ export const toRelativeUrl = (url: URL) => {
7342
* Returns a URL string that may be relative or absolute
7443
*/
7544

76-
export const toCanonicalUrlString = (url: URL) => {
45+
export const toCanonicalUrlString = (url: URL): string => {
7746
return url.hostname === "n" ? toRelativeUrl(url) : url.toString();
7847
};
7948

8049
/**
8150
* Normalises a URL object or string URL to a URL object.
8251
*/
83-
export const toUrl = (url: string | URL, base?: string | URL | undefined) => {
52+
export const toUrl = (
53+
url: string | URL,
54+
base?: string | URL | undefined,
55+
): URL => {
8456
return typeof url === "string" ? new URL(url, base ?? "http://n/") : url;
8557
};
8658

8759
/**
8860
* Escapes a string, even if it's URL-safe
8961
*/
90-
export const escapeChar = (text: string) =>
62+
export const escapeChar = (text: string): string =>
9163
text === " " ? "+" : ("%" +
9264
text.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
9365

94-
export const stripLeadingSlash = (str?: string) =>
66+
export const stripLeadingSlash = (str?: string): string | undefined =>
9567
str?.startsWith("/") ? str.slice(1) : str;
9668

97-
export const stripTrailingSlash = (str?: string) =>
69+
export const stripTrailingSlash = (str?: string): string | undefined =>
9870
str?.endsWith("/") ? str.slice(0, -1) : str;
9971

100-
export const addLeadingSlash = (str?: string) =>
72+
export const addLeadingSlash = (str?: string): string =>
10173
str?.startsWith("/") ? str : `/${str}`;
10274

103-
export const addTrailingSlash = (str?: string) =>
75+
export const addTrailingSlash = (str?: string): string =>
10476
str?.endsWith("/") ? str : `${str}/`;
10577

10678
/**

0 commit comments

Comments
 (0)