-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
45 lines (38 loc) · 1.13 KB
/
index.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
// Copyright IBM Corp. 2013. All Rights Reserved.
// Node module: strong-mq
// This file is licensed under the Artistic License 2.0.
// License text available at https://opensource.org/licenses/Artistic-2.0
// attempt to lazy-load providers on reference
var assert = require('assert');
var copy = require('underscore').clone;
var parse = require('url').parse;
function urlProvider(url) {
var protocol = parse(url).protocol;
return protocol.split(':')[0];
}
function extractProvider(options) {
var provider;
var url;
if (typeof options == 'string') {
provider = urlProvider(options);
url = options;
options = null;
} else {
provider = options.provider;
url = null;
options = copy(options);
delete options.provider;
}
assert(provider, 'options must specify the provider');
return [provider, url, options];
}
exports.create = function(options) {
var parsed = extractProvider(options || {
provider: 'native'
});
var provider = parsed[0];
var url = parsed[1];
options = parsed[2];
var Connection = require('./lib/adapters/' + provider);
return new Connection(provider, url, options);
};