MCPcopy
hub / github.com/QwikDev/qwik / readLines

Function readLines

scripts/docs_sync/util.ts:31–59  ·  view source on GitHub ↗
(file: string)

Source from the content-addressed store, hash-verified

29const hackMdCache = new Map<string, Promise<string[]>>();
30
31export async function readLines(file: string): Promise<string[]> {
32 file = file.replace('https:/', 'https://').replace('https:///', 'https://');
33 let promise = hackMdCache.get(file);
34 if (promise) return promise;
35
36 const index = file.indexOf('https://hackmd.io/');
37 if (index === -1) {
38 promise = new Promise((res, rej) =>
39 readFile(file, (err, data) => (err ? rej(err) : res(String(data).split('\n'))))
40 );
41 } else {
42 const url = file.substring(index) + '/download';
43 console.log('FETCHING:', url);
44 promise = new Promise<string[]>((resolve, rej) => {
45 get(url, (res) => {
46 res.setEncoding('utf8');
47 let body = '';
48 res.on('data', (data) => {
49 body += String(data);
50 });
51 res.on('end', () => {
52 resolve(body.split('\n'));
53 });
54 });
55 });
56 }
57 hackMdCache.set(file, promise);
58 return promise;
59}
60
61export async function writeFileLines(file: string, lines: string[]) {
62 return new Promise((res, rej) =>

Callers 5

mainFunction · 0.90
readFetchFunction · 0.90
mainFunction · 0.90
readFileSectionFunction · 0.90
resolveCodeExampleFunction · 0.90

Calls 6

readFileFunction · 0.85
onMethod · 0.80
getMethod · 0.65
setMethod · 0.65
getFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…