type.js 447 B

1234567891011121314151617181920
  1. 'use strict';
  2. /*!
  3. * ignore
  4. */
  5. module.exports = function(val) {
  6. if (Array.isArray(val)) {
  7. if (!val.every(v => typeof v === 'number' || typeof v === 'string')) {
  8. throw new Error('$type array values must be strings or numbers');
  9. }
  10. return val;
  11. }
  12. if (typeof val !== 'number' && typeof val !== 'string') {
  13. throw new Error('$type parameter must be number, string, or array of numbers and strings');
  14. }
  15. return val;
  16. };