MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / parseMetadata

Function parseMetadata

src/pkg/utils/script.ts:24–46  ·  view source on GitHub ↗
(code: string)

Source from the content-addressed store, hash-verified

22
23// 从脚本代码抽出Metadata
24export function parseMetadata(code: string): SCMetadata | null {
25 let isSubscribe = false;
26 let headerContent: string;
27 let m: RegExpExecArray | null;
28 if ((m = HEADER_BLOCK.exec(code))) {
29 isSubscribe = m[1] === "Subscribe";
30 headerContent = m[2];
31 } else {
32 return null;
33 }
34 const metadata: SCMetadata = {} as SCMetadata;
35 META_LINE.lastIndex = 0; // 重置正则表达式的lastIndex(用于复用)
36 while ((m = META_LINE.exec(headerContent)) !== null) {
37 const key = m[1].toLowerCase();
38 const val = m[2]?.trim() ?? "";
39 const values = metadata[key] || (metadata[key] = []);
40 values.push(val);
41 }
42 if (!metadata.name || Object.keys(metadata).length < 3) return null;
43 if (!metadata.namespace) metadata.namespace = [""];
44 if (isSubscribe) metadata.usersubscribe = []; // 如果是 user.sub.js, 在 metadata 会有一个额外的 usersubscribe
45 return metadata;
46}
47
48// 从网址取得脚本代码
49export async function fetchScriptBody(url: string, signal?: AbortSignal): Promise<string> {

Callers 10

onDropFunction · 0.90
fetchScriptBodyFunction · 0.90
initAsyncFunction · 0.90
script.test.tsFile · 0.90
_checkUpdateAvailableMethod · 0.90
_checkUpdateAvailableMethod · 0.90
parseScriptFromCodeFunction · 0.85
prepareScriptByCodeFunction · 0.85
prepareSubscribeByCodeFunction · 0.85

Calls 2

pushMethod · 0.80
keysMethod · 0.80

Tested by

no test coverage detected