From 3f23299430b07e955255d2aeb505c0a6dfb7859b Mon Sep 17 00:00:00 2001 From: pyoor Date: Mon, 21 May 2018 12:04:34 -0400 Subject: [PATCH] Sort functions alphabetically --- lib/utils/script.js | 144 ++++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/lib/utils/script.js b/lib/utils/script.js index 6c730a1..fa988f6 100644 --- a/lib/utils/script.js +++ b/lib/utils/script.js @@ -8,76 +8,12 @@ const utils = require('../utils') const {o} = require('./objects') class script extends utils { - static methodHead (list, numOptional) { - if (isNaN(numOptional)) { - numOptional = 0 - } - let arity = list.length - random.number(numOptional) - let params = [] - for (let i = 0; i < arity; i++) { - params.push(random.pick([list[i]])) - } - return `(${params.join(', ')})` + static addElementToBody (name) { + return `(document.body || document.documentElement).appendChild${script.methodHead([name])}` } - static methodCall (objectName, methodHash) { - if (!utils.common.getKeysFromHash(methodHash).length || !objectName) { - return '' - } - let methodName = random.key(methodHash) - let methodArgs = methodHash[methodName] - if (typeof (methodArgs) === 'function') { // Todo: Hmmmm.. - return methodArgs() - } - return `${objectName}.${methodName}${script.methodHead(methodArgs)}` - } - - static setAttribute (objectName, attributeHash) { - if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) { - return '' - } - let attributeName = random.key(attributeHash) - let attributeValue = random.pick(attributeHash[attributeName]) - let operator = ' = ' - /* - if (typeof(attributeValue) == "number" && Random.chance(8)) { - operator = " " + Make.randomAssignmentOperator() + " "; - } - if (typeof(attributeValue) == "string") { - attributeValue = "'" + attributeValue + "'"; - } - */ - return `${objectName}.${attributeName}${operator}${attributeValue};` - } - - static makeConstraint (keys, values) { - let o = {} - let n = random.range(0, keys.length) - while (n--) { - o[random.pick(keys)] = random.pick(values) - } - return o - } - - static makeRandomOptions (baseObject) { - let o = {} - let unique = random.subset(Object.keys(baseObject)) - for (let i = 0; i < unique.length; i++) { - o[unique[i]] = random.pick(baseObject[unique[i]]) - } - return JSON.stringify(o) - } - - static safely (obj) { - if (Array.isArray(obj)) { - return obj.map(s => utils.script.safely(s)).join(' ') - } else { - return `try { ${obj} } catch(e) { }` - } - } - - static makeLoop (s, max) { - return `for (let i = 0; i < ${max || make.number.range()}; i++) {${s}}` + static getRandomElement () { + return `document.getElementsByTagName('*')[${random.number(document.getElementsByTagName('*').length)}]` } static makeArray (type, arrayLength, cb) { @@ -97,16 +33,80 @@ class script extends utils { } } + static makeConstraint (keys, values) { + let o = {} + let n = random.range(0, keys.length) + while (n--) { + o[random.pick(keys)] = random.pick(values) + } + return o + } + + static makeLoop (s, max) { + return `for (let i = 0; i < ${max || make.number.range()}; i++) {${s}}` + } + + static makeRandomOptions (baseObject) { + let o = {} + let unique = random.subset(Object.keys(baseObject)) + for (let i = 0; i < unique.length; i++) { + o[unique[i]] = random.pick(baseObject[unique[i]]) + } + return JSON.stringify(o) + } + + static methodCall (objectName, methodHash) { + if (!utils.common.getKeysFromHash(methodHash).length || !objectName) { + return '' + } + let methodName = random.key(methodHash) + let methodArgs = methodHash[methodName] + if (typeof (methodArgs) === 'function') { // Todo: Hmmmm.. + return methodArgs() + } + return `${objectName}.${methodName}${script.methodHead(methodArgs)}` + } + + static methodHead (list, numOptional) { + if (isNaN(numOptional)) { + numOptional = 0 + } + let arity = list.length - random.number(numOptional) + let params = [] + for (let i = 0; i < arity; i++) { + params.push(random.pick([list[i]])) + } + return `(${params.join(', ')})` + } + static randListIndex (objName) { return `${random.number()} % ${o.pick(objName)}.length` } - static addElementToBody (name) { - return `(document.body || document.documentElement).appendChild${script.methodHead([name])}` + static safely (obj) { + if (Array.isArray(obj)) { + return obj.map(s => utils.script.safely(s)).join(' ') + } else { + return `try { ${obj} } catch(e) { }` + } } - static getRandomElement () { - return `document.getElementsByTagName('*')[${random.number(document.getElementsByTagName('*').length)}]` + static setAttribute (objectName, attributeHash) { + if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) { + return '' + } + let attributeName = random.key(attributeHash) + let attributeValue = random.pick(attributeHash[attributeName]) + let operator = ' = ' + /* + if (typeof(attributeValue) == "number" && Random.chance(8)) { + operator = " " + Make.randomAssignmentOperator() + " "; + } + if (typeof(attributeValue) == "string") { + attributeValue = "'" + attributeValue + "'"; + } + */ + return `${objectName}.${attributeName}${operator}${attributeValue};` } }