2017-04-22 20:16:47 +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/. */
|
|
|
|
|
2017-04-13 13:20:04 +00:00
|
|
|
utils.block = {
|
2017-04-22 20:07:29 +00:00
|
|
|
block: function (list, optional) {
|
2017-04-13 13:20:04 +00:00
|
|
|
if (optional == true) {
|
|
|
|
if (random.chance(6)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function go_deeper(item) {
|
|
|
|
if (item == null || item === undefined) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
if (typeof(item) == "function") {
|
|
|
|
return item();
|
|
|
|
}
|
|
|
|
if (typeof(item) == "string") {
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-22 20:07:29 +00:00
|
|
|
if (item instanceof (Array)) {
|
2017-04-22 19:02:38 +00:00
|
|
|
let s = "";
|
|
|
|
for (let i = 0; i < item.length; i++) {
|
2017-04-13 13:20:04 +00:00
|
|
|
s += go_deeper(item[i]);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2017-04-22 19:02:38 +00:00
|
|
|
let asString = "";
|
|
|
|
for (let i = 0; i < list.length; i++) {
|
2017-04-13 13:20:04 +00:00
|
|
|
asString += go_deeper(list[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return asString;
|
|
|
|
}
|
|
|
|
};
|