Skip to content

Commit

Permalink
fix(dist): expose functions to global scope (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Sep 21, 2024
1 parent 9b3ddcf commit 6f374ae
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/js/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ function initDiscord() {
});
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.initDiscord = initDiscord;
}

module.exports = {
initDiscord,
randomQuote,
Expand Down
5 changes: 5 additions & 0 deletions src/js/levenshtein-distance.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ function levenshteinDistance(a, b) {
return (1 - (matrix[b.length][a.length] / Math.max(a.length, b.length))) * 100
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.levenshteinDistance = levenshteinDistance;
}

module.exports = levenshteinDistance;
5 changes: 5 additions & 0 deletions src/js/load-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ function loadScript(url, callback) {
document.head.appendChild(script);
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.loadScript = loadScript;
}

module.exports = loadScript;
7 changes: 6 additions & 1 deletion src/js/ranking-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param secondKey The secondary key to sort by, in case the first key is equal.
* @returns {(function(*, *): (number))|*} The sorting function.
*/
let rankingSorter = function (firstKey, secondKey) {
function rankingSorter(firstKey, secondKey) {
return function(a, b) {
if (a[firstKey] > b[firstKey]) {
return -1;
Expand All @@ -23,4 +23,9 @@ let rankingSorter = function (firstKey, secondKey) {
}
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.rankingSorter = rankingSorter;
}

module.exports = rankingSorter;
5 changes: 5 additions & 0 deletions src/js/sleep.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

// Expose to the global scope
if (typeof window !== 'undefined') {
window.sleep = sleep;
}

module.exports = sleep;

0 comments on commit 6f374ae

Please sign in to comment.