forked from ttezel/twit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
46 lines (37 loc) · 1.18 KB
/
helpers.js
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
40
41
42
43
44
45
46
var EventEmitter = require('events').EventEmitter;
var stream = require('stream');
var util = require('util');
// Used to stub out calls to `request`.
exports.FakeRequest = function () {
EventEmitter.call(this)
}
util.inherits(exports.FakeRequest, EventEmitter)
exports.FakeRequest.prototype.destroy = function () {
}
// Used to stub out the http.IncomingMessage object emitted by the "response" event on `request`.
exports.FakeResponse = function (statusCode, body) {
if (!body) {
body = '';
}
this.statusCode = statusCode;
stream.Readable.call(this);
this.push(body);
this.push(null);
}
util.inherits(exports.FakeResponse, stream.Readable);
exports.FakeResponse.prototype._read = function () {
}
exports.FakeResponse.prototype.destroy = function () {
}
exports.generateRandomString = function generateRandomString (length) {
var length = length || 10
var ret = ''
var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
for (var i = 0; i < length; i++) {
// use an easy set of unicode as an alphabet - twitter won't reformat them
// which makes testing easier
ret += alphabet[Math.floor(Math.random()*alphabet.length)]
}
ret = encodeURI(ret)
return ret
}