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/. */
|
|
|
|
|
2018-03-19 04:54:40 +00:00
|
|
|
const random = require('../random')
|
2018-03-19 03:23:05 +00:00
|
|
|
const utils = require('../utils')
|
|
|
|
|
|
|
|
class block extends utils {
|
|
|
|
static block (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)) {
|
2017-04-25 22:21:31 +00:00
|
|
|
return ''
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
function deeper (item) {
|
2017-04-25 15:22:15 +00:00
|
|
|
if (item === null || item === undefined) {
|
2017-04-25 22:21:31 +00:00
|
|
|
return ''
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
if (typeof (item) === 'function') {
|
|
|
|
return item()
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
if (typeof (item) === 'string') {
|
|
|
|
return item
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-06-08 13:31:41 +00:00
|
|
|
if (Array.isArray(item)) {
|
2017-04-25 22:21:31 +00:00
|
|
|
let s = ''
|
2017-04-22 22:49:49 +00:00
|
|
|
for (let i = 0; i < item.length; i++) {
|
2017-04-25 22:21:31 +00:00
|
|
|
s += deeper(item[i])
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
return s
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
return item
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
let asString = ''
|
2017-04-22 22:49:49 +00:00
|
|
|
for (let i = 0; i < list.length; i++) {
|
2017-04-25 22:21:31 +00:00
|
|
|
asString += deeper(list[i])
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:21:31 +00:00
|
|
|
return asString
|
2017-04-22 22:49:49 +00:00
|
|
|
}
|
2017-04-25 22:21:31 +00:00
|
|
|
}
|
2018-03-19 03:23:05 +00:00
|
|
|
|
|
|
|
module.exports = block
|