diff --git a/frontend/src/utils/screen.js b/frontend/src/utils/screen.js index 215487f..059efae 100644 --- a/frontend/src/utils/screen.js +++ b/frontend/src/utils/screen.js @@ -1,99 +1,123 @@ -const getWidth = (key) => ({ - key: 'Width', - code: `window.screen.${key}`, - value: window.screen[key], - issues: [ - checkScreenProperties('width'), - checkScreenValue('width'), - checkScreenPrototype('width'), - checkWidth(), - ], -}); +const getWidth = () => { + const name = 'width'; + return { + key: 'Width', + code: `window.screen.${name}`, + value: window.screen[name], + issues: [ + checkScreenProperties('width'), + checkScreenValue('width'), + checkScreenPrototype('width'), + checkWidth(), + ], + }; +}; -const getAvailWidth = (key) => ({ - key: 'Avail width', - code: `window.screen.${key}`, - value: window.screen[key], - issues: [ - checkScreenProperties('availWidth'), - checkScreenValue('availWidth'), - checkScreenPrototype('availWidth'), - checkWidth(), - ], -}); +const getAvailWidth = () => { + const name = 'availWidth'; + return { + key: 'Avail width', + code: `window.screen.${name}`, + value: window.screen[name], + issues: [ + checkScreenProperties('availWidth'), + checkScreenValue('availWidth'), + checkScreenPrototype('availWidth'), + checkWidth(), + ], + }; +}; -const getOuterWidth = (key) => ({ - key: 'Outer width', - code: `window.${key}`, - value: window[key], - issues: [], -}); +const getOuterWidth = () => { + const name = 'outerWidth'; + return { + key: 'Outer width', + code: `window.${name}`, + value: window[name], + issues: [], + }; +}; -const getHeight = (key) => ({ - key: 'Height', - code: `window.screen.${key}`, - value: window.screen[key], - issues: [ - checkScreenProperties('height'), - checkScreenValue('height'), - checkScreenPrototype('height'), - ], -}); +const getHeight = () => { + const name = 'height'; + return { + key: 'Height', + code: `window.screen.${name}`, + value: window.screen[name], + issues: [ + checkScreenProperties('height'), + checkScreenValue('height'), + checkScreenPrototype('height'), + ], + }; +}; -const getAvailHeight = (key) => ({ - key: 'Avail height', - code: `window.screen.${key}`, - value: window.screen[key], - issues: [ - checkScreenProperties('availHeight'), - checkScreenValue('availHeight'), - checkScreenPrototype('availHeight'), - checkHeight(), - ], -}); +const getAvailHeight = () => { + const name = 'availHeight'; + return { + key: 'Avail height', + code: `window.screen.${name}`, + value: window.screen[name], + issues: [ + checkScreenProperties('availHeight'), + checkScreenValue('availHeight'), + checkScreenPrototype('availHeight'), + checkHeight(), + ], + }; +}; -const getOuterHeight = (key) => ({ - key: 'Outer height', - code: `window.${key}`, - value: window[key], - issues: [], -}); +const getOuterHeight = () => { + const name = 'outerHeight'; + return { + key: 'Outer height', + code: `window.${name}`, + value: window[name], + issues: [], + }; +}; -const getPixelDepth = (key) => ({ - key: 'Pixel depth', - code: `window.screen.${key}`, - value: window.screen[key], - issues: [ - checkScreenProperties('pixelDepth'), - checkScreenValue('pixelDepth'), - checkScreenPrototype('pixelDepth'), - ], -}); +const getPixelDepth = () => { + const name = 'pixelDepth'; + return { + key: 'Pixel depth', + code: `window.screen.${name}`, + value: window.screen[name], + issues: [ + checkScreenProperties('pixelDepth'), + checkScreenValue('pixelDepth'), + checkScreenPrototype('pixelDepth'), + ], + }; +}; -const getColorDepth = (key) => ({ - key: 'Color depth', - code: `window.screen.${key}`, - value: window.screen[key], - issues: [ - checkScreenProperties('colorDepth'), - checkScreenValue('colorDepth'), - checkScreenPrototype('colorDepth'), - ], -}); +const getColorDepth = () => { + const name = 'colorDepth'; + return { + key: 'Color depth', + code: `window.screen.${name}`, + value: window.screen[name], + issues: [ + checkScreenProperties('colorDepth'), + checkScreenValue('colorDepth'), + checkScreenPrototype('colorDepth'), + ], + }; +}; -const checkScreenValue = (key) => { +const checkScreenValue = (name) => { if ( - Object.getOwnPropertyDescriptor(Screen.prototype, key).value !== undefined + Object.getOwnPropertyDescriptor(Screen.prototype, name).value !== undefined ) { return 'Failed descriptor.value undefined'; } return null; }; -const checkScreenPrototype = (key) => { +const checkScreenPrototype = (name) => { try { // eslint-disable-next-line no-unused-vars - const check = Screen.prototype[key]; + const check = Screen.prototype[name]; return 'Failed Screen.prototype'; } catch (err) { // eslint-disable-next-line no-unused-vars @@ -116,22 +140,22 @@ const checkHeight = () => { return null; }; -const checkScreenProperties = (key) => { - if (Object.getOwnPropertyDescriptor(window.screen, key) !== undefined) { +const checkScreenProperties = (name) => { + if (Object.getOwnPropertyDescriptor(window.screen, name) !== undefined) { return 'Failed undefined properties'; } return null; }; const getScreen = () => [ - getWidth('width'), - getAvailWidth('availWidth'), - getOuterWidth('outerWidth'), - getHeight('height'), - getAvailHeight('availHeight'), - getOuterHeight('outerHeight'), - getPixelDepth('pixelDepth'), - getColorDepth('colorDepth'), + getWidth(), + getAvailWidth(), + getOuterWidth(), + getHeight(), + getAvailHeight(), + getOuterHeight(), + getPixelDepth(), + getColorDepth(), ]; export default getScreen;