Use template literals throughout
This commit is contained in:
parent
cf910de0f6
commit
600bb045be
11 changed files with 62 additions and 61 deletions
|
@ -25,19 +25,19 @@ class colors extends make {
|
||||||
values = [random.number(255), random.number(255), random.number(255)]
|
values = [random.number(255), random.number(255), random.number(255)]
|
||||||
} else {
|
} else {
|
||||||
// Percents
|
// Percents
|
||||||
values = ['%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [`%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
}
|
}
|
||||||
return 'rgba(' + values.join(',') + ')'
|
return `rgba(${values.join(',')})`
|
||||||
case 1:
|
case 1:
|
||||||
// Rgba functional notation
|
// Rgba functional notation
|
||||||
values = [random.number(255), random.number(255), random.number(255), random.float()]
|
values = [random.number(255), random.number(255), random.number(255), random.float()]
|
||||||
return 'rgba(' + values.join(',') + ')'
|
return `rgba(${values.join(',')})`
|
||||||
case 2:
|
case 2:
|
||||||
// 4 char hex
|
// 4 char hex
|
||||||
return '#' + random.hex(4)
|
return `#${random.hex(4)}`
|
||||||
default:
|
default:
|
||||||
// 8 char hex
|
// 8 char hex
|
||||||
return '#' + random.hex(8)
|
return `#${random.hex(8)}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,18 +46,18 @@ class colors extends make {
|
||||||
|
|
||||||
switch (random.number(4)) {
|
switch (random.number(4)) {
|
||||||
case 0:
|
case 0:
|
||||||
values = [random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
case 1:
|
case 1:
|
||||||
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
case 2:
|
case 2:
|
||||||
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
|
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
|
||||||
values = [random.number(255) + opt, '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
|
values = [random.number(255) + opt, `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
default:
|
default:
|
||||||
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), random.float()]
|
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, random.float()]
|
||||||
return 'hsl(' + values.join(',') + ')'
|
return `hsl(${values.join(',')})`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class font extends make {
|
||||||
static family () {
|
static family () {
|
||||||
let s = random.pick(font.familyName)
|
let s = random.pick(font.familyName)
|
||||||
if (random.chance(8)) {
|
if (random.chance(8)) {
|
||||||
s += ', ' + random.pick(font.genericFamily)
|
s += `, ${random.pick(font.genericFamily)}`
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -86,16 +86,16 @@ class font extends make {
|
||||||
static font () {
|
static font () {
|
||||||
let s = ''
|
let s = ''
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += random.pick(font.style) + ' '
|
s += `${random.pick(font.style)} `
|
||||||
}
|
}
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += random.pick(font.variant) + ' '
|
s += `${random.pick(font.variant)} `
|
||||||
}
|
}
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += random.pick(font.weight) + ' '
|
s += `${random.pick(font.weight)} `
|
||||||
}
|
}
|
||||||
if (random.chance(4)) {
|
if (random.chance(4)) {
|
||||||
s += make.number.any() + '/'
|
s += `${make.number.any()}/`
|
||||||
}
|
}
|
||||||
s += font.size()
|
s += font.size()
|
||||||
s += ' '
|
s += ' '
|
||||||
|
|
|
@ -52,7 +52,7 @@ class network extends make {
|
||||||
random.pick([0, 1, make.number.any]),
|
random.pick([0, 1, make.number.any]),
|
||||||
' ',
|
' ',
|
||||||
random.pick(['UDP', 'TCP', 'SCTP']),
|
random.pick(['UDP', 'TCP', 'SCTP']),
|
||||||
random.pick(['', '/' + random.pick(['DTLS', 'DTLS-SRTP'])]),
|
random.pick(['', `/${random.pick(['DTLS', 'DTLS-SRTP'])}`]),
|
||||||
' ',
|
' ',
|
||||||
random.pick([make.number.any]),
|
random.pick([make.number.any]),
|
||||||
' ',
|
' ',
|
||||||
|
@ -117,10 +117,11 @@ class network extends make {
|
||||||
}
|
}
|
||||||
|
|
||||||
static randomIPv4 () {
|
static randomIPv4 () {
|
||||||
return random.pick([random.number(255), make.number.any]) + '.' +
|
function octet () {
|
||||||
random.pick([random.number(255), make.number.any]) + '.' +
|
return random.pick([random.number(255), make.number.any])
|
||||||
random.pick([random.number(255), make.number.any]) + '.' +
|
}
|
||||||
random.pick([random.number(255), make.number.any])
|
|
||||||
|
return `${octet()}.${octet()}.${octet()}.${octet()}.`
|
||||||
}
|
}
|
||||||
|
|
||||||
static randomIPv6 () {
|
static randomIPv6 () {
|
||||||
|
@ -188,7 +189,7 @@ class network extends make {
|
||||||
'',
|
'',
|
||||||
'#',
|
'#',
|
||||||
'#main-content',
|
'#main-content',
|
||||||
() => '#' + make.text.any()
|
() => `#${make.text.any()}`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,19 +198,19 @@ class network extends make {
|
||||||
'',
|
'',
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
() => '/' + make.text.any()
|
() => `/${make.text.any()}`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
static protocol () {
|
static protocol () {
|
||||||
return random.pick([
|
return `${random.pick([
|
||||||
'http',
|
'http',
|
||||||
'https',
|
'https',
|
||||||
'ftp',
|
'ftp',
|
||||||
'telnet',
|
'telnet',
|
||||||
'chrome',
|
'chrome',
|
||||||
'resource'
|
'resource'
|
||||||
]) + ':'
|
])}:`
|
||||||
}
|
}
|
||||||
|
|
||||||
static search () {
|
static search () {
|
||||||
|
@ -217,7 +218,7 @@ class network extends make {
|
||||||
'',
|
'',
|
||||||
'?',
|
'?',
|
||||||
'?foo=bar',
|
'?foo=bar',
|
||||||
() => '?' + make.text.any()
|
() => `?${make.text.any()}`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +229,7 @@ class network extends make {
|
||||||
let max = random.range(2, list.length)
|
let max = random.range(2, list.length)
|
||||||
let mask = random.pick(list)
|
let mask = random.pick(list)
|
||||||
for (let i = 1; i < max; i++) {
|
for (let i = 1; i < max; i++) {
|
||||||
mask += '|' + random.pick(list)
|
mask += `|${random.pick(list)}`
|
||||||
}
|
}
|
||||||
return mask
|
return mask
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,45 +10,45 @@ class typed extends make {
|
||||||
// [-128, 127]
|
// [-128, 127]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(129)
|
let value = (limit !== null) ? random.number(limit) : random.number(129)
|
||||||
value = random.chance(10) ? -value : value
|
value = random.chance(10) ? -value : value
|
||||||
return 'new Uint8Array([' + value + '])[0]'
|
return `new Uint8Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static octet (limit = null) {
|
static octet (limit = null) {
|
||||||
// [0, 255]
|
// [0, 255]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(256)
|
let value = (limit !== null) ? random.number(limit) : random.number(256)
|
||||||
return 'new Int8Array([' + value + '])[0]'
|
return `new Int8Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static short (limit = null) {
|
static short (limit = null) {
|
||||||
// [-32768, 32767]
|
// [-32768, 32767]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(32769)
|
let value = (limit !== null) ? random.number(limit) : random.number(32769)
|
||||||
value = random.chance(10) ? -value : value
|
value = random.chance(10) ? -value : value
|
||||||
return 'new Int16Array([' + value + '])[0]'
|
return `new Int16Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsignedShort (limit = null) {
|
static unsignedShort (limit = null) {
|
||||||
// [0, 65535]
|
// [0, 65535]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(65535)
|
let value = (limit !== null) ? random.number(limit) : random.number(65535)
|
||||||
return 'new Uint16Array([' + value + '])[0]'
|
return `new Uint16Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static long (limit = null) {
|
static long (limit = null) {
|
||||||
// [-2147483648, 2147483647]
|
// [-2147483648, 2147483647]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(2147483649)
|
let value = (limit !== null) ? random.number(limit) : random.number(2147483649)
|
||||||
value = random.chance(10) ? -value : value
|
value = random.chance(10) ? -value : value
|
||||||
return 'new Int32Array([' + value + '])[0]'
|
return `new Int32Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsignedLong (limit = null) {
|
static unsignedLong (limit = null) {
|
||||||
// [0, 4294967295]
|
// [0, 4294967295]
|
||||||
let value = (limit !== null) ? random.number(limit) : random.number(4294967296)
|
let value = (limit !== null) ? random.number(limit) : random.number(4294967296)
|
||||||
return 'new Uint32Array([' + value + '])[0]'
|
return `new Uint32Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static float (limit = null) {
|
static float (limit = null) {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
||||||
return 'new Float32Array([' + value + '])[0]'
|
return `new Float32Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static unrestrictedFloat (limit = null) {
|
static unrestrictedFloat (limit = null) {
|
||||||
|
@ -56,14 +56,14 @@ class typed extends make {
|
||||||
return random.pick([NaN, +Infinity, -Infinity])
|
return random.pick([NaN, +Infinity, -Infinity])
|
||||||
} else {
|
} else {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
return 'new Float32Array([' + (base + random.float()) + '])[0]'
|
return `new Float32Array([${base + random.float()}])[0]`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static double (limit = null) {
|
static double (limit = null) {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
||||||
return 'new Float64Array([' + value + '])[0]'
|
return `new Float64Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
|
|
||||||
static unrestrictedDouble (limit = null) {
|
static unrestrictedDouble (limit = null) {
|
||||||
|
@ -72,7 +72,7 @@ class typed extends make {
|
||||||
} else {
|
} else {
|
||||||
let base = (limit !== null) ? random.number(limit) : random.number()
|
let base = (limit !== null) ? random.number(limit) : random.number()
|
||||||
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
let value = random.chance(10) ? -(base + random.float()) : (base + random.float())
|
||||||
return 'new Float64Array([' + value + '])[0]'
|
return `new Float64Array([${value}])[0]`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,12 +89,12 @@ class typed extends make {
|
||||||
|
|
||||||
static arrayBuffer (byteLength = null) {
|
static arrayBuffer (byteLength = null) {
|
||||||
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
||||||
return 'new ArrayBuffer(' + length + ')'
|
return `new ArrayBuffer(${length})`
|
||||||
}
|
}
|
||||||
|
|
||||||
static dataView (byteLength = null) {
|
static dataView (byteLength = null) {
|
||||||
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
|
||||||
return 'new DataView(' + typed.arrayBuffer(length) + ')'
|
return `new DataView(${typed.arrayBuffer(length)})`
|
||||||
}
|
}
|
||||||
|
|
||||||
static typedArray (byteLength = null) {
|
static typedArray (byteLength = null) {
|
||||||
|
@ -105,14 +105,14 @@ class typed extends make {
|
||||||
'Int32', 'Uint32',
|
'Int32', 'Uint32',
|
||||||
'Float32', 'Float64'
|
'Float32', 'Float64'
|
||||||
])
|
])
|
||||||
let method = 'new ' + arrType + 'Array'
|
let method = `new ${arrType}Array`
|
||||||
switch (random.number(16)) {
|
switch (random.number(16)) {
|
||||||
case 0:
|
case 0:
|
||||||
return method + '()'
|
return `${method}()`
|
||||||
case 1:
|
case 1:
|
||||||
return method + '(' + this.typedArray() + ')'
|
return `${method}(${this.typedArray()})`
|
||||||
default:
|
default:
|
||||||
return method + '(' + length + ')'
|
return `${method}(${length})`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class unit extends make {
|
||||||
}
|
}
|
||||||
|
|
||||||
static percent () {
|
static percent () {
|
||||||
return make.number.any() + '%'
|
return `${make.number.any()}%`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class uri extends make {
|
||||||
'data:image/png,',
|
'data:image/png,',
|
||||||
'data:',
|
'data:',
|
||||||
'javascript:5555',
|
'javascript:5555',
|
||||||
'javascript:"QQQQ' + String.fromCharCode(0) + 'UUUU"',
|
`javascript:"QQQQ${String.fromCharCode(0)}UUUU"`,
|
||||||
'http://a.invalid/',
|
'http://a.invalid/',
|
||||||
'http://localhost:6/',
|
'http://localhost:6/',
|
||||||
'https://localhost:6/',
|
'https://localhost:6/',
|
||||||
|
|
|
@ -340,7 +340,7 @@ class webgl extends make {
|
||||||
]
|
]
|
||||||
if (isWebGL2) {
|
if (isWebGL2) {
|
||||||
attachment.extend([
|
attachment.extend([
|
||||||
'COLOR_ATTACHMENT' + random.range(0, 15)
|
`COLOR_ATTACHMENT${random.range(0, 15)}`
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
return random.item(attachment)
|
return random.item(attachment)
|
||||||
|
|
|
@ -7,9 +7,9 @@ const utils = require('../utils')
|
||||||
class common extends utils {
|
class common extends utils {
|
||||||
static objToString (obj) {
|
static objToString (obj) {
|
||||||
try {
|
try {
|
||||||
return '' + obj
|
return `${obj}`
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return '[' + e + ']'
|
return `[${e}]`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ class common extends utils {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
// https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem
|
||||||
if (process.browser) {
|
if (process.browser) {
|
||||||
return decodeURIComponent(atob(str).split('').map(function (c) {
|
return decodeURIComponent(atob(str).split('').map(function (c) {
|
||||||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
|
return `%${('00' + c.charCodeAt(0).toString(16)).slice(-2)}`
|
||||||
}).join(''))
|
}).join(''))
|
||||||
} else {
|
} else {
|
||||||
return Buffer.from(str, 'base64').toString('ascii')
|
return Buffer.from(str, 'base64').toString('ascii')
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Objects {
|
||||||
if (!(category in this.container)) {
|
if (!(category in this.container)) {
|
||||||
// return {type:null, name:null};
|
// return {type:null, name:null};
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new Error(category + ' is not available.')
|
throw new Error(`${category} is not available.`)
|
||||||
}
|
}
|
||||||
if (last) {
|
if (last) {
|
||||||
return this.container[category].slice(-1)[0]
|
return this.container[category].slice(-1)[0]
|
||||||
|
@ -43,7 +43,7 @@ class Objects {
|
||||||
return this.get(category, last).name
|
return this.get(category, last).name
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw logger.JSError('Error: pick(\'' + category + '\') is undefined.')
|
throw logger.JSError(`Error: pick('${category}') is undefined.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,10 @@ class platform extends utils {
|
||||||
function platformName (candidates) {
|
function platformName (candidates) {
|
||||||
for (let i = 0; i < candidates.length; i++) {
|
for (let i = 0; i < candidates.length; i++) {
|
||||||
if (candidates[i] in window) {
|
if (candidates[i] in window) {
|
||||||
return 'window.' + candidates[i]
|
return `window.${candidates[i]}`
|
||||||
}
|
}
|
||||||
if (candidates[i] in navigator) {
|
if (candidates[i] in navigator) {
|
||||||
return 'navigator.' + candidates[i]
|
return `navigator.${candidates[i]}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
|
|
|
@ -29,7 +29,7 @@ class script extends utils {
|
||||||
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
|
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
|
||||||
return methodArgs()
|
return methodArgs()
|
||||||
}
|
}
|
||||||
return objectName + '.' + methodName + script.methodHead(methodArgs)
|
return `${objectName}.${methodName}${script.methodHead(methodArgs)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
static setAttribute (objectName, attributeHash) {
|
static setAttribute (objectName, attributeHash) {
|
||||||
|
@ -47,7 +47,7 @@ class script extends utils {
|
||||||
attributeValue = "'" + attributeValue + "'";
|
attributeValue = "'" + attributeValue + "'";
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return objectName + '.' + attributeName + operator + attributeValue + ';'
|
return `${objectName}.${attributeName}${operator}${attributeValue};`
|
||||||
}
|
}
|
||||||
|
|
||||||
static makeConstraint (keys, values) {
|
static makeConstraint (keys, values) {
|
||||||
|
@ -77,7 +77,7 @@ class script extends utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
static makeLoop (s, max) {
|
static makeLoop (s, max) {
|
||||||
return 'for (let i = 0; i < ' + (max || make.number.range()) + '; i++) {' + s + '}'
|
return `for (let i = 0; i < ${max || make.number.range()}; i++) {${s}}`
|
||||||
}
|
}
|
||||||
|
|
||||||
static makeArray (type, arrayLength, cb) {
|
static makeArray (type, arrayLength, cb) {
|
||||||
|
@ -86,8 +86,8 @@ class script extends utils {
|
||||||
}
|
}
|
||||||
switch (random.number(8)) {
|
switch (random.number(8)) {
|
||||||
case 0:
|
case 0:
|
||||||
let src = 'function() { let buffer = new ' + type + 'Array(' + arrayLength + ');'
|
let src = `function() { let buffer = new ${type}Array(${arrayLength});`
|
||||||
src += script.makeLoop('buffer[i] = ' + cb() + ';', arrayLength)
|
src += script.makeLoop(`buffer[i] = ${cb()};`, arrayLength)
|
||||||
src += 'return buffer;}()'
|
src += 'return buffer;}()'
|
||||||
return src
|
return src
|
||||||
case 1:
|
case 1:
|
||||||
|
@ -98,7 +98,7 @@ class script extends utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
static randListIndex (objName) {
|
static randListIndex (objName) {
|
||||||
return random.number() + ' % ' + o.pick(objName) + '.length'
|
return `${random.number()} % ${o.pick(objName)}.length`
|
||||||
}
|
}
|
||||||
|
|
||||||
static addElementToBody (name) {
|
static addElementToBody (name) {
|
||||||
|
|
Loading…
Reference in a new issue