Skip to content

Commit 2139dc0

Browse files
committed
☕ Add JSDoc
1 parent f7e6529 commit 2139dc0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

scripts/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import * as streams from "https://deno.land/std@0.183.0/streams/mod.ts";
22

3+
/**
4+
* Downloads a text file and returns the contents.
5+
* Throws error if fetch fails.
6+
*/
37
export async function downloadString(url: string): Promise<string> {
48
const textDecoder = new TextDecoder();
59
const response = await fetch(url);
@@ -10,24 +14,32 @@ export async function downloadString(url: string): Promise<string> {
1014
return textDecoder.decode(await streams.readAll(reader));
1115
}
1216

17+
/**
18+
* Find the position of the first pattern match.
19+
* Search from the specified position, or from the beginning if not specified.
20+
* Returns -1 if the pattern not match.
21+
*/
1322
export function regexIndexOf(s: string, pattern: RegExp, offset = 0): number {
1423
const index = s.slice(offset).search(pattern);
1524
return index < 0 ? index : index + offset;
1625
}
1726

27+
/** Count the number of occurrences of a name. */
1828
export class Counter {
1929
#map: Map<string, number>;
2030

2131
constructor() {
2232
this.#map = new Map();
2333
}
2434

35+
/** Increments the count number of the name and returns it. */
2536
count(name: string): number {
2637
const value = this.get(name) + 1;
2738
this.#map.set(name, value);
2839
return value;
2940
}
3041

42+
/** Returns the count number of the name. */
3143
get(name: string): number {
3244
return this.#map.get(name) ?? 0;
3345
}

0 commit comments

Comments
 (0)