index.js 1023 B

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