UNPKG

1.03 kBJavaScriptView Raw
1'use strict'
2
3const logger = require('../logger')
4const Client = require('./client')
5
6module.exports = {
7 Client: Client,
8 createClient: function createClient (options) {
9 if (isObject(options) === false) throw TypeError('options (object) required')
10 if (options.url && typeof options.url !== 'string' && !Array.isArray(options.url)) throw TypeError('options.url (string|array) required')
11 if (options.socketPath && typeof options.socketPath !== 'string') throw TypeError('options.socketPath must be a string')
12 if ((options.url && options.socketPath) || !(options.url || options.socketPath)) throw TypeError('options.url ^ options.socketPath (String) required')
13 if (!options.log) options.log = logger
14 if (isObject(options.log) !== true) throw TypeError('options.log must be an object')
15 if (!options.log.child) options.log.child = function () { return options.log }
16
17 return new Client(options)
18 }
19}
20
21function isObject (input) {
22 return Object.prototype.toString.apply(input) === '[object Object]'
23}