-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyProvider.js
More file actions
39 lines (31 loc) · 791 Bytes
/
keyProvider.js
File metadata and controls
39 lines (31 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var KVP = [],
keyLength = 10,
valueLength = 90;
function init(startRange, numOfKeys) {
var endRange = startRange + numOfKeys;
for (var i = startRange; i < endRange; i++) {
KVP.push({
key : i + makeString(keyLength),
value: makeString(valueLength)
});
}
}
// NOTE: will return unique KVP randomly
function getKey(index) {
return KVP[index].key;
}
function getValue(index) {
return KVP[index].value;
}
function makeString(length) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i = 0; i < length; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
module.exports = {
init: init,
getKey: getKey,
getValue: getValue
};