Namespace changes

This commit is contained in:
Christoph Diehl 2017-04-22 22:02:38 +03:00
parent 227f6a1958
commit 34e67a89a9
12 changed files with 64 additions and 64 deletions

View file

@ -1,7 +1,7 @@
make.arrays = { make.arrays = {
filledArray: function (fn, limit) { filledArray: function (fn, limit) {
let array = []; let array = [];
let size = limit || random.number(make.tinyNumber); let size = limit || random.number(make.numbers.tinyNumber);
for (let i = 0; i < size; i++) { for (let i = 0; i < size; i++) {
array.push(fn()); array.push(fn());

View file

@ -1,9 +1,9 @@
make.colors = { make.colors = {
colors: function() { colors: function() {
return random.pick([ return random.pick([
make.colorRGB, make.colors.colorRGB,
make.colorHSL, make.colors.colorHSL,
make.colorKeywords make.colors.colorKeywords
]); ]);
}, },

View file

@ -33,9 +33,9 @@ make.files = {
}, },
file: function () { file: function () {
return random.pick([ return random.pick([
make.image, make.files.image,
make.video, make.files.video,
make.audio make.files.audio
]); ]);
}, },
}; };

View file

@ -15,35 +15,35 @@ make.fonts = {
return ["serif", "sans-serif", "cursive", "fantasy", "monospace"]; return ["serif", "sans-serif", "cursive", "fantasy", "monospace"];
}, },
fontFamilies: function() { fontFamilies: function() {
return ['"' + "Times New Roman" + '"', "Arial", "Courier", "Helvetica"]; return ["'Times New Roman'", "Arial", "Courier", "Helvetica"];
}, },
fontFamily: function () { fontFamily: function () {
let s = random.pick(make.fontFamilies); let s = random.pick(make.fonts.fontFamilies);
if (random.chance(8)) { if (random.chance(8)) {
s += ", " + random.pick(make.fontFamiliesGeneric); s += ", " + random.pick(make.fonts.fontFamiliesGeneric);
} }
return s; return s;
}, },
fontSize: function () { fontSize: function () {
return make.unsignedNumber() + make.lengthUnit(); return make.numbers.unsignedNumber() + make.fonts.lengthUnit();
}, },
font: function () { font: function () {
let s = ""; let s = "";
if (random.chance(4)) { if (random.chance(4)) {
s += random.pick(make.fontStyles) + " "; s += random.pick(make.fonts.fontStyles) + " ";
} }
if (random.chance(4)) { if (random.chance(4)) {
s += random.pick(make.fontVariants) + " "; s += random.pick(make.fonts.fontVariants) + " ";
} }
if (random.chance(4)) { if (random.chance(4)) {
s += random.pick(make.fontWeights) + " "; s += random.pick(make.fonts.fontWeights) + " ";
} }
if (random.chance(4)) { if (random.chance(4)) {
s += make.number() + "/"; s += make.numbers.number() + "/";
} }
s += make.fontSize(); s += make.fonts.fontSize();
s += " "; s += " ";
s += Make.fontFamily(); s += Make.fonts.fontFamily();
return "'" + s + "'"; return "'" + s + "'";
} }
}; };

View file

@ -38,13 +38,13 @@ make.network = {
return ["turn", "turns", "stun", "stuns"] return ["turn", "turns", "stun", "stuns"]
}, },
randomIPv4: function() { randomIPv4: function() {
return random.pick([random.number(255), make.number]) + "." + return random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.number]) + "." + random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.number]) + "." + random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.number]); random.pick([random.number(255), make.numbers.number]);
}, },
randomIPv6: function() { randomIPv6: function() {
return "[" + make.stringFromBlocks([":", function() { return make.digitsHex(random.range(1, 4)) }]) + "]" return "[" + make.stringFromBlocks([":", function() { return make.strings.digitsHex(random.range(1, 4)) }]) + "]"
}, },
goodHostnames: function() { return [ goodHostnames: function() { return [
"0.0.0.0", "0.0.0.0",

View file

@ -19,14 +19,14 @@ make.numbers = {
return n; return n;
}, },
rangeNumber: function () { rangeNumber: function () {
return random.pick([1, 2, 3, 4, 6, 8, 16, 32, 64, make.tinyNumber]); return random.pick([1, 2, 3, 4, 6, 8, 16, 32, 64, make.numbers.tinyNumber]);
}, },
tinyNumber: function () { tinyNumber: function () {
return Math.pow(2, random.number(12)); return Math.pow(2, random.number(12));
}, },
unsignedNumber: function () { unsignedNumber: function () {
if (random.chance(2)) { if (random.chance(2)) {
return Math.abs(make.number()); return Math.abs(make.numbers.number());
} }
return Math.pow(2, random.number(65)) + random.number(3) - 1; return Math.pow(2, random.number(65)) + random.number(3) - 1;
}, },
@ -35,9 +35,9 @@ make.numbers = {
}, },
number: function () { number: function () {
let value = random.choose([ let value = random.choose([
[10, make.float], [10, make.numbers.float],
[10, [make.rangeNumber, make.tinyNumber]], [10, [make.numbers.rangeNumber, make.numbers.tinyNumber]],
[ 1, Make.unsignedNumber] [ 1, Make.numbers.unsignedNumber]
]); ]);
return random.chance(10) ? -value : value; return random.chance(10) ? -value : value;
} }

View file

@ -135,8 +135,8 @@ make.shaders = {
shaderPair: function(v, f) { shaderPair: function(v, f) {
let i = random.number(v.length); let i = random.number(v.length);
return { return {
vertex: Utils.quote(v[i].join("\n")), vertex: utils.common.quote(v[i].join("\n")),
fragment: Utils.quote(f[i].join("\n")) fragment: utils.common.quote(f[i].join("\n"))
}; };
}, },
}; };

View file

@ -6,18 +6,18 @@ make.strings = {
let s = ""; let s = "";
if (maxlen == null || maxlen === undefined) { if (maxlen == null || maxlen === undefined) {
maxlen = make.rangeNumber(); maxlen = make.numbers.rangeNumber();
} }
for (let i = 0; i < maxlen; i++) { for (let i = 0; i < maxlen; i++) {
//s += String.fromCodePoint(Random.pick(Make.layoutCharCodes)); //s += String.fromCodePoint(Random.pick(make.fonts.layoutCharCodes));
s += "A" s += "A"
} }
return s; return s;
}, },
quotedString: function (maxlen) { quotedString: function (maxlen) {
return utils.quote(make.string(maxlen)); return utils.common.quote(make.strings.string(maxlen));
}, },
stringFromBlocks: function (set, maxlen) { stringFromBlocks: function (set, maxlen) {
let s = ""; let s = "";

View file

@ -5,9 +5,9 @@ make.units = {
]); ]);
}, },
length: function () { length: function () {
return make.number() + make.lengthUnit(); return make.numbers.number() + make.units.lengthUnit();
}, },
percent: function () { percent: function () {
return make.number() + "%"; return make.numbers.number() + "%";
}, },
}; };

View file

@ -17,8 +17,8 @@ utils.block = {
return item; return item;
} }
if (item instanceof(Array)) { if (item instanceof(Array)) {
var s = ""; let s = "";
for (var i = 0; i < item.length; i++) { for (let i = 0; i < item.length; i++) {
s += go_deeper(item[i]); s += go_deeper(item[i]);
} }
return s; return s;
@ -26,8 +26,8 @@ utils.block = {
return item; return item;
} }
var asString = ""; let asString = "";
for (var i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
asString += go_deeper(list[i]); asString += go_deeper(list[i]);
} }

View file

@ -16,7 +16,7 @@ utils.common = {
}, },
getKeysFromHash: function (obj) { getKeysFromHash: function (obj) {
let list = []; let list = [];
for (var p in obj) { for (let p in obj) {
list.push(p); list.push(p);
} }
return list; return list;
@ -50,7 +50,7 @@ utils.common = {
for (let p in obj2) { for (let p in obj2) {
try { try {
if (obj2[p].constructor == Object) { if (obj2[p].constructor == Object) {
obj1[p] = Utils.mergeHash(obj1[p], obj2[p]); obj1[p] = utils.common.mergeHash(obj1[p], obj2[p]);
} else { } else {
obj1[p] = obj2[p]; obj1[p] = obj2[p];
} }

View file

@ -3,30 +3,30 @@ utils.script = {
if (isNaN(numOptional)) { if (isNaN(numOptional)) {
numOptional = 0; numOptional = 0;
} }
var arity = list.length - Random.number(numOptional); var arity = list.length - random.number(numOptional);
var params = []; var params = [];
for (var i = 0; i < arity; i++) { for (var i = 0; i < arity; i++) {
params.push(Random.pick([list[i]])); params.push(random.pick([list[i]]));
} }
return "(" + params.join(", ") + ")"; return "(" + params.join(", ") + ")";
}, },
methodCall: function (objectName, methodHash) { methodCall: function (objectName, methodHash) {
if(!Utils.getKeysFromHash(methodHash).length || !objectName) { if(!utils.common.getKeysFromHash(methodHash).length || !objectName) {
return ""; return "";
} }
var methodName = Random.key(methodHash); var methodName = random.key(methodHash);
var methodArgs = methodHash[methodName]; var methodArgs = methodHash[methodName];
if (typeof(methodArgs) == "function") { // Todo: Hmmmm.. if (typeof(methodArgs) == "function") { // Todo: Hmmmm..
return methodArgs(); return methodArgs();
} }
return objectName + "." + methodName + JS.methodHead(methodArgs); return objectName + "." + methodName + utils.script..methodHead(methodArgs);
}, },
setAttribute: function (objectName, attributeHash) { setAttribute: function (objectName, attributeHash) {
if(!Utils.getKeysFromHash(attributeHash).length || !objectName) { if(!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
return ""; return "";
} }
var attributeName = Random.key(attributeHash); var attributeName = random.key(attributeHash);
var attributeValue = Random.pick(attributeHash[attributeName]); var attributeValue = random.pick(attributeHash[attributeName]);
var operator = " = "; var operator = " = ";
/* /*
if (typeof(attributeValue) == "number" && Random.chance(8)) { if (typeof(attributeValue) == "number" && Random.chance(8)) {
@ -40,16 +40,16 @@ utils.script = {
}, },
makeConstraint: function (keys, values) { makeConstraint: function (keys, values) {
var o = {}; var o = {};
var n = Random.range(0, keys.length); var n = random.range(0, keys.length);
while (n--) { while (n--) {
o[Random.pick(keys)] = Random.pick(values); o[random.pick(keys)] = random.pick(values);
} }
return o; return o;
}, },
makeRandomOptions: function (base_o) { makeRandomOptions: function (base_o) {
var o = {}, unique = Random.some(Object.keys(base_o)); var o = {}, unique = random.some(Object.keys(base_o));
for (var i = 0; i < unique.length; i++) { for (var i = 0; i < unique.length; i++) {
o[unique[i]] = Random.pick(base_o[unique[i]]); o[unique[i]] = random.pick(base_o[unique[i]]);
} }
return JSON.stringify(o); return JSON.stringify(o);
}, },
@ -60,40 +60,40 @@ utils.script = {
return "try { " + s + " } catch(e) { }"; return "try { " + s + " } catch(e) { }";
}, },
makeLoop: function (s, max) { makeLoop: function (s, max) {
return "for (var i = 0; i < " + (max || Make.rangeNumber()) + "; i++) {" + s + "}"; return "for (var i = 0; i < " + (max || make.numbers.rangeNumber()) + "; i++) {" + s + "}";
}, },
makeArray: function (type, arrayLength, cb) { makeArray: function (type, arrayLength, cb) {
if (type == null || type === undefined) { if (type == null || type === undefined) {
type = Random.index(["Uint8", "Float32"]); type = random.index(["Uint8", "Float32"]);
} }
switch (Random.number(8)) { switch (random.number(8)) {
case 0: case 0:
var src = "function() { var buffer = new " + type + "Array(" + arrayLength + ");"; var src = "function() { var buffer = new " + type + "Array(" + arrayLength + ");";
src += JS.makeLoop("buffer[i] = " + cb() + ";", arrayLength); src += utils.script.makeLoop("buffer[i] = " + cb() + ";", arrayLength);
src += "return buffer;}()"; src += "return buffer;}()";
return src; return src;
case 1: case 1:
return "new " + type + "Array([" + Make.filledArray(cb, arrayLength) + "])"; return "new " + type + "Array([" + make.arrays.filledArray(cb, arrayLength) + "])";
default: default:
return "new " + type + "Array(" + arrayLength + ")"; return "new " + type + "Array(" + arrayLength + ")";
} }
}, },
randListIndex: function (objName) { randListIndex: function (objName) {
return Random.number() + ' % ' + o.pick(objName) + '.length'; return random.number() + ' % ' + o.pick(objName) + '.length';
}, },
addElementToBody: function (name) { addElementToBody: function (name) {
return "(document.body || document.documentElement).appendChild" + JS.methodHead([name]); return "(document.body || document.documentElement).appendChild" + utils.script..methodHead([name]);
}, },
forceGC: function () { forceGC: function () {
if (Platform.isMozilla) {} if (platform.isMozilla) {}
if (Platform.isChrome) { if (platform.isChrome) {
if (window.GCController) if (window.GCController)
return GCController.collect(); return GCController.collect();
} }
if (Platform.isSafari) {} if (platform.isSafari) {}
if (Platform.isIE) {} if (platform.isIE) {}
}, },
getRandomElement: function() { getRandomElement: function() {
return "document.getElementsByTagName('*')[" + Random.number(document.getElementsByTagName("*").length) + "]"; return "document.getElementsByTagName('*')[" + random.number(document.getElementsByTagName("*").length) + "]";
} }
}; };