trimArray util function

This commit is contained in:
Daniel Odendahl Jr
2017-11-05 15:06:37 +00:00
parent 5defa6f019
commit 4ffda3a8ae
3 changed files with 13 additions and 13 deletions
+9
View File
@@ -52,6 +52,15 @@ class Util {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
static trimArray(arr, maxLen = 10) {
if (arr.length > maxLen) {
const len = arr.length - maxLen;
arr = arr.slice(0, maxLen);
arr.push(`${len} more...`);
}
return arr;
}
static promisifyAll(obj, suffix = 'Async') {
for (const key of Object.keys(obj)) {
if (typeof obj[key] !== 'function') continue;