From dda92bd41f4bee11e2cc5de265ce4fbf5221f1ff Mon Sep 17 00:00:00 2001 From: stonedDiscord Date: Wed, 20 Sep 2023 13:10:36 +0200 Subject: autoformat with eslint --- webAO/utils/__tests__/aoml.test.ts | 92 +++++++++++++++++------------------ webAO/utils/__tests__/tryUrls.test.ts | 18 +++---- webAO/utils/aoml.ts | 6 +-- webAO/utils/calculateApngLength.js | 44 ++++++++--------- webAO/utils/calculateGifLength.js | 34 ++++++------- webAO/utils/calculateWebpLength.js | 32 ++++++------ 6 files changed, 113 insertions(+), 113 deletions(-) (limited to 'webAO/utils') diff --git a/webAO/utils/__tests__/aoml.test.ts b/webAO/utils/__tests__/aoml.test.ts index 90967d7..78355ed 100644 --- a/webAO/utils/__tests__/aoml.test.ts +++ b/webAO/utils/__tests__/aoml.test.ts @@ -39,75 +39,75 @@ c6_talking = 0 const mockRequest = request as jest.MockedFunction; mockRequest.mockReturnValue(Promise.resolve(networkRequest)) - describe('mlConfig', () => { +describe('mlConfig', () => { beforeEach(() => { - // Clear all instances and calls to constructor and all methods: - mockRequest.mockClear(); + // Clear all instances and calls to constructor and all methods: + mockRequest.mockClear(); }); it('Should make a network request', () => { mlConfig('localhost') expect(mockRequest).toHaveBeenCalledTimes(1); - }); - }) - describe('applyMarkdown', () => { + }); +}) +describe('applyMarkdown', () => { const config = mlConfig('localhost') beforeEach(() => { - // Clear all instances and calls to constructor and all methods: - mockRequest.mockClear(); + // Clear all instances and calls to constructor and all methods: + mockRequest.mockClear(); }); - + it('Should create an array of spans containing letters', async () => { - const word = `hello` - const actual = await config.applyMarkdown(`hello`, `blue`) - let index = 0 - for (const element of actual) { - expect(element.innerHTML).toBe(word[index]) - index++ - } + const word = `hello` + const actual = await config.applyMarkdown(`hello`, `blue`) + let index = 0 + for (const element of actual) { + expect(element.innerHTML).toBe(word[index]) + index++ + } }) it('Should add colors based on settings', async () => { - const config = mlConfig('localhost') - const actual = await config.applyMarkdown(`(heya)`, `blue`) - expect(actual[0].getAttribute('style')).toBe('color: rgb(107, 198, 247);') + const config = mlConfig('localhost') + const actual = await config.applyMarkdown(`(heya)`, `blue`) + expect(actual[0].getAttribute('style')).toBe('color: rgb(107, 198, 247);') }) it('Should keep a letter if remove = 0', async () => { - const config = mlConfig('localhost') - - const actual = await config.applyMarkdown(`(What())Hey!`, `white`) - const expected = `(` - expect(actual[5].innerHTML).toBe(expected) + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`(What())Hey!`, `white`) + const expected = `(` + expect(actual[5].innerHTML).toBe(expected) }) it('Should remove a letter if remove = 1', async () => { - const config = mlConfig('localhost') - - const actual = await config.applyMarkdown(`~What~()Hey!`, `white`) - const expected = `` - expect(actual[0].innerHTML).toBe(expected) + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`~What~()Hey!`, `white`) + const expected = `` + expect(actual[0].innerHTML).toBe(expected) }) it('Should remove a letter if remove = 1', async () => { - const config = mlConfig('localhost') - - const actual = await config.applyMarkdown(`~What~()Hey!`, `white`) - const expected = `` - expect(actual[0].innerHTML).toBe(expected) + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`~What~()Hey!`, `white`) + const expected = `` + expect(actual[0].innerHTML).toBe(expected) }) it('Should keep a closing letter if remove = 0', async () => { - const config = mlConfig('localhost') - - const actual = await config.applyMarkdown(`~NO[]~!`, `white`) - const expected = `` - expect(actual[4].innerHTML).toBe(expected) + const config = mlConfig('localhost') + + const actual = await config.applyMarkdown(`~NO[]~!`, `white`) + const expected = `` + expect(actual[4].innerHTML).toBe(expected) }) it('Should remove a closing letter if remove = 1', async () => { - const config = mlConfig('localhost') - const actual = await config.applyMarkdown(`~NO||~!`, `white`) - const expected = `` - expect(actual[5].innerHTML).toBe(expected) + const config = mlConfig('localhost') + const actual = await config.applyMarkdown(`~NO||~!`, `white`) + const expected = `` + expect(actual[5].innerHTML).toBe(expected) }) - - }) - + +}) + diff --git a/webAO/utils/__tests__/tryUrls.test.ts b/webAO/utils/__tests__/tryUrls.test.ts index 444664e..ebc2f6b 100644 --- a/webAO/utils/__tests__/tryUrls.test.ts +++ b/webAO/utils/__tests__/tryUrls.test.ts @@ -9,23 +9,23 @@ describe('tryUrls', () => { it('Should try multiple file extensions', async () => { const url = "localhost/stoneddiscord/assets" mockFileExists - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(false)) - .mockReturnValueOnce(Promise.resolve(true)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(false)) + .mockReturnValueOnce(Promise.resolve(true)) const actual = await tryUrls(url) const expected = 'localhost/stoneddiscord/assets.apng' expect(actual).toBe(expected); - }); - + }); + it('Should return a transparent png if it cant find any assets', async () => { const url = "localhost/stoneddiscord/assets" mockFileExists - .mockReturnValue(Promise.resolve(false)) + .mockReturnValue(Promise.resolve(false)) const actual = await tryUrls(url) const expected = transparentPng expect(actual).toBe(expected); - }); + }); }) - + diff --git a/webAO/utils/aoml.ts b/webAO/utils/aoml.ts index 1f2f482..a2c1dd5 100644 --- a/webAO/utils/aoml.ts +++ b/webAO/utils/aoml.ts @@ -64,10 +64,10 @@ const mlConfig = (AO_HOST: string) => { const closingStack = [] const colorStack = [] // each value in output will be an html element - let output: HTMLSpanElement[] = [] + const output: HTMLSpanElement[] = [] for (const letter of text) { - let currentSelector = document.createElement('span') - let currentIdentifier = identifiers.get(letter) + const currentSelector = document.createElement('span') + const currentIdentifier = identifiers.get(letter) const currentClosingLetter = closingStack[closingStack.length - 1] const keepChar = Number(currentIdentifier?.remove) === 0 if (currentClosingLetter === letter) { diff --git a/webAO/utils/calculateApngLength.js b/webAO/utils/calculateApngLength.js index 0a84d46..ab8682a 100644 --- a/webAO/utils/calculateApngLength.js +++ b/webAO/utils/calculateApngLength.js @@ -3,28 +3,28 @@ * @param {data} apngFile the APNG data */ const calculateApngLength = (apngFile) => { - const d = new Uint8Array(apngFile); - // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk - let duration = 0; - for (let i = 0; i < d.length; i++) { - // Find fcTL header (66 63 54 4C) - if (d[i] === 0x66 - && d[i + 1] === 0x63 - && d[i + 2] === 0x54 - && d[i + 3] === 0x4C) { - // numerator and denominator - const delayNum = Number(d[i + 23]); - const delayDen = Number(d[i + 25]); - let delay; - // minimum is 100ms - if (delayDen === 0) { - delay = delayNum / 100; - } else { - delay = delayNum / delayDen; - } - duration += delay; + const d = new Uint8Array(apngFile); + // https://wiki.mozilla.org/APNG_Specification#.60fcTL.60:_The_Frame_Control_Chunk + let duration = 0; + for (let i = 0; i < d.length; i++) { + // Find fcTL header (66 63 54 4C) + if (d[i] === 0x66 + && d[i + 1] === 0x63 + && d[i + 2] === 0x54 + && d[i + 3] === 0x4C) { + // numerator and denominator + const delayNum = Number(d[i + 23]); + const delayDen = Number(d[i + 25]); + let delay; + // minimum is 100ms + if (delayDen === 0) { + delay = delayNum / 100; + } else { + delay = delayNum / delayDen; + } + duration += delay; + } } - } - return duration * 10; + return duration * 10; }; export default calculateApngLength; diff --git a/webAO/utils/calculateGifLength.js b/webAO/utils/calculateGifLength.js index 3ed6aa4..eccfc77 100644 --- a/webAO/utils/calculateGifLength.js +++ b/webAO/utils/calculateGifLength.js @@ -6,24 +6,24 @@ * @param {data} gifFile the GIF data */ const calculateGifLength = (gifFile) => { - const d = new Uint8Array(gifFile); - // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/ - // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt - let duration = 0; - for (let i = 0; i < d.length; i++) { - // Find a Graphic Control Extension hex(21F904__ ____ __00) - if (d[i] === 0x21 - && d[i + 1] === 0xF9 - && d[i + 2] === 0x04 - && d[i + 7] === 0x00) { - // Swap 5th and 6th bytes to get the delay per frame - const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF); + const d = new Uint8Array(gifFile); + // Thanks to http://justinsomnia.org/2006/10/gif-animation-duration-calculation/ + // And http://www.w3.org/Graphics/GIF/spec-gif89a.txt + let duration = 0; + for (let i = 0; i < d.length; i++) { + // Find a Graphic Control Extension hex(21F904__ ____ __00) + if (d[i] === 0x21 + && d[i + 1] === 0xF9 + && d[i + 2] === 0x04 + && d[i + 7] === 0x00) { + // Swap 5th and 6th bytes to get the delay per frame + const delay = (d[i + 5] << 8) | (d[i + 4] & 0xFF); - // Should be aware browsers have a minimum frame delay - // e.g. 6ms for IE, 2ms modern browsers (50fps) - duration += delay < 2 ? 10 : delay; + // Should be aware browsers have a minimum frame delay + // e.g. 6ms for IE, 2ms modern browsers (50fps) + duration += delay < 2 ? 10 : delay; + } } - } - return duration * 10; + return duration * 10; }; export default calculateGifLength; diff --git a/webAO/utils/calculateWebpLength.js b/webAO/utils/calculateWebpLength.js index ea7eb80..e81a77b 100644 --- a/webAO/utils/calculateWebpLength.js +++ b/webAO/utils/calculateWebpLength.js @@ -1,24 +1,24 @@ /* eslint no-bitwise: "off" */ const calculateWebpLength = (webpFile) => { - const d = new Uint8Array(webpFile); - // https://developers.google.com/speed/webp/docs/riff_container#animation - let duration = 0; - for (let i = 0; i < d.length; i++) { - // Find ANMF header (41 4E 4D 46) - if (d[i] === 0x41 - && d[i + 1] === 0x4E - && d[i + 2] === 0x4D - && d[i + 3] === 0x46) { - // Swap 5th and 6th bytes to get the delay per frame - const delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF); + const d = new Uint8Array(webpFile); + // https://developers.google.com/speed/webp/docs/riff_container#animation + let duration = 0; + for (let i = 0; i < d.length; i++) { + // Find ANMF header (41 4E 4D 46) + if (d[i] === 0x41 + && d[i + 1] === 0x4E + && d[i + 2] === 0x4D + && d[i + 3] === 0x46) { + // Swap 5th and 6th bytes to get the delay per frame + const delay = (d[i + 21] << 8) | (d[i + 20] & 0xFF); - // Should be aware browsers have a minimum frame delay - // e.g. 6ms for IE, 2ms modern browsers (50fps) - duration += delay < 2 ? 10 : delay; + // Should be aware browsers have a minimum frame delay + // e.g. 6ms for IE, 2ms modern browsers (50fps) + duration += delay < 2 ? 10 : delay; + } } - } - return duration; + return duration; }; export default calculateWebpLength; -- cgit