Additional JSDoc fixes
This commit is contained in:
parent
e95c56bb7f
commit
68c606d0dd
2 changed files with 46 additions and 7 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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('')
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue