Additional JSDoc fixes

This commit is contained in:
pyoor 2018-08-13 10:59:05 -04:00
parent e95c56bb7f
commit 68c606d0dd
2 changed files with 46 additions and 7 deletions

View File

@ -81,7 +81,7 @@ class random {
/** /**
* Returns a random index from a list * Returns a random index from a list
* @param {Array} list * @param {Array} list
* @returns list[n] * @returns {*}
*/ */
static item (list) { static item (list) {
if (!Array.isArray(list)) { if (!Array.isArray(list)) {

View File

@ -5,6 +5,11 @@ const jsesc = require('jsesc')
const utils = require('../utils') const utils = require('../utils')
class common extends utils { class common extends utils {
/**
* Return stringified object
* @param obj
* @returns {string}
*/
static objToString (obj) { static objToString (obj) {
try { try {
return `${obj}` return `${obj}`
@ -13,6 +18,11 @@ class common extends utils {
} }
} }
/**
* Return enumerable properties recursively
* @param obj
* @returns {Array}
*/
static getAllProperties (obj) { static getAllProperties (obj) {
let list = [] let list = []
while (obj) { while (obj) {
@ -22,6 +32,11 @@ class common extends utils {
return list return list
} }
/**
* Return all properties (non-recursive)
* @param obj
* @returns {Array}
*/
static getKeysFromHash (obj) { static getKeysFromHash (obj) {
let list = [] let list = []
for (let p in obj) { for (let p in obj) {
@ -32,8 +47,8 @@ class common extends utils {
/** /**
* Escape and quote a string * Escape and quote a string
* @param s {string} - String to be quoted * @param s - String to be quoted
* @param html {boolean} - Identifies whether the string must be HTML safe * @param {boolean} html - Identifies whether the string must be HTML safe
* @returns {*} * @returns {*}
*/ */
static quote (s, html = false) { 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) { 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) { if (process.browser) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes (match, p1) { 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) { 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) { if (process.browser) {
return decodeURIComponent(atob(str).split('').map(function (c) { return decodeURIComponent(atob(str).split('').map(function (c) {
return `%${('00' + c.charCodeAt(0).toString(16)).slice(-2)}` 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) { static uniqueList (list) {
let tmp = {} let tmp = {}
let r = [] let r = []
@ -88,6 +116,12 @@ class common extends utils {
return r return r
} }
/**
* Merge two objects recursively
* @param {Object} obj1
* @param {Object} obj2
* @returns {*}
*/
static mergeHash (obj1, obj2) { static mergeHash (obj1, obj2) {
for (let p in obj2) { for (let p in obj2) {
try { try {
@ -103,6 +137,11 @@ class common extends utils {
return obj1 return obj1
} }
/**
* Template string beautifier
* @param {Object} obj
* @returns {string}
*/
static mockup (obj) { static mockup (obj) {
return obj.split('\n').map((ln) => ln.trim()).join('') return obj.split('\n').map((ln) => ln.trim()).join('')
} }