helpers.js 495 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. /*!
  3. * Module requirements.
  4. */
  5. const SchemaNumber = require('../number');
  6. /*!
  7. * @ignore
  8. */
  9. exports.castToNumber = castToNumber;
  10. exports.castArraysOfNumbers = castArraysOfNumbers;
  11. /*!
  12. * @ignore
  13. */
  14. function castToNumber(val) {
  15. return SchemaNumber.cast()(val);
  16. }
  17. function castArraysOfNumbers(arr, self) {
  18. arr.forEach(function(v, i) {
  19. if (Array.isArray(v)) {
  20. castArraysOfNumbers(v, self);
  21. } else {
  22. arr[i] = castToNumber.call(self, v);
  23. }
  24. });
  25. }