Skip to content

Commit b551ffa

Browse files
authored
prefer arrow over function (#4252)
1 parent 9de6d08 commit b551ffa

37 files changed

Lines changed: 296 additions & 297 deletions

clientonly/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ const https = require("node:https");
1212
* @param {string} defaultValue value if no key is given at the command line
1313
* @returns {string} the value of the parameter
1414
*/
15-
function getCommandLineParameter (key, defaultValue = undefined) {
15+
const getCommandLineParameter = (key, defaultValue = undefined) => {
1616
const index = process.argv.indexOf(`--${key}`);
1717
const value = index > -1 ? process.argv[index + 1] : undefined;
1818
return value !== undefined ? String(value) : defaultValue;
19-
}
19+
};
2020

2121
/**
2222
* Helper function to get server address/hostname from either the commandline or env
2323
* @returns {object} config object containing address, port, and tls properties
2424
*/
25-
function getServerParameters () {
25+
const getServerParameters = () => {
2626
const config = {};
2727

2828
// Prefer command line arguments over environment variables
@@ -34,14 +34,14 @@ function getServerParameters () {
3434
config.tls = process.argv.includes("--use-tls");
3535

3636
return config;
37-
}
37+
};
3838

3939
/**
4040
* Gets the config from the specified server url
4141
* @param {string} url location where the server is running.
4242
* @returns {Promise} the config
4343
*/
44-
function getServerConfig (url) {
44+
const getServerConfig = (url) => {
4545
// Return new pending promise
4646
return new Promise((resolve, reject) => {
4747
// Select http or https module, depending on requested url
@@ -67,29 +67,29 @@ function getServerConfig (url) {
6767
reject(new Error(`Unable to read config from server (${url}) (${error.message})`));
6868
});
6969
});
70-
}
70+
};
7171

7272
/**
7373
* Print a message to the console in case of errors
7474
* @param {string} message error message to print
7575
* @param {number} code error code for the exit call
7676
*/
77-
function fail (message, code = 1) {
77+
const fail = (message, code = 1) => {
7878
if (message !== undefined && typeof message === "string") {
7979
console.error(message);
8080
} else {
8181
console.error("Usage: 'node clientonly --address 192.168.1.10 --port 8080 [--use-tls]'");
8282
}
8383
process.exit(code);
84-
}
84+
};
8585

8686
/**
8787
* Starts the client by connecting to the server and launching the Electron application
8888
* @param {object} config server configuration
8989
* @param {string} prefix http or https prefix
9090
* @async
9191
*/
92-
async function startClient (config, prefix) {
92+
const startClient = async (config, prefix) => {
9393
try {
9494
const serverUrl = `${prefix}${config.address}:${config.port}/config/`;
9595
console.log(`Client: Connecting to server at ${serverUrl}`);
@@ -143,7 +143,7 @@ async function startClient (config, prefix) {
143143
} catch (reason) {
144144
fail(`Unable to connect to server: (${reason})`);
145145
}
146-
}
146+
};
147147

148148
// Main execution
149149
const config = getServerParameters();

defaultmodules/compliments/compliments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Module.register("compliments", {
112112
return 0;
113113
}
114114

115-
const generate = function () {
115+
const generate = () => {
116116
return Math.floor(Math.random() * compliments.length);
117117
};
118118

defaultmodules/newsfeed/newsfeed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Module.register("newsfeed", {
261261
}
262262

263263
if (this.config.prohibitedWords.length > 0) {
264-
newsItems = newsItems.filter(function (item) {
264+
newsItems = newsItems.filter((item) => {
265265
for (const word of this.config.prohibitedWords) {
266266
if (item.title.toLowerCase().indexOf(word.toLowerCase()) > -1) {
267267
return false;

defaultmodules/weather/provider-utils.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const SunCalc = require("suncalc");
99
* @param {string} weatherType - OpenWeatherMap icon code (e.g., "01d", "02n")
1010
* @returns {string|null} Internal weather type
1111
*/
12-
function convertWeatherType (weatherType) {
12+
const convertWeatherType = (weatherType) => {
1313
const weatherTypes = {
1414
"01d": "day-sunny",
1515
"02d": "day-cloudy",
@@ -32,26 +32,26 @@ function convertWeatherType (weatherType) {
3232
};
3333

3434
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
35-
}
35+
};
3636

3737
/**
3838
* Apply timezone offset to a date
3939
* @param {Date} date - The date to apply offset to
4040
* @param {number} offsetMinutes - Timezone offset in minutes
4141
* @returns {Date} Date with applied offset
4242
*/
43-
function applyTimezoneOffset (date, offsetMinutes) {
43+
const applyTimezoneOffset = (date, offsetMinutes) => {
4444
const utcTime = date.getTime() + (date.getTimezoneOffset() * 60000);
4545
return new Date(utcTime + (offsetMinutes * 60000));
46-
}
46+
};
4747

4848
/**
4949
* Limit decimal places for coordinates (truncate, not round)
5050
* @param {number} value - The coordinate value
5151
* @param {number} decimals - Maximum number of decimal places
5252
* @returns {number} Value with limited decimal places
5353
*/
54-
function limitDecimals (value, decimals) {
54+
const limitDecimals = (value, decimals) => {
5555
const str = value.toString();
5656
if (str.includes(".")) {
5757
const parts = str.split(".");
@@ -60,7 +60,7 @@ function limitDecimals (value, decimals) {
6060
}
6161
}
6262
return value;
63-
}
63+
};
6464

6565
/**
6666
* Get sunrise and sunset times for a given date and location
@@ -69,13 +69,13 @@ function limitDecimals (value, decimals) {
6969
* @param {number} lon - Longitude
7070
* @returns {object} Object with sunrise and sunset Date objects
7171
*/
72-
function getSunTimes (date, lat, lon) {
72+
const getSunTimes = (date, lat, lon) => {
7373
const sunTimes = SunCalc.getTimes(date, lat, lon);
7474
return {
7575
sunrise: sunTimes.sunrise,
7676
sunset: sunTimes.sunset
7777
};
78-
}
78+
};
7979

8080
/**
8181
* Check if a given time is during daylight hours
@@ -84,52 +84,52 @@ function getSunTimes (date, lat, lon) {
8484
* @param {Date} sunset - Sunset time
8585
* @returns {boolean} True if during daylight hours
8686
*/
87-
function isDayTime (date, sunrise, sunset) {
87+
const isDayTime = (date, sunrise, sunset) => {
8888
if (!sunrise || !sunset) {
8989
return true; // Default to day if times unavailable
9090
}
9191
return date >= sunrise && date < sunset;
92-
}
92+
};
9393

9494
/**
9595
* Format timezone offset as string (e.g., "+01:00", "-05:30")
9696
* @param {number} offsetMinutes - Timezone offset in minutes (use -new Date().getTimezoneOffset() for local)
9797
* @returns {string} Formatted offset string
9898
*/
99-
function formatTimezoneOffset (offsetMinutes) {
99+
const formatTimezoneOffset = (offsetMinutes) => {
100100
const hours = Math.floor(Math.abs(offsetMinutes) / 60);
101101
const minutes = Math.abs(offsetMinutes) % 60;
102102
const sign = offsetMinutes >= 0 ? "+" : "-";
103103
return `${sign}${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
104-
}
104+
};
105105

106106
/**
107107
* Get date string in YYYY-MM-DD format (local time)
108108
* @param {Date} date - The date to format
109109
* @returns {string} Date string in YYYY-MM-DD format
110110
*/
111-
function getDateString (date) {
111+
const getDateString = (date) => {
112112
const year = date.getFullYear();
113113
const month = String(date.getMonth() + 1).padStart(2, "0");
114114
const day = String(date.getDate()).padStart(2, "0");
115115
return `${year}-${month}-${day}`;
116-
}
116+
};
117117

118118
/**
119119
* Convert wind speed from km/h to m/s
120120
* @param {number} kmh - Wind speed in km/h
121121
* @returns {number} Wind speed in m/s
122122
*/
123-
function convertKmhToMs (kmh) {
123+
const convertKmhToMs = (kmh) => {
124124
return kmh / 3.6;
125-
}
125+
};
126126

127127
/**
128128
* Convert cardinal wind direction string to degrees
129129
* @param {string} direction - Cardinal direction (e.g., "N", "NNE", "SW")
130130
* @returns {number|null} Direction in degrees (0-360) or null if unknown
131131
*/
132-
function cardinalToDegrees (direction) {
132+
const cardinalToDegrees = (direction) => {
133133
const directions = {
134134
N: 0,
135135
NNE: 22.5,
@@ -149,23 +149,23 @@ function cardinalToDegrees (direction) {
149149
NNW: 337.5
150150
};
151151
return directions[direction] ?? null;
152-
}
152+
};
153153

154154
/**
155155
* Validate and limit coordinate precision
156156
* @param {object} config - Configuration object with lat/lon properties
157157
* @param {number} maxDecimals - Maximum decimal places to preserve
158158
* @throws {Error} If coordinates are missing or invalid
159159
*/
160-
function validateCoordinates (config, maxDecimals = 4) {
160+
const validateCoordinates = (config, maxDecimals = 4) => {
161161
if (config.lat == null || config.lon == null
162162
|| !Number.isFinite(config.lat) || !Number.isFinite(config.lon)) {
163163
throw new Error("Latitude and longitude are required");
164164
}
165165

166166
config.lat = limitDecimals(config.lat, maxDecimals);
167167
config.lon = limitDecimals(config.lon, maxDecimals);
168-
}
168+
};
169169

170170
module.exports = {
171171
convertWeatherType,

js/alias-resolver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const resolved = Object.fromEntries(
2121
// Prevent multiple patching if this file is required more than once.
2222
if (!Module._mmAliasPatched) {
2323
const origResolveFilename = Module._resolveFilename;
24-
Module._resolveFilename = function (request, parent, isMain, options) {
24+
Module._resolveFilename = (request, parent, isMain, options) => {
2525
if (Object.prototype.hasOwnProperty.call(resolved, request)) {
2626
return resolved[request];
2727
}

js/animateCSS.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const AnimateCSSOut = [
128128
* @param {string} [animation] animation name.
129129
* @param {number} [animationTime] animation duration.
130130
*/
131-
function addAnimateCSS (element, animation, animationTime) {
131+
const addAnimateCSS = (element, animation, animationTime) => {
132132
const animationName = `animate__${animation}`;
133133
const node = document.getElementById(element);
134134
if (!node) {
@@ -138,14 +138,14 @@ function addAnimateCSS (element, animation, animationTime) {
138138
}
139139
node.style.setProperty("--animate-duration", `${animationTime}s`);
140140
node.classList.add("animate__animated", animationName);
141-
}
141+
};
142142

143143
/**
144144
* Remove an animation with Animate CSS
145145
* @param {string} [element] div element to animate.
146146
* @param {string} [animation] animation name.
147147
*/
148-
function removeAnimateCSS (element, animation) {
148+
const removeAnimateCSS = (element, animation) => {
149149
const animationName = `animate__${animation}`;
150150
const node = document.getElementById(element);
151151
if (!node) {
@@ -155,5 +155,5 @@ function removeAnimateCSS (element, animation) {
155155
}
156156
node.classList.remove("animate__animated", animationName);
157157
node.style.removeProperty("--animate-duration");
158-
}
158+
};
159159
if (typeof window === "undefined") module.exports = { AnimateCSSIn, AnimateCSSOut, addAnimateCSS, removeAnimateCSS };

js/app.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function App () {
6868
* Loads a specific module.
6969
* @param {string} module The name of the module (including subpath).
7070
*/
71-
function loadModule (module) {
71+
const loadModule = (module) => {
7272
const elements = module.split("/");
7373
const moduleName = elements[elements.length - 1];
7474
let moduleFolder = path.resolve(`${global.root_path}/${env.modulesDir}`, module);
@@ -130,22 +130,22 @@ function App () {
130130

131131
m.loaded();
132132
}
133-
}
133+
};
134134

135135
/**
136136
* Loads all modules.
137137
* @param {Module[]} modules All modules to be loaded
138138
* @returns {Promise} A promise that is resolved when all modules been loaded
139139
*/
140-
async function loadModules (modules) {
140+
const loadModules = async (modules) => {
141141
Log.log("Loading module helpers ...");
142142

143143
for (const module of modules) {
144144
await loadModule(module);
145145
}
146146

147147
Log.log("All module helpers loaded.");
148-
}
148+
};
149149

150150
/**
151151
* Compare two semantic version numbers and return the difference.
@@ -154,7 +154,7 @@ function App () {
154154
* @returns {number} A positive number if a is larger than b, a negative
155155
* number if a is smaller and 0 if they are the same
156156
*/
157-
function cmpVersions (a, b) {
157+
const cmpVersions = (a, b) => {
158158
let i, diff;
159159
const regExStrip0 = /(\.0+)+$/;
160160
const segmentsA = a.replace(regExStrip0, "").split(".");
@@ -168,7 +168,7 @@ function App () {
168168
}
169169
}
170170
return segmentsA.length - segmentsB.length;
171-
}
171+
};
172172

173173
/**
174174
* Start the core app.
@@ -177,7 +177,7 @@ function App () {
177177
* @async
178178
* @returns {Promise<object>} the config used
179179
*/
180-
this.start = async function () {
180+
this.start = async () => {
181181
try {
182182
const configObj = Utils.loadConfig();
183183
global.config = configObj.fullConf;
@@ -277,7 +277,7 @@ function App () {
277277
* @returns {Promise} A promise that is resolved when all node_helpers and
278278
* the http server has been closed
279279
*/
280-
this.stop = async function () {
280+
this.stop = async () => {
281281
const nodePromises = [];
282282
for (const nodeHelper of nodeHelpers) {
283283
try {

0 commit comments

Comments
 (0)