diff --git a/scripts/update_benchmarks.ts b/scripts/update_benchmarks.ts index 62fcd09e..db484a37 100755 --- a/scripts/update_benchmarks.ts +++ b/scripts/update_benchmarks.ts @@ -46,8 +46,8 @@ const outputFile = async (name: string, content: any) => { .map((benchmark) => { benchmark.gpu = benchmark.gpu .toLowerCase() - .replace(/\s*\([^\)]+(\))/g, '') - .replace(/([0-9]+)\/[^ ]+/, '$1') + .replace(/\s*\([^)]+(\))/g, '') + .replace(/(\d+)\/[^ ]+/, '$1') .replace( /x\.org |inc\. |open source technology center |imagination technologies |™ |nvidia corporation |apple inc\. |advanced micro devices, inc\. | series$| edition$| graphics$/g, '' @@ -99,7 +99,7 @@ const outputFile = async (name: string, content: any) => { fps: fpses[index] === '' ? undefined - : Math.round(Number(fpses[index].replace(/[^0-9.]+/g, ''))), + : Math.round(Number(fpses[index].replace(/[^\d.]+/g, ''))), gpu: gpuNameLookup[gpuIndex], mobile: formFactorLookup[formFactor[index]].includes('mobile'), resolution: screenSizeLookup[screenSizes[index]], diff --git a/src/index.ts b/src/index.ts index 1c7cd8f0..a370a959 100644 --- a/src/index.ts +++ b/src/index.ts @@ -126,7 +126,7 @@ export const getGPUTier = async ({ ? (['adreno', 'apple', 'mali-t', 'mali', 'nvidia', 'powervr'] as const) : (['intel', 'amd', 'radeon', 'nvidia', 'geforce'] as const); for (const type of types) { - if (renderer.indexOf(type) > -1) { + if (renderer.includes(type)) { return type; } } @@ -168,7 +168,7 @@ export const getGPUTier = async ({ // If nothing matched, try comparing model names: if (!matched.length) { - matched = benchmarks.filter(([model]) => model.indexOf(renderer) > -1); + matched = benchmarks.filter(([model]) => model.includes(renderer)); debug?.( `found ${matched.length} matching entries comparing model names`, @@ -229,7 +229,7 @@ export const getGPUTier = async ({ } if (!closest) { - return undefined; + return; } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion @@ -287,10 +287,10 @@ export const getGPUTier = async ({ ); if (!results.length) { - const blocklistedModel: string | undefined = BLOCKLISTED_GPUS.filter( + const blocklistedModel: string | undefined = BLOCKLISTED_GPUS.find( // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (blocklistedModel) => renderer!.indexOf(blocklistedModel) > -1 - )[0]; + (blocklistedModel) => renderer!.includes(blocklistedModel) + ); return blocklistedModel ? toResult(0, 'BLOCKLISTED', blocklistedModel) : toResult(1, 'FALLBACK', `${renderer} (${rawRenderer})`); diff --git a/src/internal/cleanRenderer.ts b/src/internal/cleanRenderer.ts index 7ea1fe14..f6849d8c 100644 --- a/src/internal/cleanRenderer.ts +++ b/src/internal/cleanRenderer.ts @@ -7,11 +7,11 @@ export const cleanRenderer = (renderer: string) => { .toLowerCase() // Strip off ANGLE() - for example: // 'ANGLE (NVIDIA TITAN Xp)' becomes 'NVIDIA TITAN Xp'': - .replace(/angle \((.+)\)*$/, '$1') + .replace(/^angle ?\((.+)\)*$/, '$1') // Strip off [number]gb & strip off direct3d and after - for example: // 'Radeon (TM) RX 470 Series Direct3D11 vs_5_0 ps_5_0' becomes // 'Radeon (TM) RX 470 Series' - .replace(/\s+([0-9]+gb|direct3d.+$)|\(r\)| \([^)]+\)$/g, ''); + .replace(/\s(\d{1,2}gb|direct3d.+$)|\(r\)| \([^)]+\)$/g, ''); debug?.('cleanRenderer - renderer cleaned to', { renderer }); diff --git a/src/internal/deobfuscateAppleGPU.ts b/src/internal/deobfuscateAppleGPU.ts index e2540e06..f5e5069f 100644 --- a/src/internal/deobfuscateAppleGPU.ts +++ b/src/internal/deobfuscateAppleGPU.ts @@ -82,7 +82,7 @@ export const deobfuscateAppleGPU = ( gl.vertexAttribPointer(aPosition, 3, GL_FLOAT, false, 0, 0); gl.enableVertexAttribArray(aPosition); - gl.clearColor(1.0, 1.0, 1.0, 1.0); + gl.clearColor(1, 1, 1, 1); gl.clear(GL_COLOR_BUFFER_BIT); gl.viewport(0, 0, 1, 1); gl.drawArrays(GL_TRIANGLES, 0, 3); diff --git a/src/internal/deobfuscateRenderer.ts b/src/internal/deobfuscateRenderer.ts index 36cac742..1f1e6daa 100644 --- a/src/internal/deobfuscateRenderer.ts +++ b/src/internal/deobfuscateRenderer.ts @@ -6,9 +6,5 @@ export const deobfuscateRenderer = ( renderer: string, isMobileTier: boolean ) => { - if (renderer === 'apple gpu') { - return deobfuscateAppleGPU(gl, renderer, isMobileTier); - } else { - return [renderer]; - } + return renderer === 'apple gpu' ? deobfuscateAppleGPU(gl, renderer, isMobileTier) : [renderer]; }; diff --git a/src/internal/getGPUVersion.ts b/src/internal/getGPUVersion.ts index 855d02a3..6e16db11 100644 --- a/src/internal/getGPUVersion.ts +++ b/src/internal/getGPUVersion.ts @@ -3,9 +3,9 @@ export const getGPUVersion = (model: string) => { const matches = // First set of digits - model.match(/[\d]+/) || + model.match(/\d+/) || // If the renderer did not contain any numbers, match letters - model.match(/(\W|^)([a-zA-Z]{1,3})(\W|$)/g); + model.match(/(\W|^)([A-Za-z]{1,3})(\W|$)/g); // Remove any non-word characters and also remove 'amd' which could be matched // in the clause above diff --git a/test/index.test.ts b/test/index.test.ts index 2f11a005..6aab68a5 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -80,7 +80,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => { }); // expect BENCHMARK results: -[ +for (const { input, expected } of [ { expected: { gpu: 'intel uhd graphics 620', @@ -233,7 +233,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => { renderer: 'Mali-G51', }, }, -].forEach(({ input, expected }) => { +]) { test(`${input.renderer} should find ${expected.gpu}`, async () => { expectGPUResults( { @@ -243,7 +243,7 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => { await getTier(input) ); }); -}); +} // expect FALLBACK results: [