From 68c606d0dd3c74f7b3a2b0408b9aa1654cbc3bfe Mon Sep 17 00:00:00 2001 From: pyoor Date: Mon, 13 Aug 2018 10:59:05 -0400 Subject: [PATCH] Additional JSDoc fixes --- lib/random/random.js | 2 +- lib/utils/common.js | 51 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/lib/random/random.js b/lib/random/random.js index 3a86f64..ec87107 100644 --- a/lib/random/random.js +++ b/lib/random/random.js @@ -81,7 +81,7 @@ class random { /** * Returns a random index from a list * @param {Array} list - * @returns list[n] + * @returns {*} */ static item (list) { if (!Array.isArray(list)) { diff --git a/lib/utils/common.js b/lib/utils/common.js index d30f0ed..d35f2ef 100644 --- a/lib/utils/common.js +++ b/lib/utils/common.js @@ -5,6 +5,11 @@ const jsesc = require('jsesc') const utils = require('../utils') class common extends utils { + /** + * Return stringified object + * @param obj + * @returns {string} + */ static objToString (obj) { try { return `${obj}` @@ -13,6 +18,11 @@ class common extends utils { } } + /** + * Return enumerable properties recursively + * @param obj + * @returns {Array} + */ static getAllProperties (obj) { let list = [] while (obj) { @@ -22,6 +32,11 @@ class common extends utils { return list } + /** + * Return all properties (non-recursive) + * @param obj + * @returns {Array} + */ static getKeysFromHash (obj) { let list = [] for (let p in obj) { @@ -32,8 +47,8 @@ class common extends utils { /** * Escape and quote a string - * @param s {string} - String to be quoted - * @param html {boolean} - Identifies whether the string must be HTML safe + * @param s - String to be quoted + * @param {boolean} html - Identifies whether the string must be HTML safe * @returns {*} */ static quote (s, html = false) { @@ -49,9 +64,13 @@ class common extends utils { } } + /** + * Unicode safe b64 encoding + * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem + * @param {string} str + * @returns {*} + */ static b64encode (str) { - // Unicode safe b64 encoding - // https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem if (process.browser) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function toSolidBytes (match, p1) { @@ -64,9 +83,13 @@ class common extends utils { } } + /** + * Unicode safe b64 decoding + * https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem + * @param {string} str + * @returns {*} + */ static b64decode (str) { - // Unicode safe b64 decoding - // https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem if (process.browser) { return decodeURIComponent(atob(str).split('').map(function (c) { return `%${('00' + c.charCodeAt(0).toString(16)).slice(-2)}` @@ -76,6 +99,11 @@ class common extends utils { } } + /** + * Remove duplicate items from a list + * @param {Array} list + * @returns {Array} + */ static uniqueList (list) { let tmp = {} let r = [] @@ -88,6 +116,12 @@ class common extends utils { return r } + /** + * Merge two objects recursively + * @param {Object} obj1 + * @param {Object} obj2 + * @returns {*} + */ static mergeHash (obj1, obj2) { for (let p in obj2) { try { @@ -103,6 +137,11 @@ class common extends utils { return obj1 } + /** + * Template string beautifier + * @param {Object} obj + * @returns {string} + */ static mockup (obj) { return obj.split('\n').map((ln) => ln.trim()).join('') }