diff --git a/.eslintrc.json b/.eslintrc.json index 6d6839d6..f24799a5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,6 @@ { - "extends": ["eslint:recommended", "plugin:prettier/recommended"], - "plugins": ["prettier"], + "extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:jsdoc/recommended"], + "plugins": ["prettier", "jsdoc"], "env": { "browser": true, "es6": true, diff --git a/CHANGELOG.md b/CHANGELOG.md index 05446f80..8a904d51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,11 +18,13 @@ _This release is scheduled to be released on 2020-10-01._ - Add lithuanian language. - Added support in weatherforecast for OpenWeather onecall API. - Added config option to calendar-icons for recurring- and fullday-events +- Added eslint-plugin for jsdoc comments ### Updated - Change incorrect weather.js default properties. - Cleaned up newsfeed module. +- Cleaned up jsdoc comments. ### Deleted diff --git a/clientonly/index.js b/clientonly/index.js index 7d1c4fe3..88454d93 100644 --- a/clientonly/index.js +++ b/clientonly/index.js @@ -4,10 +4,19 @@ (function () { var config = {}; - // Helper function to get server address/hostname from either the commandline or env + /** + * Helper function to get server address/hostname from either the commandline or env + */ function getServerAddress() { - // Helper function to get command line parameters - // Assumes that a cmdline parameter is defined with `--key [value]` + /** + * Get command line parameters + * Assumes that a cmdline parameter is defined with `--key [value]` + * + * @param {string} key key to look for at the command line + * @param {string} defaultValue value if no key is given at the command line + * + * @returns {string} the value of the parameter + */ function getCommandLineParameter(key, defaultValue = undefined) { var index = process.argv.indexOf(`--${key}`); var value = index > -1 ? process.argv[index + 1] : undefined; @@ -23,10 +32,17 @@ config["tls"] = process.argv.indexOf("--use-tls") > 0; } + /** + * Gets the config from the specified server url + * + * @param {string} url location where the server is running. + * + * @returns {Promise} the config + */ function getServerConfig(url) { // Return new pending promise return new Promise((resolve, reject) => { - // Select http or https module, depending on reqested url + // Select http or https module, depending on requested url const lib = url.startsWith("https") ? require("https") : require("http"); const request = lib.get(url, (response) => { var configData = ""; @@ -47,6 +63,12 @@ }); } + /** + * Print a message to the console in case of errors + * + * @param {string} [message] error message to print + * @param {number} code error code for the exit call + */ function fail(message, code = 1) { if (message !== undefined && typeof message === "string") { console.log(message); diff --git a/js/app.js b/js/app.js index b1fcc9bb..64844269 100644 --- a/js/app.js +++ b/js/app.js @@ -40,16 +40,19 @@ process.on("uncaughtException", function (err) { Log.error("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues"); }); -/* App - The core app. +/** + * The core app. + * + * @class */ var App = function () { var nodeHelpers = []; - /* loadConfig(callback) - * Loads the config file. combines it with the defaults, - * and runs the callback with the found config as argument. + /** + * Loads the config file. Combines it with the defaults, and runs the + * callback with the found config as argument. * - * argument callback function - The callback function. + * @param {Function} callback Function to be called after loading the config */ var loadConfig = function (callback) { Log.log("Loading config ..."); @@ -80,6 +83,12 @@ var App = function () { } }; + /** + * Checks the config for deprecated options and throws a warning in the logs + * if it encounters one option from the deprecated.js list + * + * @param {object} userConfig The user config + */ var checkDeprecatedOptions = function (userConfig) { var deprecated = require(global.root_path + "/js/deprecated.js"); var deprecatedOptions = deprecated.configs; @@ -96,10 +105,11 @@ var App = function () { } }; - /* loadModule(module) + /** * Loads a specific module. * - * argument module string - The name of the module (including subpath). + * @param {string} module The name of the module (including subpath). + * @param {Function} callback Function to be called after loading */ var loadModule = function (module, callback) { var elements = module.split("/"); @@ -144,10 +154,11 @@ var App = function () { } }; - /* loadModules(modules) + /** * Loads all modules. * - * argument module string - The name of the module (including subpath). + * @param {Module[]} modules All modules to be loaded + * @param {Function} callback Function to be called after loading */ var loadModules = function (modules, callback) { Log.log("Loading module helpers ..."); @@ -169,11 +180,14 @@ var App = function () { loadNextModule(); }; - /* cmpVersions(a,b) + /** * Compare two semantic version numbers and return the difference. * - * argument a string - Version number a. - * argument a string - Version number b. + * @param {string} a Version number a. + * @param {string} b Version number b. + * + * @returns {number} A positive number if a is larger than b, a negative + * number if a is smaller and 0 if they are the same */ function cmpVersions(a, b) { var i, diff; @@ -191,12 +205,13 @@ var App = function () { return segmentsA.length - segmentsB.length; } - /* start(callback) - * This methods starts the core app. - * It loads the config, then it loads all modules. - * When it's done it executes the callback with the config as argument. + /** + * Start the core app. * - * argument callback function - The callback function. + * It loads the config, then it loads all modules. When it's done it + * executes the callback with the config as argument. + * + * @param {Function} callback Function to be called after start */ this.start = function (callback) { loadConfig(function (c) { @@ -234,9 +249,10 @@ var App = function () { }); }; - /* stop() - * This methods stops the core app. - * This calls each node_helper's STOP() function, if it exists. + /** + * Stops the core app. This calls each node_helper's STOP() function, if it + * exists. + * * Added to fix #1056 */ this.stop = function () { @@ -248,7 +264,8 @@ var App = function () { } }; - /* Listen for SIGINT signal and call stop() function. + /** + * Listen for SIGINT signal and call stop() function. * * Added to fix #1056 * Note: this is only used if running `server-only`. Otherwise @@ -263,7 +280,9 @@ var App = function () { process.exit(0); }); - /* We also need to listen to SIGTERM signals so we stop everything when we are asked to stop by the OS. + /** + * Listen to SIGTERM signals so we can stop everything when we + * are asked to stop by the OS. */ process.on("SIGTERM", () => { Log.log("[SIGTERM] Received. Shutting down server..."); diff --git a/js/check_config.js b/js/check_config.js index cfd56824..7ed6ea96 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -16,9 +16,11 @@ const config = require(rootPath + "/.eslintrc.json"); const Log = require(rootPath + "/js/logger.js"); const Utils = require(rootPath + "/js/utils.js"); -/* getConfigFile() - * Return string with path of configuration file +/** + * Returns a string with path of configuration file. * Check if set by environment variable MM_CONFIG_FILE + * + * @returns {string} path and filename of the config file */ function getConfigFile() { // FIXME: This function should be in core. Do you want refactor me ;) ?, be good! @@ -29,6 +31,9 @@ function getConfigFile() { return configFileName; } +/** + * Checks the config file using eslint. + */ function checkConfigFile() { const configFileName = getConfigFile(); @@ -38,7 +43,7 @@ function checkConfigFile() { throw new Error("No config file present!"); } - // check permission + // Check permission try { fs.accessSync(configFileName, fs.F_OK); } catch (e) { diff --git a/js/class.js b/js/class.js index f52ac405..9c46a894 100644 --- a/js/class.js +++ b/js/class.js @@ -57,7 +57,9 @@ : prop[name]; } - // The dummy class constructor + /** + * The dummy class constructor + */ function Class() { // All construction is actually done in the init method if (!initializing && this.init) { @@ -78,8 +80,13 @@ }; })(); -//Define the clone method for later use. -//Helper Method +/** + * Define the clone method for later use. Helper Method. + * + * @param {object} obj Object to be cloned + * + * @returns {object} the cloned object + */ function cloneObject(obj) { if (obj === null || typeof obj !== "object") { return obj; diff --git a/js/electron.js b/js/electron.js index 0978cd0d..216dee48 100644 --- a/js/electron.js +++ b/js/electron.js @@ -15,6 +15,9 @@ const BrowserWindow = electron.BrowserWindow; // be closed automatically when the JavaScript object is garbage collected. let mainWindow; +/** + * + */ function createWindow() { app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required"); var electronOptionsDefaults = { diff --git a/js/loader.js b/js/loader.js index bc376bd9..4ba75578 100644 --- a/js/loader.js +++ b/js/loader.js @@ -15,7 +15,7 @@ var Loader = (function () { /* Private Methods */ - /* loadModules() + /** * Loops thru all modules and requests load for every module. */ var loadModules = function () { @@ -43,7 +43,7 @@ var Loader = (function () { loadNextModule(); }; - /* startModules() + /** * Loops thru all modules and requests start for every module. */ var startModules = function () { @@ -56,19 +56,19 @@ var Loader = (function () { MM.modulesStarted(moduleObjects); }; - /* getAllModules() + /** * Retrieve list of all modules. * - * return array - module data as configured in config + * @returns {object[]} module data as configured in config */ var getAllModules = function () { return config.modules; }; - /* getModuleData() + /** * Generate array with module information including module paths. * - * return array - Module information. + * @returns {object[]} Module information. */ var getModuleData = function () { var modules = getAllModules(); @@ -106,11 +106,11 @@ var Loader = (function () { return moduleFiles; }; - /* loadModule(module) - * Load modules via ajax request and create module objects. + /** + * Load modules via ajax request and create module objects.s * - * argument callback function - Function called when done. - * argument module object - Information about the module we want to load. + * @param {object} module Information about the module we want to load. + * @param {Function} callback Function called when done. */ var loadModule = function (module, callback) { var url = module.path + "/" + module.file; @@ -136,12 +136,12 @@ var Loader = (function () { } }; - /* bootstrapModule(module, mObj) + /** * Bootstrap modules by setting the module data and loading the scripts & styles. * - * argument module object - Information about the module we want to load. - * argument mObj object - Modules instance. - * argument callback function - Function called when done. + * @param {object} module Information about the module we want to load. + * @param {Module} mObj Modules instance. + * @param {Function} callback Function called when done. */ var bootstrapModule = function (module, mObj, callback) { Log.info("Bootstrapping module: " + module.name); @@ -161,11 +161,11 @@ var Loader = (function () { }); }; - /* loadFile(fileName) + /** * Load a script or stylesheet by adding it to the dom. * - * argument fileName string - Path of the file we want to load. - * argument callback function - Function called when done. + * @param {string} fileName Path of the file we want to load. + * @param {Function} callback Function called when done. */ var loadFile = function (fileName, callback) { var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1); @@ -215,20 +215,20 @@ var Loader = (function () { /* Public Methods */ return { - /* loadModules() + /** * Load all modules as defined in the config. */ loadModules: function () { loadModules(); }, - /* loadFile() + /** * Load a file (script or stylesheet). * Prevent double loading and search for files in the vendor folder. * - * argument fileName string - Path of the file we want to load. - * argument module Module Object - the module that calls the loadFile function. - * argument callback function - Function called when done. + * @param {string} fileName Path of the file we want to load. + * @param {Module} module The module that calls the loadFile function. + * @param {Function} callback Function called when done. */ loadFile: function (fileName, module, callback) { if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) { diff --git a/js/main.js b/js/main.js index cbf2566f..a02e6496 100644 --- a/js/main.js +++ b/js/main.js @@ -11,9 +11,8 @@ var MM = (function () { /* Private Methods */ - /* createDomObjects() - * Create dom objects for all modules that - * are configured for a specific position. + /** + * Create dom objects for all modules that are configured for a specific position. */ var createDomObjects = function () { var domCreationPromises = []; @@ -65,10 +64,12 @@ var MM = (function () { }); }; - /* selectWrapper(position) + /** * Select the wrapper dom object for a specific position. * - * argument position string - The name of the position. + * @param {string} position The name of the position. + * + * @returns {HTMLElement} the wrapper element */ var selectWrapper = function (position) { var classes = position.replace("_", " "); @@ -81,13 +82,13 @@ var MM = (function () { } }; - /* sendNotification(notification, payload, sender) + /** * Send a notification to all modules. * - * argument notification string - The identifier of the notification. - * argument payload mixed - The payload of the notification. - * argument sender Module - The module that sent the notification. - * argument sendTo Module - The module to send the notification to. (optional) + * @param {string} notification The identifier of the notification. + * @param {*} payload The payload of the notification. + * @param {Module} sender The module that sent the notification. + * @param {Module} [sendTo] The (optional) module to send the notification to. */ var sendNotification = function (notification, payload, sender, sendTo) { for (var m in modules) { @@ -98,13 +99,13 @@ var MM = (function () { } }; - /* updateDom(module, speed) + /** * Update the dom for a specific module. * - * argument module Module - The module that needs an update. - * argument speed Number - The number of microseconds for the animation. (optional) + * @param {Module} module The module that needs an update. + * @param {number} [speed] The (optional) number of microseconds for the animation. * - * return Promise - Resolved when the dom is fully updated. + * @returns {Promise} Resolved when the dom is fully updated. */ var updateDom = function (module, speed) { return new Promise(function (resolve) { @@ -126,15 +127,15 @@ var MM = (function () { }); }; - /* updateDomWithContent(module, speed, newHeader, newContent) + /** * Update the dom with the specified content * - * argument module Module - The module that needs an update. - * argument speed Number - The number of microseconds for the animation. (optional) - * argument newHeader String - The new header that is generated. - * argument newContent Domobject - The new content that is generated. + * @param {Module} module The module that needs an update. + * @param {number} [speed] The (optional) number of microseconds for the animation. + * @param {string} newHeader The new header that is generated. + * @param {HTMLElement} newContent The new content that is generated. * - * return Promise - Resolved when the module dom has been updated. + * @returns {Promise} Resolved when the module dom has been updated. */ var updateDomWithContent = function (module, speed, newHeader, newContent) { return new Promise(function (resolve) { @@ -165,14 +166,14 @@ var MM = (function () { }); }; - /* moduleNeedsUpdate(module, newContent) + /** * Check if the content has changed. * - * argument module Module - The module to check. - * argument newHeader String - The new header that is generated. - * argument newContent Domobject - The new content that is generated. + * @param {Module} module The module to check. + * @param {string} newHeader The new header that is generated. + * @param {HTMLElement} newContent The new content that is generated. * - * return bool - Does the module need an update? + * @returns {boolean} True if the module need an update, false otherwise */ var moduleNeedsUpdate = function (module, newHeader, newContent) { var moduleWrapper = document.getElementById(module.identifier); @@ -197,12 +198,12 @@ var MM = (function () { return headerNeedsUpdate || contentNeedsUpdate; }; - /* moduleNeedsUpdate(module, newContent) + /** * Update the content of a module on screen. * - * argument module Module - The module to check. - * argument newHeader String - The new header that is generated. - * argument newContent Domobject - The new content that is generated. + * @param {Module} module The module to check. + * @param {string} newHeader The new header that is generated. + * @param {HTMLElement} newContent The new content that is generated. */ var updateModuleContent = function (module, newHeader, newContent) { var moduleWrapper = document.getElementById(module.identifier); @@ -223,12 +224,13 @@ var MM = (function () { } }; - /* hideModule(module, speed, callback) + /** * Hide the module. * - * argument module Module - The module to hide. - * argument speed Number - The speed of the hide animation. - * argument callback function - Called when the animation is done. + * @param {Module} module The module to hide. + * @param {number} speed The speed of the hide animation. + * @param {Function} callback Called when the animation is done. + * @param {object} [options] Optional settings for the hide method. */ var hideModule = function (module, speed, callback, options) { options = options || {}; @@ -268,12 +270,13 @@ var MM = (function () { } }; - /* showModule(module, speed, callback) + /** * Show the module. * - * argument module Module - The module to show. - * argument speed Number - The speed of the show animation. - * argument callback function - Called when the animation is done. + * @param {Module} module The module to show. + * @param {number} speed The speed of the show animation. + * @param {Function} callback Called when the animation is done. + * @param {object} [options] Optional settings for the show method. */ var showModule = function (module, speed, callback, options) { options = options || {}; @@ -327,7 +330,7 @@ var MM = (function () { } }; - /* updateWrapperStates() + /** * Checks for all positions if it has visible content. * If not, if will hide the position to prevent unwanted margins. * This method should be called by the show and hide methods. @@ -356,8 +359,8 @@ var MM = (function () { }); }; - /* loadConfig() - * Loads the core config and combines it with de system defaults. + /** + * Loads the core config and combines it with the system defaults. */ var loadConfig = function () { // FIXME: Think about how to pass config around without breaking tests @@ -372,41 +375,41 @@ var MM = (function () { /* eslint-enable */ }; - /* setSelectionMethodsForModules() + /** * Adds special selectors on a collection of modules. * - * argument modules array - Array of modules. + * @param {Module[]} modules Array of modules. */ var setSelectionMethodsForModules = function (modules) { - /* withClass(className) - * calls modulesByClass to filter modules with the specified classes. + /** + * Filter modules with the specified classes. * - * argument className string/array - one or multiple classnames. (array or space divided) + * @param {string|string[]} className one or multiple classnames (array or space divided). * - * return array - Filtered collection of modules. + * @returns {Module[]} Filtered collection of modules. */ var withClass = function (className) { return modulesByClass(className, true); }; - /* exceptWithClass(className) - * calls modulesByClass to filter modules without the specified classes. + /** + * Filter modules without the specified classes. * - * argument className string/array - one or multiple classnames. (array or space divided) + * @param {string|string[]} className one or multiple classnames (array or space divided). * - * return array - Filtered collection of modules. + * @returns {Module[]} Filtered collection of modules. */ var exceptWithClass = function (className) { return modulesByClass(className, false); }; - /* modulesByClass(className, include) - * filters a collection of modules based on classname(s). + /** + * Filters a collection of modules based on classname(s). * - * argument className string/array - one or multiple classnames. (array or space divided) - * argument include boolean - if the filter should include or exclude the modules with the specific classes. + * @param {string|string[]} className one or multiple classnames (array or space divided). + * @param {boolean} include if the filter should include or exclude the modules with the specific classes. * - * return array - Filtered collection of modules. + * @returns {Module[]} Filtered collection of modules. */ var modulesByClass = function (className, include) { var searchClasses = className; @@ -431,12 +434,12 @@ var MM = (function () { return newModules; }; - /* exceptModule(module) + /** * Removes a module instance from the collection. * - * argument module Module object - The module instance to remove from the collection. + * @param {object} module The module instance to remove from the collection. * - * return array - Filtered collection of modules. + * @returns {Module[]} Filtered collection of modules. */ var exceptModule = function (module) { var newModules = modules.filter(function (mod) { @@ -447,10 +450,10 @@ var MM = (function () { return newModules; }; - /* enumerate(callback) + /** * Walks thru a collection of modules and executes the callback with the module as an argument. * - * argument callback function - The function to execute with the module as an argument. + * @param {Function} callback The function to execute with the module as an argument. */ var enumerate = function (callback) { modules.map(function (module) { @@ -475,7 +478,7 @@ var MM = (function () { return { /* Public Methods */ - /* init() + /** * Main init method. */ init: function () { @@ -488,10 +491,10 @@ var MM = (function () { Loader.loadModules(); }, - /* modulesStarted(moduleObjects) + /** * Gets called when all modules are started. * - * argument moduleObjects array - All module instances. + * @param {Module[]} moduleObjects All module instances. */ modulesStarted: function (moduleObjects) { modules = []; @@ -506,12 +509,12 @@ var MM = (function () { createDomObjects(); }, - /* sendNotification(notification, payload, sender) + /** * Send a notification to all modules. * - * argument notification string - The identifier of the notification. - * argument payload mixed - The payload of the notification. - * argument sender Module - The module that sent the notification. + * @param {string} notification The identifier of the notification. + * @param {*} payload The payload of the notification. + * @param {Module} sender The module that sent the notification. */ sendNotification: function (notification, payload, sender) { if (arguments.length < 3) { @@ -533,11 +536,11 @@ var MM = (function () { sendNotification(notification, payload, sender); }, - /* updateDom(module, speed) + /** * Update the dom for a specific module. * - * argument module Module - The module that needs an update. - * argument speed Number - The number of microseconds for the animation. (optional) + * @param {Module} module The module that needs an update. + * @param {number} [speed] The number of microseconds for the animation. */ updateDom: function (module, speed) { if (!(module instanceof Module)) { @@ -549,36 +552,36 @@ var MM = (function () { updateDom(module, speed); }, - /* getModules(module, speed) + /** * Returns a collection of all modules currently active. * - * return array - A collection of all modules currently active. + * @returns {Module[]} A collection of all modules currently active. */ getModules: function () { setSelectionMethodsForModules(modules); return modules; }, - /* hideModule(module, speed, callback) + /** * Hide the module. * - * argument module Module - The module hide. - * argument speed Number - The speed of the hide animation. - * argument callback function - Called when the animation is done. - * argument options object - Optional settings for the hide method. + * @param {Module} module The module to hide. + * @param {number} speed The speed of the hide animation. + * @param {Function} callback Called when the animation is done. + * @param {object} [options] Optional settings for the hide method. */ hideModule: function (module, speed, callback, options) { module.hidden = true; hideModule(module, speed, callback, options); }, - /* showModule(module, speed, callback) + /** * Show the module. * - * argument module Module - The module show. - * argument speed Number - The speed of the show animation. - * argument callback function - Called when the animation is done. - * argument options object - Optional settings for the hide method. + * @param {Module} module The module to show. + * @param {number} speed The speed of the show animation. + * @param {Function} callback Called when the animation is done. + * @param {object} [options] Optional settings for the show method. */ showModule: function (module, speed, callback, options) { // do not change module.hidden yet, only if we really show it later diff --git a/js/module.js b/js/module.js index 4aa26a80..8bb5990e 100644 --- a/js/module.js +++ b/js/module.js @@ -2,9 +2,11 @@ /* Magic Mirror * Module Blueprint. + * @typedef {Object} Module * * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. + * */ var Module = Class.extend({ /********************************************************* @@ -29,53 +31,55 @@ var Module = Class.extend({ // Use the nunjucksEnvironment() to get it. _nunjucksEnvironment: null, - /* init() - * Is called when the module is instantiated. + /** + * Called when the module is instantiated. */ init: function () { //Log.log(this.defaults); }, - /* start() - * Is called when the module is started. + /** + * Called when the module is started. */ start: function () { Log.info("Starting module: " + this.name); }, - /* getScripts() + /** * Returns a list of scripts the module requires to be loaded. * - * return Array - An array with filenames. + * @returns {string[]} An array with filenames. */ getScripts: function () { return []; }, - /* getStyles() + /** * Returns a list of stylesheets the module requires to be loaded. * - * return Array - An array with filenames. + * @returns {string[]} An array with filenames. */ getStyles: function () { return []; }, - /* getTranslations() + /** * Returns a map of translation files the module requires to be loaded. * - * return Map - A map with langKeys and filenames. + * return Map - + * + * @returns {*} A map with langKeys and filenames. */ getTranslations: function () { return false; }, - /* getDom() - * This method generates the dom which needs to be displayed. This method is called by the Magic Mirror core. + /** + * Generates the dom which needs to be displayed. This method is called by the Magic Mirror core. * This method can to be subclassed if the module wants to display info on the mirror. * Alternatively, the getTemplate method could be subclassed. * - * return DomObject | Promise - The dom or a promise with the dom to display. + * @returns {HTMLElement|Promise} The dom or a promise with the dom to display. */ getDom: function () { var self = this; @@ -105,46 +109,45 @@ var Module = Class.extend({ }); }, - /* getHeader() - * This method generates the header string which needs to be displayed if a user has a header configured for this module. + /** + * Generates the header string which needs to be displayed if a user has a header configured for this module. * This method is called by the Magic Mirror core, but only if the user has configured a default header for the module. * This method needs to be subclassed if the module wants to display modified headers on the mirror. * - * return string - The header to display above the header. + * @returns {string} The header to display above the header. */ getHeader: function () { return this.data.header; }, - /* getTemplate() - * This method returns the template for the module which is used by the default getDom implementation. + /** + * Returns the template for the module which is used by the default getDom implementation. * This method needs to be subclassed if the module wants to use a template. * It can either return a template sting, or a template filename. * If the string ends with '.html' it's considered a file from within the module's folder. * - * return string - The template string of filename. + * @returns {string} The template string of filename. */ getTemplate: function () { return '
' + this.name + '
' + this.identifier + "
"; }, - /* getTemplateData() - * This method returns the data to be used in the template. + /** + * Returns the data to be used in the template. * This method needs to be subclassed if the module wants to use a custom data. * - * return Object + * @returns {object} The data for the template */ getTemplateData: function () { return {}; }, - /* notificationReceived(notification, payload, sender) - * This method is called when a notification arrives. - * This method is called by the Magic Mirror core. + /** + * Called by the Magic Mirror core when a notification arrives. * - * argument notification string - The identifier of the notification. - * argument payload mixed - The payload of the notification. - * argument sender Module - The module that sent the notification. + * @param {string} notification The identifier of the notification. + * @param {*} payload The payload of the notification. + * @param {Module} sender The module that sent the notification. */ notificationReceived: function (notification, payload, sender) { if (sender) { @@ -154,11 +157,11 @@ var Module = Class.extend({ } }, - /** nunjucksEnvironment() + /** * Returns the nunjucks environment for the current module. * The environment is checked in the _nunjucksEnvironment instance variable. - - * @returns Nunjucks Environment + * + * @returns {object} The Nunjucks Environment */ nunjucksEnvironment: function () { if (this._nunjucksEnvironment !== null) { @@ -171,6 +174,7 @@ var Module = Class.extend({ trimBlocks: true, lstripBlocks: true }); + this._nunjucksEnvironment.addFilter("translate", function (str) { return self.translate(str); }); @@ -178,25 +182,25 @@ var Module = Class.extend({ return this._nunjucksEnvironment; }, - /* socketNotificationReceived(notification, payload) - * This method is called when a socket notification arrives. + /** + * Called when a socket notification arrives. * - * argument notification string - The identifier of the notification. - * argument payload mixed - The payload of the notification. + * @param {string} notification The identifier of the notification. + * @param {*} payload The payload of the notification. */ socketNotificationReceived: function (notification, payload) { Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); }, - /* suspend() - * This method is called when a module is hidden. + /* + * Called when the module is hidden. */ suspend: function () { Log.log(this.name + " is suspended."); }, - /* resume() - * This method is called when a module is shown. + /* + * Called when the module is shown. */ resume: function () { Log.log(this.name + " is resumed."); @@ -206,10 +210,10 @@ var Module = Class.extend({ * The methods below don"t need subclassing. * *********************************************/ - /* setData(data) + /** * Set the module data. * - * argument data object - Module data. + * @param {Module} data The module data */ setData: function (data) { this.data = data; @@ -220,18 +224,20 @@ var Module = Class.extend({ this.setConfig(data.config); }, - /* setConfig(config) + /** * Set the module config and combine it with the module defaults. * - * argument config object - Module config. + * @param {object} config The combined module config. */ setConfig: function (config) { this.config = Object.assign({}, this.defaults, config); }, - /* socket() - * Returns a socket object. If it doesn't exist, it"s created. + /** + * Returns a socket object. If it doesn't exist, it's created. * It also registers the notification callback. + * + * @returns {MMSocket} a socket object */ socket: function () { if (typeof this._socket === "undefined") { @@ -246,40 +252,39 @@ var Module = Class.extend({ return this._socket; }, - /* file(file) + /** * Retrieve the path to a module file. * - * argument file string - Filename. - * - * return string - File path. + * @param {string} file Filename + * @returns {string} the file path */ file: function (file) { return (this.data.path + "/" + file).replace("//", "/"); }, - /* loadStyles() + /** * Load all required stylesheets by requesting the MM object to load the files. * - * argument callback function - Function called when done. + * @param {Function} callback Function called when done. */ loadStyles: function (callback) { this.loadDependencies("getStyles", callback); }, - /* loadScripts() + /** * Load all required scripts by requesting the MM object to load the files. * - * argument callback function - Function called when done. + * @param {Function} callback Function called when done. */ loadScripts: function (callback) { this.loadDependencies("getScripts", callback); }, - /* loadDependencies(funcName, callback) + /** * Helper method to load all dependencies. * - * argument funcName string - Function name to call to get scripts or styles. - * argument callback function - Function called when done. + * @param {string} funcName Function name to call to get scripts or styles. + * @param {Function} callback Function called when done. */ loadDependencies: function (funcName, callback) { var self = this; @@ -300,10 +305,10 @@ var Module = Class.extend({ loadNextDependency(); }, - /* loadScripts() - * Load all required scripts by requesting the MM object to load the files. + /** + * Load all translations. * - * argument callback function - Function called when done. + * @param {Function} callback Function called when done. */ loadTranslations: function (callback) { var self = this; @@ -334,12 +339,13 @@ var Module = Class.extend({ } }, - /* translate(key, defaultValueOrVariables, defaultValue) + /** * Request the translation for a given key with optional variables and default value. * - * argument key string - The key of the string to translate - * argument defaultValueOrVariables string/object - The default value or variables for translating. (Optional) - * argument defaultValue string - The default value with variables. (Optional) + * @param {string} key The key of the string to translate + * @param {string|object} [defaultValueOrVariables] The default value or variables for translating. + * @param {string} [defaultValue] The default value with variables. + * @returns {string} the translated key */ translate: function (key, defaultValueOrVariables, defaultValue) { if (typeof defaultValueOrVariables === "object") { @@ -348,41 +354,41 @@ var Module = Class.extend({ return Translator.translate(this, key) || defaultValueOrVariables || ""; }, - /* updateDom(speed) + /** * Request an (animated) update of the module. * - * argument speed Number - The speed of the animation. (Optional) + * @param {number} [speed] The speed of the animation. */ updateDom: function (speed) { MM.updateDom(this, speed); }, - /* sendNotification(notification, payload) + /** * Send a notification to all modules. * - * argument notification string - The identifier of the notification. - * argument payload mixed - The payload of the notification. + * @param {string} notification The identifier of the notification. + * @param {*} payload The payload of the notification. */ sendNotification: function (notification, payload) { MM.sendNotification(notification, payload, this); }, - /* sendSocketNotification(notification, payload) + /** * Send a socket notification to the node helper. * - * argument notification string - The identifier of the notification. - * argument payload mixed - The payload of the notification. + * @param {string} notification The identifier of the notification. + * @param {*} payload The payload of the notification. */ sendSocketNotification: function (notification, payload) { this.socket().sendNotification(notification, payload); }, - /* hideModule(module, speed, callback) + /** * Hide this module. * - * argument speed Number - The speed of the hide animation. - * argument callback function - Called when the animation is done. - * argument options object - Optional settings for the hide method. + * @param {number} speed The speed of the hide animation. + * @param {Function} callback Called when the animation is done. + * @param {object} [options] Optional settings for the hide method. */ hide: function (speed, callback, options) { if (typeof callback === "object") { @@ -405,12 +411,12 @@ var Module = Class.extend({ ); }, - /* showModule(module, speed, callback) + /** * Show this module. * - * argument speed Number - The speed of the show animation. - * argument callback function - Called when the animation is done. - * argument options object - Optional settings for the hide method. + * @param {number} speed The speed of the show animation. + * @param {Function} callback Called when the animation is done. + * @param {object} [options] Optional settings for the show method. */ show: function (speed, callback, options) { if (typeof callback === "object") { @@ -451,11 +457,27 @@ Module.create = function (name) { return new ModuleClass(); }; -/* cmpVersions(a,b) +Module.register = function (name, moduleDefinition) { + if (moduleDefinition.requiresVersion) { + Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + window.version); + if (cmpVersions(window.version, moduleDefinition.requiresVersion) >= 0) { + Log.log("Version is ok!"); + } else { + Log.log("Version is incorrect. Skip module: '" + name + "'"); + return; + } + } + Log.log("Module registered: " + name); + Module.definitions[name] = moduleDefinition; +}; + +/** * Compare two semantic version numbers and return the difference. * - * argument a string - Version number a. - * argument a string - Version number b. + * @param {string} a Version number a. + * @param {string} b Version number b. + * @returns {number} A positive number if a is larger than b, a negative + * number if a is smaller and 0 if they are the same */ function cmpVersions(a, b) { var i, diff; @@ -472,17 +494,3 @@ function cmpVersions(a, b) { } return segmentsA.length - segmentsB.length; } - -Module.register = function (name, moduleDefinition) { - if (moduleDefinition.requiresVersion) { - Log.log("Check MagicMirror version for module '" + name + "' - Minimum version: " + moduleDefinition.requiresVersion + " - Current version: " + window.version); - if (cmpVersions(window.version, moduleDefinition.requiresVersion) >= 0) { - Log.log("Version is ok!"); - } else { - Log.log("Version is incorrect. Skip module: '" + name + "'"); - return; - } - } - Log.log("Module registered: " + name); - Module.definitions[name] = moduleDefinition; -}; diff --git a/js/translator.js b/js/translator.js index ee4e1051..0f4bc00a 100644 --- a/js/translator.js +++ b/js/translator.js @@ -7,11 +7,11 @@ * MIT Licensed. */ var Translator = (function () { - /* loadJSON(file, callback) + /** * Load a JSON file via XHR. * - * argument file string - Path of the file we want to load. - * argument callback function - Function called when done. + * @param {string} file Path of the file we want to load. + * @param {Function} callback Function called when done. */ function loadJSON(file, callback) { var xhr = new XMLHttpRequest(); @@ -31,20 +31,27 @@ var Translator = (function () { translations: {}, translationsFallback: {}, - /* translate(module, key, variables) + /** * Load a translation for a given key for a given module. * - * argument module Module - The module to load the translation for. - * argument key string - The key of the text to translate. - * argument variables - The variables to use within the translation template (optional) + * @param {Module} module The module to load the translation for. + * @param {string} key The key of the text to translate. + * @param {object} variables The variables to use within the translation template (optional) + * @returns {string} the translated key */ translate: function (module, key, variables) { variables = variables || {}; //Empty object by default - // Combines template and variables like: - // template: "Please wait for {timeToWait} before continuing with {work}." - // variables: {timeToWait: "2 hours", work: "painting"} - // to: "Please wait for 2 hours before continuing with painting." + /** + * Combines template and variables like: + * template: "Please wait for {timeToWait} before continuing with {work}." + * variables: {timeToWait: "2 hours", work: "painting"} + * to: "Please wait for 2 hours before continuing with painting." + * + * @param {string} template Text with placeholder + * @param {object} variables Variables for the placeholder + * @returns {string} the template filled with the variables + */ function createStringFromTemplate(template, variables) { if (Object.prototype.toString.call(template) !== "[object String]") { return template; @@ -80,13 +87,13 @@ var Translator = (function () { return key; }, - /* load(module, file, isFallback, callback) + /** * Load a translation file (json) and remember the data. * - * argument module Module - The module to load the translation file for. - * argument file string - Path of the file we want to load. - * argument isFallback boolean - Flag to indicate fallback translations. - * argument callback function - Function called when done. + * @param {Module} module The module to load the translation file for. + * @param {string} file Path of the file we want to load. + * @param {boolean} isFallback Flag to indicate fallback translations. + * @param {Function} callback Function called when done. */ load: function (module, file, isFallback, callback) { if (!isFallback) { @@ -110,10 +117,10 @@ var Translator = (function () { } }, - /* loadCoreTranslations(lang) + /** * Load the core translations. * - * argument lang String - The language identifier of the core language. + * @param {string} lang The language identifier of the core language. */ loadCoreTranslations: function (lang) { var self = this; @@ -130,7 +137,7 @@ var Translator = (function () { self.loadCoreTranslationsFallback(); }, - /* loadCoreTranslationsFallback() + /** * Load the core translations fallback. * The first language defined in translations.js will be used. */ diff --git a/modules/default/alert/notificationFx.js b/modules/default/alert/notificationFx.js index 61ba59d7..89034420 100644 --- a/modules/default/alert/notificationFx.js +++ b/modules/default/alert/notificationFx.js @@ -12,7 +12,11 @@ */ (function (window) { /** - * extend obj function + * Extend one object with another one + * + * @param {object} a The object to extend + * @param {object} b The object which extends the other, overwrites existing keys + * @returns {object} The merged object */ function extend(a, b) { for (let key in b) { @@ -24,7 +28,10 @@ } /** - * NotificationFx function + * NotificationFx constructor + * + * @param {object} options The configuration options + * @class */ function NotificationFx(options) { this.options = extend({}, this.options); @@ -66,8 +73,7 @@ }; /** - * init function - * initialize and cache some vars + * Initialize and cache some vars */ NotificationFx.prototype._init = function () { // create HTML structure @@ -95,7 +101,7 @@ }; /** - * init events + * Init events */ NotificationFx.prototype._initEvents = function () { // dismiss notification by tapping on it if someone has a touchscreen @@ -105,7 +111,7 @@ }; /** - * show the notification + * Show the notification */ NotificationFx.prototype.show = function () { this.active = true; @@ -115,7 +121,7 @@ }; /** - * dismiss the notification + * Dismiss the notification */ NotificationFx.prototype.dismiss = function () { this.active = false; @@ -144,7 +150,7 @@ }; /** - * add to global namespace + * Add to global namespace */ window.NotificationFx = NotificationFx; })(window); diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 06026363..af804139 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -416,7 +416,7 @@ Module.register("calendar", { * it will a localeSpecification object with the system locale time format. * * @param {number} timeFormat Specifies either 12 or 24 hour time format - * @returns {moment.LocaleSpecification} + * @returns {moment.LocaleSpecification} formatted time */ getLocaleSpecification: function (timeFormat) { switch (timeFormat) { @@ -432,12 +432,11 @@ Module.register("calendar", { } }, - /* hasCalendarURL(url) - * Check if this config contains the calendar url. + /** + * Checks if this config contains the calendar url. * - * argument url string - Url to look for. - * - * return bool - Has calendar url + * @param {string} url The calendar url + * @returns {boolean} True if the calendar config contains the url, False otherwise */ hasCalendarURL: function (url) { for (var c in this.config.calendars) { @@ -450,10 +449,10 @@ Module.register("calendar", { return false; }, - /* createEventList() + /** * Creates the sorted list of all events. * - * return array - Array with events. + * @returns {object[]} Array with events. */ createEventList: function () { var events = []; @@ -534,10 +533,12 @@ Module.register("calendar", { return false; }, - /* createEventList(url) + /** * Requests node helper to add calendar url. * - * argument url string - Url to add. + * @param {string} url The calendar url to add + * @param {object} auth The authentication method and credentials + * @param {object} calendarConfig The config of the specific calendar */ addCalendar: function (url, auth, calendarConfig) { this.sendSocketNotification("ADD_CALENDAR", { @@ -556,12 +557,10 @@ Module.register("calendar", { }, /** - * symbolsForEvent(event) * Retrieves the symbols for a specific event. * - * argument event object - Event to look for. - * - * return array - The Symbols + * @param {object} event Event to look for. + * @returns {string[]} The symbols */ symbolsForEvent: function (event) { let symbols = this.getCalendarPropertyAsArray(event.url, "symbol", this.config.defaultSymbol); @@ -586,82 +585,72 @@ Module.register("calendar", { }, /** - * symbolClassForUrl(url) - * Retrieves the symbolClass for a specific url. + * Retrieves the symbolClass for a specific calendar url. * - * @param url string - Url to look for. - * - * @returns string + * @param {string} url The calendar url + * @returns {string} The class to be used for the symbols of the calendar */ symbolClassForUrl: function (url) { return this.getCalendarProperty(url, "symbolClass", ""); }, /** - * titleClassForUrl(url) - * Retrieves the titleClass for a specific url. + * Retrieves the titleClass for a specific calendar url. * - * @param url string - Url to look for. - * - * @returns string + * @param {string} url The calendar url + * @returns {string} The class to be used for the title of the calendar */ titleClassForUrl: function (url) { return this.getCalendarProperty(url, "titleClass", ""); }, /** - * timeClassForUrl(url) - * Retrieves the timeClass for a specific url. + * Retrieves the timeClass for a specific calendar url. * - * @param url string - Url to look for. - * - * @returns string + * @param {string} url The calendar url + * @returns {string} The class to be used for the time of the calendar */ timeClassForUrl: function (url) { return this.getCalendarProperty(url, "timeClass", ""); }, - /* calendarNameForUrl(url) - * Retrieves the calendar name for a specific url. + /** + * Retrieves the calendar name for a specific calendar url. * - * argument url string - Url to look for. - * - * return string - The name of the calendar + * @param {string} url The calendar url + * @returns {string} The name of the calendar */ calendarNameForUrl: function (url) { return this.getCalendarProperty(url, "name", ""); }, - /* colorForUrl(url) - * Retrieves the color for a specific url. + /** + * Retrieves the color for a specific calendar url. * - * argument url string - Url to look for. - * - * return string - The Color + * @param {string} url The calendar url + * @returns {string} The color */ colorForUrl: function (url) { return this.getCalendarProperty(url, "color", "#fff"); }, - /* countTitleForUrl(url) - * Retrieves the name for a specific url. + /** + * Retrieves the count title for a specific calendar url. * - * argument url string - Url to look for. - * - * return string - The Symbol + * @param {string} url The calendar url + * @returns {string} The title */ countTitleForUrl: function (url) { return this.getCalendarProperty(url, "repeatingCountTitle", this.config.defaultRepeatingCountTitle); }, - /* getCalendarProperty(url, property, defaultValue) - * Helper method to retrieve the property for a specific url. + /** + * Helper method to retrieve the property for a specific calendar url. * - * argument url string - Url to look for. - * argument property string - Property to look for. - * argument defaultValue string - Value if property is not found. - * - * return string - The Property + * @param {string} url The calendar url + * @param {string} property The property to look for + * @param {string} defaultValue The value if the property is not found + * @returns {*} The property */ getCalendarProperty: function (url, property, defaultValue) { for (var c in this.config.calendars) { @@ -737,22 +726,27 @@ Module.register("calendar", { } }, - /* capFirst(string) + /** * Capitalize the first letter of a string - * Return capitalized string + * + * @param {string} string The string to capitalize + * @returns {string} The capitalized string */ capFirst: function (string) { return string.charAt(0).toUpperCase() + string.slice(1); }, - /* titleTransform(title) + /** * Transforms the title of an event for usage. * Replaces parts of the text as defined in config.titleReplace. * Shortens title based on config.maxTitleLength and config.wrapEvents * - * argument title string - The title to transform. - * - * return string - The transformed title. + * @param {string} title The title to transform. + * @param {object} titleReplace Pairs of strings to be replaced in the title + * @param {boolean} wrapEvents Wrap the text after the line has reached maxLength + * @param {number} maxTitleLength The max length of the string + * @param {number} maxTitleLines The max number of vertical lines before cutting event title + * @returns {string} The transformed title. */ titleTransform: function (title, titleReplace, wrapEvents, maxTitleLength, maxTitleLines) { for (var needle in titleReplace) { @@ -771,7 +765,7 @@ Module.register("calendar", { return title; }, - /* broadcastEvents() + /** * Broadcasts the events to all other modules for reuse. * The all events available in one array, sorted on startdate. */ diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 888830ba..033f73cb 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -6,9 +6,27 @@ */ const Log = require("../../../js/logger.js"); const ical = require("ical"); -const moment = require("moment"); const request = require("request"); +/** + * Moment date + * + * @external Moment + * @see {@link http://momentjs.com} + */ +const moment = require("moment"); + +/** + * + * @param {string} url The url of the calendar to fetch + * @param {number} reloadInterval Time in ms the calendar is fetched again + * @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown. + * @param {number} maximumEntries The maximum number of events fetched. + * @param {number} maximumNumberOfDays The maximum number of days an event should be in the future. + * @param {object} auth The object containing options for authentication against the calendar. + * @param {boolean} includePastEvents If true events from the past maximumNumberOfDays will be fetched too + * @class + */ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) { const self = this; @@ -18,7 +36,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn let fetchFailedCallback = function () {}; let eventsReceivedCallback = function () {}; - /* fetchCalendar() + /** * Initiates calendar fetch. */ const fetchCalendar = function () { @@ -325,7 +343,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn }); }; - /* scheduleTimer() + /** * Schedule the timer for the next update. */ const scheduleTimer = function () { @@ -335,12 +353,11 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn }, reloadInterval); }; - /* isFullDayEvent(event) + /** * Checks if an event is a fullday event. * - * argument event object - The event object to check. - * - * return bool - The event is a fullday event. + * @param {object} event The event object to check. + * @returns {boolean} True if the event is a fullday event, false otherwise */ const isFullDayEvent = function (event) { if (event.start.length === 8 || event.start.dateOnly) { @@ -358,14 +375,13 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return false; }; - /* timeFilterApplies() + /** * Determines if the user defined time filter should apply * - * argument now Date - Date object using previously created object for consistency - * argument endDate Moment - Moment object representing the event end date - * argument filter string - The time to subtract from the end date to determine if an event should be shown - * - * return bool - The event should be filtered out + * @param {Date} now Date object using previously created object for consistency + * @param {Moment} endDate Moment object representing the event end date + * @param {string} filter The time to subtract from the end date to determine if an event should be shown + * @returns {boolean} True if the event should be filtered out, false otherwise */ const timeFilterApplies = function (now, endDate, filter) { if (filter) { @@ -380,12 +396,11 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn return false; }; - /* getTitleFromEvent(event) + /** * Gets the title from the event. * - * argument event object - The event object to check. - * - * return string - The title of the event, or "Event" if no title is found. + * @param {object} event The event object to check. + * @returns {string} The title of the event, or "Event" if no title is found. */ const getTitleFromEvent = function (event) { let title = "Event"; @@ -416,14 +431,14 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn /* public methods */ - /* startFetch() + /** * Initiate fetchCalendar(); */ this.startFetch = function () { fetchCalendar(); }; - /* broadcastItems() + /** * Broadcast the existing events. */ this.broadcastEvents = function () { @@ -431,37 +446,37 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEn eventsReceivedCallback(self); }; - /* onReceive(callback) + /** * Sets the on success callback * - * argument callback function - The on success callback. + * @param {Function} callback The on success callback. */ this.onReceive = function (callback) { eventsReceivedCallback = callback; }; - /* onError(callback) + /** * Sets the on error callback * - * argument callback function - The on error callback. + * @param {Function} callback The on error callback. */ this.onError = function (callback) { fetchFailedCallback = callback; }; - /* url() + /** * Returns the url of this fetcher. * - * return string - The url of this fetcher. + * @returns {string} The url of this fetcher. */ this.url = function () { return url; }; - /* events() + /** * Returns current available events for this fetcher. * - * return array - The current available events for this fetcher. + * @returns {object[]} The current available events for this fetcher. */ this.events = function () { return events; diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index e731ca6c..862755a0 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -4,7 +4,6 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ - const NodeHelper = require("node_helper"); const validUrl = require("valid-url"); const CalendarFetcher = require("./calendarfetcher.js"); @@ -24,12 +23,18 @@ module.exports = NodeHelper.create({ } }, - /* createFetcher(url, reloadInterval) + /** * Creates a fetcher for a new url if it doesn't exist yet. * Otherwise it reuses the existing one. * - * attribute url string - URL of the news feed. - * attribute reloadInterval number - Reload interval in milliseconds. + * @param {string} url The url of the calendar + * @param {number} fetchInterval How often does the calendar needs to be fetched in ms + * @param {string[]} excludedEvents An array of words / phrases from event titles that will be excluded from being shown. + * @param {number} maximumEntries The maximum number of events fetched. + * @param {number} maximumNumberOfDays The maximum number of days an event should be in the future. + * @param {object} auth The object containing options for authentication against the calendar. + * @param {boolean} broadcastPastEvents If true events from the past maximumNumberOfDays will be included in event broadcasts + * @param {string} identifier ID of the module */ createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) { var self = this; diff --git a/modules/default/clock/clock.js b/modules/default/clock/clock.js index cfcd1e40..1c7109b6 100644 --- a/modules/default/clock/clock.js +++ b/modules/default/clock/clock.js @@ -152,6 +152,13 @@ Module.register("clock", { timeWrapper.appendChild(periodWrapper); } + /** + * Format the time according to the config + * + * @param {object} config The config of the module + * @param {object} time time to format + * @returns {string} The formatted time string + */ function formatTime(config, time) { var formatString = hourSymbol + ":mm"; if (config.showPeriod && config.timeFormat !== 24) { @@ -159,6 +166,7 @@ Module.register("clock", { } return moment(time).format(formatString); } + if (this.config.showSunTimes) { const sunTimes = SunCalc.getTimes(now, this.config.lat, this.config.lon); const isVisible = now.isBetween(sunTimes.sunrise, sunTimes.sunset); diff --git a/modules/default/newsfeed/newsfeed.js b/modules/default/newsfeed/newsfeed.js index 3e26da4f..2ff02888 100644 --- a/modules/default/newsfeed/newsfeed.js +++ b/modules/default/newsfeed/newsfeed.js @@ -205,8 +205,8 @@ Module.register("newsfeed", { return typeof this.newsItems[this.activeItem].url === "string" ? this.newsItems[this.activeItem].url : this.newsItems[this.activeItem].url.href; }, - /* registerFeeds() - * registers the feeds to be used by the backend. + /** + * Registers the feeds to be used by the backend. */ registerFeeds: function () { for (var f in this.config.feeds) { @@ -218,10 +218,10 @@ Module.register("newsfeed", { } }, - /* generateFeed() + /** * Generate an ordered list of items for this configured module. * - * attribute feeds object - An object with feeds returned by the node helper. + * @param {object} feeds An object with feeds returned by the node helper. */ generateFeed: function (feeds) { var newsItems = []; @@ -274,12 +274,11 @@ Module.register("newsfeed", { this.newsItems = newsItems; }, - /* subscribedToFeed(feedUrl) + /** * Check if this module is configured to show this feed. * - * attribute feedUrl string - Url of the feed to check. - * - * returns bool + * @param {string} feedUrl Url of the feed to check. + * @returns {boolean} True if it is subscribed, false otherwise */ subscribedToFeed: function (feedUrl) { for (var f in this.config.feeds) { @@ -291,12 +290,11 @@ Module.register("newsfeed", { return false; }, - /* titleForFeed(feedUrl) - * Returns title for a specific feed Url. + /** + * Returns title for the specific feed url. * - * attribute feedUrl string - Url of the feed to check. - * - * returns string + * @param {string} feedUrl Url of the feed + * @returns {string} The title of the feed */ titleForFeed: function (feedUrl) { for (var f in this.config.feeds) { @@ -308,7 +306,7 @@ Module.register("newsfeed", { return ""; }, - /* scheduleUpdateInterval() + /** * Schedule visual update. */ scheduleUpdateInterval: function () { diff --git a/modules/default/newsfeed/newsfeedfetcher.js b/modules/default/newsfeed/newsfeedfetcher.js index ba32d1ad..20e45258 100644 --- a/modules/default/newsfeed/newsfeedfetcher.js +++ b/modules/default/newsfeed/newsfeedfetcher.js @@ -9,12 +9,14 @@ const FeedMe = require("feedme"); const request = require("request"); const iconv = require("iconv-lite"); -/* Fetcher +/** * Responsible for requesting an update on the set interval and broadcasting the data. * - * attribute url string - URL of the news feed. - * attribute reloadInterval number - Reload interval in milliseconds. - * attribute logFeedWarnings boolean - Log warnings when there is an error parsing a news article. + * @param {string} url URL of the news feed. + * @param {number} reloadInterval Reload interval in milliseconds. + * @param {string} encoding Encoding of the feed. + * @param {boolean} logFeedWarnings If true log warnings when there is an error parsing a news article. + * @class */ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings) { const self = this; @@ -31,7 +33,7 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings /* private methods */ - /* fetchNews() + /** * Request the new items. */ const fetchNews = function () { @@ -95,7 +97,7 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings .pipe(parser); }; - /* scheduleTimer() + /** * Schedule the timer for the next update. */ const scheduleTimer = function () { @@ -107,10 +109,10 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings /* public methods */ - /* setReloadInterval() + /** * Update the reload interval, but only if we need to increase the speed. * - * attribute interval number - Interval for the update in milliseconds. + * @param {number} interval Interval for the update in milliseconds. */ this.setReloadInterval = function (interval) { if (interval > 1000 && interval < reloadInterval) { @@ -118,14 +120,14 @@ const NewsfeedFetcher = function (url, reloadInterval, encoding, logFeedWarnings } }; - /* startFetch() + /** * Initiate fetchNews(); */ this.startFetch = function () { fetchNews(); }; - /* broadcastItems() + /** * Broadcast the existing items. */ this.broadcastItems = function () { diff --git a/modules/default/newsfeed/node_helper.js b/modules/default/newsfeed/node_helper.js index 6aca2519..bdfcbfcc 100644 --- a/modules/default/newsfeed/node_helper.js +++ b/modules/default/newsfeed/node_helper.js @@ -24,12 +24,12 @@ module.exports = NodeHelper.create({ } }, - /* createFetcher(feed, config) + /** * Creates a fetcher for a new feed if it doesn't exist yet. * Otherwise it reuses the existing one. * - * attribute feed object - A feed object. - * attribute config object - A configuration object containing reload interval in milliseconds. + * @param {object} feed The feed object. + * @param {object} config The configuration object. */ createFetcher: function (feed, config) { const url = feed.url || ""; @@ -68,7 +68,7 @@ module.exports = NodeHelper.create({ fetcher.startFetch(); }, - /* broadcastFeeds() + /** * Creates an object with all feed items of the different registered feeds, * and broadcasts these using sendSocketNotification. */ diff --git a/modules/default/weather/weatherprovider.js b/modules/default/weather/weatherprovider.js index cfcb3ef6..ed22054b 100644 --- a/modules/default/weather/weatherprovider.js +++ b/modules/default/weather/weatherprovider.js @@ -12,7 +12,7 @@ var WeatherProvider = Class.extend({ // Weather Provider Properties providerName: null, - // The following properties have accestor methods. + // The following properties have accessor methods. // Try to not access them directly. currentWeatherObject: null, weatherForecastArray: null, @@ -119,6 +119,9 @@ WeatherProvider.providers = []; /** * Static method to register a new weather provider. + * + * @param {string} providerIdentifier The name of the weather provider + * @param {object} providerDetails The details of the weather provider */ WeatherProvider.register = function (providerIdentifier, providerDetails) { WeatherProvider.providers[providerIdentifier.toLowerCase()] = WeatherProvider.extend(providerDetails); @@ -126,6 +129,10 @@ WeatherProvider.register = function (providerIdentifier, providerDetails) { /** * Static method to initialize a new weather provider. + * + * @param {string} providerIdentifier The name of the weather provider + * @param {object} delegate The weather module + * @returns {object} The new weather provider */ WeatherProvider.initialize = function (providerIdentifier, delegate) { providerIdentifier = providerIdentifier.toLowerCase(); diff --git a/package-lock.json b/package-lock.json index 87374cc7..a3214e7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1480,6 +1480,12 @@ "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true }, + "comment-parser": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-0.7.5.tgz", + "integrity": "sha512-iH9YA35ccw94nx5244GVkpyC9eVTsL71jZz6iz5w6RIf79JLF2AsXHXq9p6Oaohyl3sx5qSMnGsWUDFIAfWL4w==", + "dev": true + }, "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -2378,9 +2384,9 @@ } }, "eslint": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.4.0.tgz", - "integrity": "sha512-gU+lxhlPHu45H3JkEGgYhWhkR9wLHHEXC9FbWFnTlEkbKyZKWgWRLgf61E8zWmBuI6g5xKBph9ltg3NtZMVF8g==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.5.0.tgz", + "integrity": "sha512-vlUP10xse9sWt9SGRtcr1LAC67BENcQMFeV+w5EvLEoFe3xJ8cF1Skd0msziRx/VMC+72B4DxreCE+OR12OA6Q==", "requires": { "@babel/code-frame": "^7.0.0", "ajv": "^6.10.0", @@ -2390,9 +2396,9 @@ "doctrine": "^3.0.0", "enquirer": "^2.3.5", "eslint-scope": "^5.1.0", - "eslint-utils": "^2.0.0", - "eslint-visitor-keys": "^1.2.0", - "espree": "^7.1.0", + "eslint-utils": "^2.1.0", + "eslint-visitor-keys": "^1.3.0", + "espree": "^7.2.0", "esquery": "^1.2.0", "esutils": "^2.0.2", "file-entry-cache": "^5.0.1", @@ -2406,7 +2412,7 @@ "js-yaml": "^3.13.1", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", - "lodash": "^4.17.14", + "lodash": "^4.17.19", "minimatch": "^3.0.4", "natural-compare": "^1.4.0", "optionator": "^0.9.1", @@ -2538,9 +2544,9 @@ } }, "strip-json-comments": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.0.tgz", - "integrity": "sha512-e6/d0eBu7gHtdCqFt0xJr642LdToM5/cN4Qb9DbHjVx1CP5RyeM+zH7pbecEmDv/lBqb0QH+6Uqq75rxFPkM0w==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==" }, "supports-color": { "version": "7.1.0", @@ -2585,6 +2591,48 @@ } } }, + "eslint-plugin-jsdoc": { + "version": "30.1.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-30.1.0.tgz", + "integrity": "sha512-eMsX+TMW6ycgXwxqU9xqfts2/e7cWCSGzk+gHgDvqaITyMJr8AcHTdd4pAMjpnOh0cd16lPZv+/R5LbQ4uVHQA==", + "dev": true, + "requires": { + "comment-parser": "^0.7.5", + "debug": "^4.1.1", + "jsdoctypeparser": "^8.0.0", + "lodash": "^4.17.15", + "regextras": "^0.7.1", + "semver": "^7.3.2", + "spdx-expression-parse": "^3.0.1" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + }, + "spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dev": true, + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + } + } + }, "eslint-plugin-prettier": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz", @@ -2617,13 +2665,13 @@ "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==" }, "espree": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-7.1.0.tgz", - "integrity": "sha512-dcorZSyfmm4WTuTnE5Y7MEN1DyoPYy1ZR783QW1FJoenn7RailyWFsq/UL6ZAAA7uXurN9FIpYyUs3OfiIW+Qw==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-7.2.0.tgz", + "integrity": "sha512-H+cQ3+3JYRMEIOl87e7QdHX70ocly5iW4+dttuR8iYSPr/hXKFb+7dBsZ7+u1adC4VrnPlTkv0+OwuPnDop19g==", "requires": { - "acorn": "^7.2.0", + "acorn": "^7.3.1", "acorn-jsx": "^5.2.0", - "eslint-visitor-keys": "^1.2.0" + "eslint-visitor-keys": "^1.3.0" } }, "esprima": { @@ -3718,11 +3766,11 @@ } }, "iconv-lite": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.5.1.tgz", - "integrity": "sha512-ONHr16SQvKZNSqjQT9gy5z24Jw+uqfO02/ngBSBoqChZ+W8qXX7GPRa1RoUnzGADw8K63R1BXUMzarCVQBpY8Q==", + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz", + "integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==", "requires": { - "safer-buffer": ">= 2.1.2 < 3" + "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "ieee754": { @@ -4188,6 +4236,12 @@ "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, + "jsdoctypeparser": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/jsdoctypeparser/-/jsdoctypeparser-8.0.0.tgz", + "integrity": "sha512-eLCs6s4JqN8TjFJfgdiLHRvogLhOAJz+5RIA2FtoMe6ZDyuvghvppnlIToqAEnVbxRqLMrfnNXpW8FpmR6IMBw==", + "dev": true + }, "jsdom": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.12.0.tgz", @@ -5210,9 +5264,9 @@ "integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==" }, "moment": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", - "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + "version": "2.27.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.27.0.tgz", + "integrity": "sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ==" }, "mri": { "version": "1.1.5", @@ -6757,6 +6811,12 @@ "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.1.0.tgz", "integrity": "sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==" }, + "regextras": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/regextras/-/regextras-0.7.1.tgz", + "integrity": "sha512-9YXf6xtW+qzQ+hcMQXx95MOvfqXFgsKDZodX3qZB0x2n5Z94ioetIITsBtvJbiOyxa/6s9AtyweBLCdPmPko/w==", + "dev": true + }, "release-zalgo": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/release-zalgo/-/release-zalgo-1.0.0.tgz", diff --git a/package.json b/package.json index 3941f415..f2e95b7c 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "current-week-number": "^1.0.7", "danger": "^3.1.3", "eslint-config-prettier": "^6.11.0", + "eslint-plugin-jsdoc": "^30.1.0", "eslint-plugin-prettier": "^3.1.4", "http-auth": "^3.2.3", "husky": "^4.2.5", @@ -70,7 +71,7 @@ "dependencies": { "colors": "^1.1.2", "console-stamp": "^0.2.9", - "eslint": "^7.4.0", + "eslint": "^7.5.0", "express": "^4.16.2", "express-ipfilter": "^1.0.1", "feedme": "latest",