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

View file

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

View file

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

View file

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

View file

@ -38,13 +38,13 @@ make.network = {
return ["turn", "turns", "stun", "stuns"]
},
randomIPv4: function() {
return random.pick([random.number(255), make.number]) + "." +
random.pick([random.number(255), make.number]) + "." +
random.pick([random.number(255), make.number]) + "." +
random.pick([random.number(255), make.number]);
return random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]);
},
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 [
"0.0.0.0",

View file

@ -19,14 +19,14 @@ make.numbers = {
return n;
},
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 () {
return Math.pow(2, random.number(12));
},
unsignedNumber: function () {
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;
},
@ -35,9 +35,9 @@ make.numbers = {
},
number: function () {
let value = random.choose([
[10, make.float],
[10, [make.rangeNumber, make.tinyNumber]],
[ 1, Make.unsignedNumber]
[10, make.numbers.float],
[10, [make.numbers.rangeNumber, make.numbers.tinyNumber]],
[ 1, Make.numbers.unsignedNumber]
]);
return random.chance(10) ? -value : value;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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