Skip to content

Commit 64565a4

Browse files
committed
feat: replace custom function with ufo's withTrailingSlash
The custom function for adding a trailing slash to a string has been replaced with the withTrailingSlash function from the 'ufo' library. This change simplifies the code and reduces redundancy.
1 parent 02c38d1 commit 64565a4

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

deno.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"pathe": "npm:pathe@^1.1.2",
2626
"query-string": "npm:query-string@^9.1.0",
2727
"svelte": "npm:svelte@^4.2.18",
28+
"ufo": "npm:ufo@^1.5.4",
2829
"unconfig": "npm:unconfig@^0.5.5",
2930
"vite": "npm:vite@^5.3.5"
3031
},

deno.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mod.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { PreprocessorGroup } from "svelte/compiler";
88
import type { Config as SvelteKitConfig } from "@sveltejs/kit";
99
import type { UserConfig as ViteConfig } from "vite";
1010
import { loadConfig } from "unconfig";
11+
import { withTrailingSlash } from "ufo";
1112

1213
async function loadAliases() {
1314
const { config } = await loadConfig({
@@ -50,10 +51,9 @@ async function getAbsPath(
5051
}
5152

5253
for (const [alias, aliasPath] of Object.entries(aliases)) {
53-
const addSlash = (str: string) => (str.endsWith("/") ? str : `${str}/`);
54-
if (file.startsWith(addSlash(alias)) || file === alias) {
54+
if (file.startsWith(withTrailingSlash(alias)) || file === alias) {
5555
const s = new MagicString(file);
56-
s.overwrite(0, alias.length, addSlash(aliasPath));
56+
s.overwrite(0, alias.length, withTrailingSlash(aliasPath));
5757
return path.resolve(s.toString());
5858
}
5959
}

0 commit comments

Comments
 (0)