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
/**
* @title jsdoc-extractor
*/
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
import { parse } from "npm:comment-parser";
const commentRegex = /\/\*\*[\s\S]*?\*\//;
function extractJSDocfromText(text: string) {
const comments = text.match(commentRegex);
if (!comments) {
throw new Error("No comment found");
}
const comment = comments[0];
const doc = parse(comment);
return doc;
}
async function extractJSDocfromURL(url: string) {
const text = await fetchText(url);
return extractJSDocfromText(text);
}
async function extractJSDocfromVal(author: string, name: string, version: string = "latest") {
if (version === "latest") {
return extractJSDocfromURL(`https://esm.town/v/${author}/${name}`);
}
return extractJSDocfromURL(`https://esm.town/v/${author}/${name}?v=${version}`);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
April 24, 2024