octo-deno/lib/utils/block.js

41 lines
941 B
JavaScript
Raw Normal View History

2017-04-22 22:49:49 +00:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
utils.block = {
block: function (list, optional) {
2017-04-25 15:22:15 +00:00
if (optional === true) {
2017-04-22 22:49:49 +00:00
if (random.chance(6)) {
return '';
}
}
function go_deeper(item) {
2017-04-25 15:22:15 +00:00
if (item === null || item === undefined) {
2017-04-22 22:49:49 +00:00
return "";
}
2017-04-25 15:22:15 +00:00
if (typeof(item) === "function") {
2017-04-22 22:49:49 +00:00
return item();
}
2017-04-25 15:22:15 +00:00
if (typeof(item) === "string") {
2017-04-22 22:49:49 +00:00
return item;
}
if (item instanceof (Array)) {
let s = "";
for (let i = 0; i < item.length; i++) {
s += go_deeper(item[i]);
}
return s;
}
return item;
}
let asString = "";
for (let i = 0; i < list.length; i++) {
asString += go_deeper(list[i]);
}
return asString;
}
};