HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Developer-tool: Creates large arrays with random-strings for testing-purposes

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
randomarrayscreateswithlargetestingfordeveloperstringstool

Problem

I've made this developer-tool for my own use. Perhaps for colleagues too.

Currently I'm thinking about enhancing it. So that different data-types could be chosen.

But before that I like it to be reviewed.

Therefore: Any hints and suggestions concerning algorithm, design, user-interface, whatever welcomed.



`var textArea = document.querySelector('textarea');
var exec = document.querySelector('#exec');
var countOfStrings = document.querySelector('#count-strings');
var linebreak = document.querySelector('#linebreak');
var arrayName = document.querySelector('#array-name');
var maxSelect = document.querySelector('#max');
var separator = document.querySelector('#separator');
// Set of arbitrary words.
var words = [ 'red', 'blue', 'green', 'orange',
'yellow', 'white', 'black',
'pink', 'cyan', 'crimson',
'teal', 'lime', 'Alpha', 'Beta',
'Gamma', 'Delta', 'North',
'East', 'South', 'West' ];
// Create the options of the select-input.
(function() {
var options = '';
var currentNumber;
var i;
const max = 5;

for (i = 0; i ' + currentNumber + '\n';
}

countOfStrings.innerHTML = options;
})();

/* Creates a stringified array. This array contains
* strings as elements. Each string is made out
* of one or multiple random-words.
*
* @param { array } words - An array with strings.
* @param { number } countOfStrings - Count of strings
* within the array.
* @min { number } [min = 1] - Minimal count of random-words.
* @max { number } [max = 1] - Maximal count of random-words.
* @param { string } [separator = '-'] - Separator between the
* random-words.
* @param { boolean } [linebreak = false] - Add a linebreak
* after each element.
* @param { string } [arrayName = 'testData'] - The name to the
* returned array.
*
* @returns { string } - Stringified array in case of success.
* Empty string in case of failure.
*/
function getArrayWithTestStrings( words, co

Solution

HTML Textarea element is quite slow with very large amounts of text so you might want to use a simple yet advanced editor like CodeMirror. Even with syntax highlight enabled it's much faster than the native textarea control in the abovementioned case.

Might be useful to auto-copy the result to clipboard - add a [x] auto copy to clipboard checkbox, for example.

Showing a length of the code in characters might be useful.

`` would automatically remember past used values in autocomplete.

The log pane on the bottom doesn't seem to be meaningful. And if it is, just showing successfully completed tests in green(-ish) color or using a green mark would be much more obvious.

Context

StackExchange Code Review Q#129012, answer score: 2

Revisions (0)

No revisions yet.