vladimyr-jsr2gh.web.val.run
Readme

jsr2gh

Redirect to jsr package's GitHub repository page, like vladimyr-jsr2gh.web.val.run/@luca/flag

Usage

https://vladimyr-jsr2gh.web.val.run/<scope>/<name>

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-License-Identifier: 0BSD
import { serveReadme } from "https://esm.town/v/vladimyr/serveReadme";
import { toHonoHandler } from "https://esm.town/v/vladimyr/toHonoHandler";
import { Hono } from "jsr:@kyiro/hono";
import ky from "npm:ky";
import * as v from "npm:valibot";
const PackageDataSchema = v.object({
githubRepository: v.nullable(v.object({
owner: v.string(),
name: v.string(),
})),
});
const app = new Hono();
app.get("/", toHonoHandler(serveReadme(import.meta.url)));
app.get("/:scope{@[^/]+}/:name", async (c) => {
const scope = c.req.param("scope").slice(1);
const name = c.req.param("name");
const { githubRepository: repo } = await fetchPackageData(scope, name);
if (repo) {
const githubURL = new URL(`https://github.com/${repo.owner}/${repo.name}`);
return c.redirect(githubURL);
}
const jsrURL = new URL(`https://jsr.io/@${scope}/${name}`);
return c.redirect(jsrURL);
});
export default app.fetch;
export async function fetchPackageData(scope: string, name: string) {
const prefixUrl = "https://api.jsr.io/";
const data = await ky.get(`scopes/${scope}/packages/${name}`, { prefixUrl }).json();
return v.parse(PackageDataSchema, data);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
3
stevekrouse avatar

Nice! Just saying ;)

Screenshot 2024-03-06 at 08.11.13.png

vladimyr avatar

I'm cheap I like to promote val.town :P

stevekrouse avatar
March 6, 2024