Skip to content

Instantly share code, notes, and snippets.

@kwakwaversal
Last active November 19, 2022 23:58
Show Gist options
  • Save kwakwaversal/82e71ddb1943320cc526b468564b698e to your computer and use it in GitHub Desktop.
Save kwakwaversal/82e71ddb1943320cc526b468564b698e to your computer and use it in GitHub Desktop.
jsDoc cheatsheet #javascript #boilerplate

jsDoc cheatsheet #javascript #boilerplate

A collection of jsDoc blocks for reference when coding in JavaScript.

'use strict';

/**
 * @fileOverview Class handling email-related functions.
 * @module Email
 */

/**
 * Class handling email-related functions. e,g, creating an email from an
 * object, checking if an email address is blacklisted etc.
 *
 * @example
 * let email = new Email();
 * email.create({ to: "me@me.com" })
 *   .then(result => {
 *     console.log(result);
 *   });
 *
 * @see https://google.com/
 */

 class Email {
  /**
   * Construct the email class.
   * @param args
   * @param [args.db] {Object} - optional db instance
   */
  constructor(args = {}) {
    /**
     * Describe the class attribute
     *
     * @type {Map}
     * @name Email#attachments
     * @example
     * this.attachments.set('foo', {});
     */
    this.attachments = new Map();    
  }

  /**
   * Examples
   *
   * Include examples whenever you can. They will add more context to your
   * modules and classes, remind you in the future how to consume your
   * instances and provide valuable help for people unfamiliar with the code.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce
   *
   * @example
   * console.log(true)
   * // expected output: true
   *
   * console.log(false)
   * // expected output: false
   */

  /**
   * Callback for adding two numbers.
   *
   * @callback addStuffCallback
   * @param {int} sum - An integer.
   */

  /**
   * Params
   *
   * @param {string} strRequired
   * @param args
   * @param [args.db] {Object} - optional db instance
   * @param {boolean} [bOptional=true]
   * @param {addStuffCallback} callback - A callback to run.
   */
  foo_param (strRequired, args = {}, bOptional = true) {
    
  }

  /**
   * Returning
   *
   * @return {Promise}
   * @return {Void} - https://stackoverflow.com/questions/4759175/how-to-return-void-in-jsdoc
   * @return {undefined} - https://stackoverflow.com/questions/4759175/how-to-return-void-in-jsdoc
   */
  
  /**
   * Types
   *
   * @type {Array}
   * @type {Array<Promises>}
   * @type {boolean}
   * @type {Map}
   * @type {Object}
   * @type {string}
   * @type {string|Object}
   */
  foo (objectOrString) {
  	if (typeof objectOrString === 'string') {
    	console.log('It is a string!');
    }
  }

  /**
   * Misc - The @abstract tag identifies members that must be implemented (or
   * overridden) by objects that inherit the member.
   *
   * @see https://docs.w3cub.com/jsdoc/tags-abstract/
   * @abstract
   * @return {Object}
   */
  toMsg() {
    throw new Error('Method "toMsg()" not implemented by subclass');
  }
}

module.exports = Email;
'use strict';

/**
 * @fileOverview Class which extends Email.
 * @module EmailParser
 * @requires Email
 */

/**
 * Class which extends Email.
 * @extends Email
 * @example
 * const email = new EmailParser({
 *   to: "me@me.com"
 * });
 * console.log(email.toMsg());
 */

class EmailParser extends Email {
  constructor(args = {}) {
    super(args);
    this.msg = args.msg;
  }
}

module.exports = Email;

/*****************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment