Use template literals throughout

This commit is contained in:
pyoor 2018-05-21 11:50:44 -04:00
parent cf910de0f6
commit 600bb045be
11 changed files with 62 additions and 61 deletions

View file

@ -25,19 +25,19 @@ class colors extends make {
values = [random.number(255), random.number(255), random.number(255)]
} else {
// 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:
// Rgba functional notation
values = [random.number(255), random.number(255), random.number(255), random.float()]
return 'rgba(' + values.join(',') + ')'
return `rgba(${values.join(',')})`
case 2:
// 4 char hex
return '#' + random.hex(4)
return `#${random.hex(4)}`
default:
// 8 char hex
return '#' + random.hex(8)
return `#${random.hex(8)}`
}
}
@ -46,18 +46,18 @@ class colors extends make {
switch (random.number(4)) {
case 0:
values = [random.number(255), '%' + random.number(255), '%' + random.number(255)]
return 'hsl(' + values.join(',') + ')'
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`]
return `hsl(${values.join(',')})`
case 1:
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
return 'hsl(' + values.join(',') + ')'
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
return `hsl(${values.join(',')})`
case 2:
opt = random.pick(['deg', 'rad', 'grad', 'turn'])
values = [random.number(255) + opt, '%' + random.number(255), '%' + random.number(255), '%' + random.number(255)]
return 'hsl(' + values.join(',') + ')'
values = [random.number(255) + opt, `%${random.number(255)}`, `%${random.number(255)}`, `%${random.number(255)}`]
return `hsl(${values.join(',')})`
default:
values = [random.number(255), '%' + random.number(255), '%' + random.number(255), random.float()]
return 'hsl(' + values.join(',') + ')'
values = [random.number(255), `%${random.number(255)}`, `%${random.number(255)}`, random.float()]
return `hsl(${values.join(',')})`
}
}

View file

@ -58,7 +58,7 @@ class font extends make {
static family () {
let s = random.pick(font.familyName)
if (random.chance(8)) {
s += ', ' + random.pick(font.genericFamily)
s += `, ${random.pick(font.genericFamily)}`
}
return s
}
@ -86,16 +86,16 @@ class font extends make {
static font () {
let s = ''
if (random.chance(4)) {
s += random.pick(font.style) + ' '
s += `${random.pick(font.style)} `
}
if (random.chance(4)) {
s += random.pick(font.variant) + ' '
s += `${random.pick(font.variant)} `
}
if (random.chance(4)) {
s += random.pick(font.weight) + ' '
s += `${random.pick(font.weight)} `
}
if (random.chance(4)) {
s += make.number.any() + '/'
s += `${make.number.any()}/`
}
s += font.size()
s += ' '

View file

@ -52,7 +52,7 @@ class network extends make {
random.pick([0, 1, make.number.any]),
' ',
random.pick(['UDP', 'TCP', 'SCTP']),
random.pick(['', '/' + random.pick(['DTLS', 'DTLS-SRTP'])]),
random.pick(['', `/${random.pick(['DTLS', 'DTLS-SRTP'])}`]),
' ',
random.pick([make.number.any]),
' ',
@ -117,10 +117,11 @@ class network extends make {
}
static randomIPv4 () {
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]) + '.' +
random.pick([random.number(255), make.number.any])
function octet () {
return random.pick([random.number(255), make.number.any])
}
return `${octet()}.${octet()}.${octet()}.${octet()}.`
}
static randomIPv6 () {
@ -188,7 +189,7 @@ class network extends make {
'',
'#',
'#main-content',
() => '#' + make.text.any()
() => `#${make.text.any()}`
])
}
@ -197,19 +198,19 @@ class network extends make {
'',
'/',
'/index.html',
() => '/' + make.text.any()
() => `/${make.text.any()}`
])
}
static protocol () {
return random.pick([
return `${random.pick([
'http',
'https',
'ftp',
'telnet',
'chrome',
'resource'
]) + ':'
])}:`
}
static search () {
@ -217,7 +218,7 @@ class network extends make {
'',
'?',
'?foo=bar',
() => '?' + make.text.any()
() => `?${make.text.any()}`
])
}
@ -228,7 +229,7 @@ class network extends make {
let max = random.range(2, list.length)
let mask = random.pick(list)
for (let i = 1; i < max; i++) {
mask += '|' + random.pick(list)
mask += `|${random.pick(list)}`
}
return mask
}

View file

@ -10,45 +10,45 @@ class typed extends make {
// [-128, 127]
let value = (limit !== null) ? random.number(limit) : random.number(129)
value = random.chance(10) ? -value : value
return 'new Uint8Array([' + value + '])[0]'
return `new Uint8Array([${value}])[0]`
}
static octet (limit = null) {
// [0, 255]
let value = (limit !== null) ? random.number(limit) : random.number(256)
return 'new Int8Array([' + value + '])[0]'
return `new Int8Array([${value}])[0]`
}
static short (limit = null) {
// [-32768, 32767]
let value = (limit !== null) ? random.number(limit) : random.number(32769)
value = random.chance(10) ? -value : value
return 'new Int16Array([' + value + '])[0]'
return `new Int16Array([${value}])[0]`
}
static unsignedShort (limit = null) {
// [0, 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) {
// [-2147483648, 2147483647]
let value = (limit !== null) ? random.number(limit) : random.number(2147483649)
value = random.chance(10) ? -value : value
return 'new Int32Array([' + value + '])[0]'
return `new Int32Array([${value}])[0]`
}
static unsignedLong (limit = null) {
// [0, 4294967295]
let value = (limit !== null) ? random.number(limit) : random.number(4294967296)
return 'new Uint32Array([' + value + '])[0]'
return `new Uint32Array([${value}])[0]`
}
static float (limit = null) {
let base = (limit !== null) ? random.number(limit) : random.number()
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) {
@ -56,14 +56,14 @@ class typed extends make {
return random.pick([NaN, +Infinity, -Infinity])
} else {
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) {
let base = (limit !== null) ? random.number(limit) : random.number()
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) {
@ -72,7 +72,7 @@ class typed extends make {
} else {
let base = (limit !== null) ? random.number(limit) : random.number()
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) {
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
return 'new ArrayBuffer(' + length + ')'
return `new ArrayBuffer(${length})`
}
static dataView (byteLength = null) {
let length = (byteLength !== null) ? byteLength : typed.unsignedShort()
return 'new DataView(' + typed.arrayBuffer(length) + ')'
return `new DataView(${typed.arrayBuffer(length)})`
}
static typedArray (byteLength = null) {
@ -105,14 +105,14 @@ class typed extends make {
'Int32', 'Uint32',
'Float32', 'Float64'
])
let method = 'new ' + arrType + 'Array'
let method = `new ${arrType}Array`
switch (random.number(16)) {
case 0:
return method + '()'
return `${method}()`
case 1:
return method + '(' + this.typedArray() + ')'
return `${method}(${this.typedArray()})`
default:
return method + '(' + length + ')'
return `${method}(${length})`
}
}

View file

@ -17,7 +17,7 @@ class unit extends make {
}
static percent () {
return make.number.any() + '%'
return `${make.number.any()}%`
}
}

View file

@ -25,7 +25,7 @@ class uri extends make {
'data:image/png,',
'data:',
'javascript:5555',
'javascript:"QQQQ' + String.fromCharCode(0) + 'UUUU"',
`javascript:"QQQQ${String.fromCharCode(0)}UUUU"`,
'http://a.invalid/',
'http://localhost:6/',
'https://localhost:6/',

View file

@ -340,7 +340,7 @@ class webgl extends make {
]
if (isWebGL2) {
attachment.extend([
'COLOR_ATTACHMENT' + random.range(0, 15)
`COLOR_ATTACHMENT${random.range(0, 15)}`
])
}
return random.item(attachment)

View file

@ -7,9 +7,9 @@ const utils = require('../utils')
class common extends utils {
static objToString (obj) {
try {
return '' + obj
return `${obj}`
} 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
if (process.browser) {
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(''))
} else {
return Buffer.from(str, 'base64').toString('ascii')

View file

@ -30,7 +30,7 @@ class Objects {
if (!(category in this.container)) {
// return {type:null, name:null};
logger.traceback()
throw new Error(category + ' is not available.')
throw new Error(`${category} is not available.`)
}
if (last) {
return this.container[category].slice(-1)[0]
@ -43,7 +43,7 @@ class Objects {
return this.get(category, last).name
} catch (e) {
logger.traceback()
throw logger.JSError('Error: pick(\'' + category + '\') is undefined.')
throw logger.JSError(`Error: pick('${category}') is undefined.`)
}
}

View file

@ -56,10 +56,10 @@ class platform extends utils {
function platformName (candidates) {
for (let i = 0; i < candidates.length; i++) {
if (candidates[i] in window) {
return 'window.' + candidates[i]
return `window.${candidates[i]}`
}
if (candidates[i] in navigator) {
return 'navigator.' + candidates[i]
return `navigator.${candidates[i]}`
}
}
return undefined

View file

@ -29,7 +29,7 @@ class script extends utils {
if (typeof (methodArgs) === 'function') { // Todo: Hmmmm..
return methodArgs()
}
return objectName + '.' + methodName + script.methodHead(methodArgs)
return `${objectName}.${methodName}${script.methodHead(methodArgs)}`
}
static setAttribute (objectName, attributeHash) {
@ -47,7 +47,7 @@ class script extends utils {
attributeValue = "'" + attributeValue + "'";
}
*/
return objectName + '.' + attributeName + operator + attributeValue + ';'
return `${objectName}.${attributeName}${operator}${attributeValue};`
}
static makeConstraint (keys, values) {
@ -77,7 +77,7 @@ class script extends utils {
}
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) {
@ -86,8 +86,8 @@ class script extends utils {
}
switch (random.number(8)) {
case 0:
let src = 'function() { let buffer = new ' + type + 'Array(' + arrayLength + ');'
src += script.makeLoop('buffer[i] = ' + cb() + ';', arrayLength)
let src = `function() { let buffer = new ${type}Array(${arrayLength});`
src += script.makeLoop(`buffer[i] = ${cb()};`, arrayLength)
src += 'return buffer;}()'
return src
case 1:
@ -98,7 +98,7 @@ class script extends utils {
}
static randListIndex (objName) {
return random.number() + ' % ' + o.pick(objName) + '.length'
return `${random.number()} % ${o.pick(objName)}.length`
}
static addElementToBody (name) {