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.

assert.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 Joyent, Inc.
  2. var assert = require('assert');
  3. var util = require('util');
  4. var isDN = require('./dn').DN.isDN;
  5. var isAttribute = require('./attribute').isAttribute;
  6. ///--- Helpers
  7. // Copied from mcavage/node-assert-plus
  8. function _assert(arg, type, name) {
  9. name = name || type;
  10. throw new assert.AssertionError({
  11. message: util.format('%s (%s) required', name, type),
  12. actual: typeof (arg),
  13. expected: type,
  14. operator: '===',
  15. stackStartFunction: _assert.caller
  16. });
  17. }
  18. ///--- API
  19. function stringDN(input, name) {
  20. if (isDN(input) || typeof (input) === 'string')
  21. return;
  22. _assert(input, 'DN or string', name);
  23. }
  24. function optionalStringDN(input, name) {
  25. if (input === undefined || isDN(input) || typeof (input) === 'string')
  26. return;
  27. _assert(input, 'DN or string', name);
  28. }
  29. function optionalDN(input, name) {
  30. if (input !== undefined && !isDN(input))
  31. _assert(input, 'DN', name);
  32. }
  33. function optionalArrayOfAttribute(input, name) {
  34. if (input === undefined)
  35. return;
  36. if (!Array.isArray(input) ||
  37. input.some(function (v) { return !isAttribute(v); })) {
  38. _assert(input, 'array of Attribute', name);
  39. }
  40. }
  41. ///--- Exports
  42. module.exports = {
  43. stringDN: stringDN,
  44. optionalStringDN: optionalStringDN,
  45. optionalDN: optionalDN,
  46. optionalArrayOfAttribute: optionalArrayOfAttribute
  47. };