diff --git a/package.json b/package.json index b7db4e4..4ee52dd 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "author": "Jörn-Michael Miehe ", "license": "MIT", "scripts": { - "build": "webpack --mode=development", - "build-release": "webpack --mode=production", + "build-debug": "webpack --mode=development", + "build": "webpack --mode=production", "lint-ext": "web-ext lint --source-dir=dist", "build-ext": "web-ext build --source-dir=dist --artifacts-dir=dist --overwrite-dest" }, diff --git a/src/bttv_api.ts b/src/bttv_api.ts index 0ee9133..415eb32 100644 --- a/src/bttv_api.ts +++ b/src/bttv_api.ts @@ -13,12 +13,9 @@ type BTTV_Emote = { * Query BTTV API for an emote graphic * * @param code string associated with the emote graphic (often called "emote" itself) - * @returns `null` iff no emote found or error, - * else `[code, url]` tuple where `url` is the URL to a BTTV emote graphic + * @returns `null` iff no emote found or error, else URL to a BTTV emote graphic */ -export async function bttv_get_url( - code: string, -): Promise<[string, string] | null> { +export async function bttv_get_url(code: string): Promise { // search for emotes const res = await fetch( `https://api.betterttv.net/3/emotes/shared/search?query=${code}&offset=0&limit=50`, @@ -37,8 +34,5 @@ export async function bttv_get_url( if (matches.length <= 0) return null; // return first emote's URL - return [ - code, - `//cdn.betterttv.net/emote/${matches[0].id}/1x.${matches[0].imageType}`, - ]; + return `//cdn.betterttv.net/emote/${matches[0].id}/1x.${matches[0].imageType}`; } diff --git a/src/helpers.ts b/src/helpers.ts index 7c8203b..af652cf 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,8 +1,3 @@ -/** - * Async function mapping some `input` to an `[input, output]` tuple or a `null` if no output exists - */ -type MapFunction = (input: In) => Promise<[In, Out] | null>; - /** * Concurrently create some mapping of input to output elements. * @@ -12,13 +7,13 @@ type MapFunction = (input: In) => Promise<[In, Out] | null>; */ export async function map_concurrent( inputs: Iterable, - map_fn: MapFunction, -): Promise> { + map_fn: (input: In) => Promise, +): Promise> { // apply map_fn to inputs - const queue = [...inputs].map((input) => map_fn(input)); + const outputs = await Promise.all([...inputs].map((input) => map_fn(input))); - // wait for calls to finish - return new Map( - (await Promise.all(queue)).filter((job): job is [In, Out] => job !== null), + // create map object + return new Map( + [...inputs].map((input, index) => [input, outputs[index]]), ); } diff --git a/src/main.ts b/src/main.ts index 7d68f95..4583853 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,13 +24,13 @@ async function process_text(text: string): Promise { for (const emote of matches.reverse()) { const [match, code] = emote; - if (!emotes.has(code)) continue; - // emote exists + // ensure emote exists const url = emotes.get(code); + if (url == null) continue; - if (emote.index == undefined) continue; - // position in input string is known + // ensure position in input string is known const index = emote.index; + if (index == undefined) continue; text = text.substring(0, index) +