2017-06-08 04:15:20 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
utils.mutate = {
|
|
|
|
text: function (str) {
|
|
|
|
let mutator = function (m) {
|
|
|
|
return random.number(4) === 1 ? m : make.text.any()
|
|
|
|
}
|
|
|
|
return str.replace(/[a-zA-Z]+?/g, mutator)
|
|
|
|
},
|
|
|
|
|
|
|
|
numbers: function (str) {
|
|
|
|
let mutator = function (m) {
|
|
|
|
return random.number(4) === 1 ? m : make.number.any()
|
|
|
|
}
|
|
|
|
return str.replace(/-?\d+(\.\d+)?/g, mutator)
|
|
|
|
},
|
|
|
|
|
|
|
|
units: function (str) {
|
|
|
|
let mutator = function (m) {
|
|
|
|
return random.number(4) === 1 ? m : make.unit.unit()
|
|
|
|
}
|
|
|
|
return str.replace(/(px|em|ex|ch|rem|mm|cm|in|pt|pc|%')/g, mutator)
|
|
|
|
},
|
|
|
|
|
|
|
|
random: function (str) {
|
|
|
|
let mutator = function (m) {
|
|
|
|
if (random.number(20) === 1) {
|
|
|
|
if (str.match(/[0-9]/g)) {
|
|
|
|
return make.number.any()
|
|
|
|
} else {
|
|
|
|
return make.text.any()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str.replace(/./g, mutator)
|
|
|
|
},
|
|
|
|
|
|
|
|
any: function (str) {
|
2017-06-08 04:18:33 +00:00
|
|
|
switch (random.number(4)) {
|
2017-06-08 04:15:20 +00:00
|
|
|
case 0:
|
|
|
|
return utils.mutate.text(str)
|
|
|
|
case 1:
|
|
|
|
return utils.mutate.numbers(str)
|
|
|
|
case 2:
|
|
|
|
return utils.mutate.units(str)
|
2017-06-08 04:18:33 +00:00
|
|
|
case 3:
|
|
|
|
return utils.mutate.random(str)
|
2017-06-08 04:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|