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.

36 lines
601 B

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