diff --git a/examples/jekyll/assets/js/crowdin-init.js b/examples/jekyll/assets/js/crowdin-init.js index 9ae9050..2dda5bd 100644 --- a/examples/jekyll/assets/js/crowdin-init.js +++ b/examples/jekyll/assets/js/crowdin-init.js @@ -1 +1 @@ -window.initCrowdIn('LizardByte-docs', null); +globalThis.initCrowdIn('LizardByte-docs', null); diff --git a/examples/jekyll/assets/js/discord-init.js b/examples/jekyll/assets/js/discord-init.js deleted file mode 100644 index e9e9585..0000000 --- a/examples/jekyll/assets/js/discord-init.js +++ /dev/null @@ -1 +0,0 @@ -window.initDiscord(); diff --git a/examples/sphinx/source/_static/js/crowdin.js b/examples/sphinx/source/_static/js/crowdin.js index c801b66..ac845bd 100644 --- a/examples/sphinx/source/_static/js/crowdin.js +++ b/examples/sphinx/source/_static/js/crowdin.js @@ -1 +1 @@ -window.initCrowdIn('LizardByte-docs', 'sphinx') +globalThis.initCrowdIn('LizardByte-docs', 'sphinx') diff --git a/src/js/format-number.js b/src/js/format-number.js index 3dcf21c..cccdddf 100644 --- a/src/js/format-number.js +++ b/src/js/format-number.js @@ -15,8 +15,8 @@ function formatNumber(num, decimalPlaces = 1) { } // Expose to the global scope -if (typeof window !== 'undefined') { - window.formatNumber = formatNumber; +if (globalThis.window !== undefined) { + globalThis.formatNumber = formatNumber; } module.exports = formatNumber; diff --git a/src/js/levenshtein-distance.js b/src/js/levenshtein-distance.js index 9c367fb..f9e240d 100644 --- a/src/js/levenshtein-distance.js +++ b/src/js/levenshtein-distance.js @@ -40,8 +40,8 @@ function levenshteinDistance(a, b) { } // Expose to the global scope -if (typeof window !== 'undefined') { - window.levenshteinDistance = levenshteinDistance; +if (globalThis.window !== undefined) { + globalThis.levenshteinDistance = levenshteinDistance; } module.exports = levenshteinDistance; diff --git a/src/js/load-script.js b/src/js/load-script.js index dddfcf4..718609d 100644 --- a/src/js/load-script.js +++ b/src/js/load-script.js @@ -20,8 +20,8 @@ function loadScript(url, callback) { } // Expose to the global scope -if (typeof window !== 'undefined') { - window.loadScript = loadScript; +if (globalThis.window !== undefined) { + globalThis.loadScript = loadScript; } module.exports = loadScript; diff --git a/src/js/ranking-sorter.js b/src/js/ranking-sorter.js index 0960e8b..e9792fa 100644 --- a/src/js/ranking-sorter.js +++ b/src/js/ranking-sorter.js @@ -10,22 +10,19 @@ function rankingSorter(firstKey, secondKey) { return -1; } else if (a[firstKey] < b[firstKey]) { return 1; - } - else { - if (a[secondKey] > b[secondKey]) { - return 1; - } else if (a[secondKey] < b[secondKey]) { - return -1; - } else { - return 0; - } + } else if (a[secondKey] > b[secondKey]) { + return 1; + } else if (a[secondKey] < b[secondKey]) { + return -1; + } else { + return 0; } } } // Expose to the global scope -if (typeof window !== 'undefined') { - window.rankingSorter = rankingSorter; +if (globalThis.window !== undefined) { + globalThis.rankingSorter = rankingSorter; } module.exports = rankingSorter; diff --git a/src/js/sleep.js b/src/js/sleep.js index 77d4ccb..edcb49a 100644 --- a/src/js/sleep.js +++ b/src/js/sleep.js @@ -8,8 +8,8 @@ function sleep(ms) { } // Expose to the global scope -if (typeof window !== 'undefined') { - window.sleep = sleep; +if (globalThis.window !== undefined) { + globalThis.sleep = sleep; } module.exports = sleep; diff --git a/tests/crowdin.test.js b/tests/crowdin.test.js index 7446b11..5847478 100644 --- a/tests/crowdin.test.js +++ b/tests/crowdin.test.js @@ -49,7 +49,7 @@ describe('initCrowdIn', () => { afterEach(() => { jest.clearAllMocks(); jest.useRealTimers(); - delete global.window.proxyTranslator; + delete globalThis.window.proxyTranslator; delete globalThis._crowdinMirrorInstalled; }); @@ -84,7 +84,7 @@ describe('initCrowdIn', () => { // Simulate script loading jest.runAllTimers(); - expect(window.proxyTranslator.init).toHaveBeenCalledWith( + expect(globalThis.proxyTranslator.init).toHaveBeenCalledWith( expect.objectContaining({ baseUrl: "http://localhost", distribution: "d6c830ba4b41106fefe5d391bw4", diff --git a/tests/sleep.test.js b/tests/sleep.test.js index 84db3dc..8c5ef74 100644 --- a/tests/sleep.test.js +++ b/tests/sleep.test.js @@ -16,7 +16,7 @@ describe('sleep function', () => { }) beforeEach(() => { - jest.spyOn(global, 'setTimeout'); + jest.spyOn(globalThis, 'setTimeout'); }); test.each([ diff --git a/webpack.config.js b/webpack.config.js index c78f312..d504356 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,4 @@ -const path = require('path'); +const path = require('node:path'); const { codecovWebpackPlugin } = require("@codecov/webpack-plugin"); const MiniCssExtractPlugin = require('mini-css-extract-plugin');