Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2012 Mark Cavage, Inc. All rights reserved.
  2. var assert = require('assert');
  3. var Logger = require('bunyan');
  4. var Client = require('./client');
  5. ///--- Globals
  6. var DEF_LOG = new Logger({
  7. name: 'ldapjs',
  8. component: 'client',
  9. stream: process.stderr,
  10. serializers: Logger.stdSerializers
  11. });
  12. ///--- Functions
  13. function xor() {
  14. var b = false;
  15. for (var i = 0; i < arguments.length; i++) {
  16. if (arguments[i] && !b) {
  17. b = true;
  18. } else if (arguments[i] && b) {
  19. return false;
  20. }
  21. }
  22. return b;
  23. }
  24. ///--- Exports
  25. module.exports = {
  26. Client: Client,
  27. createClient: function createClient(options) {
  28. if (typeof (options) !== 'object')
  29. throw new TypeError('options (object) required');
  30. if (options.url && typeof (options.url) !== 'string')
  31. throw new TypeError('options.url (string) required');
  32. if (options.socketPath && typeof (options.socketPath) !== 'string')
  33. throw new TypeError('options.socketPath must be a string');
  34. if (!xor(options.url, options.socketPath))
  35. throw new TypeError('options.url ^ options.socketPath (String) required');
  36. if (!options.log)
  37. options.log = DEF_LOG;
  38. if (typeof (options.log) !== 'object')
  39. throw new TypeError('options.log must be an object');
  40. return new Client(options);
  41. }
  42. };