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.

bitwise.js 622B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*!
  2. * Module requirements.
  3. */
  4. 'use strict';
  5. const CastError = require('../../error/cast');
  6. /*!
  7. * ignore
  8. */
  9. function handleBitwiseOperator(val) {
  10. const _this = this;
  11. if (Array.isArray(val)) {
  12. return val.map(function(v) {
  13. return _castNumber(_this.path, v);
  14. });
  15. } else if (Buffer.isBuffer(val)) {
  16. return val;
  17. }
  18. // Assume trying to cast to number
  19. return _castNumber(_this.path, val);
  20. }
  21. /*!
  22. * ignore
  23. */
  24. function _castNumber(path, num) {
  25. const v = Number(num);
  26. if (isNaN(v)) {
  27. throw new CastError('number', num, path);
  28. }
  29. return v;
  30. }
  31. module.exports = handleBitwiseOperator;