get-rdt.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Module dependencies
  3. */
  4. // N/A
  5. /**
  6. * getRdt()
  7. *
  8. * Get the formal RDT ("RTTC display type") of the provided type schema.
  9. *
  10. * @param {Ref} typeSchema
  11. * The type schema to parse.
  12. * (Note that this should already be verified as a valid type schema.)
  13. *
  14. * @returns {String}
  15. * The formal RDT ("RTTC display type" or "RDT-formatted type") of
  16. * the specified type schema.
  17. */
  18. module.exports = function getRdt(typeSchema) {
  19. // If the type schema is a simple recognized string, then it's
  20. // already a valid RDT-- so just return it. Otherwise, it should
  21. // always be dictionary or array, so parse that and return accordingly.
  22. if (
  23. typeSchema === 'string' ||
  24. typeSchema === 'number' ||
  25. typeSchema === 'boolean' ||
  26. typeSchema === 'lamda' || //(sic)
  27. typeSchema === 'json' ||
  28. typeSchema === 'ref'
  29. ) {
  30. return typeSchema;
  31. } else if (!!typeSchema && typeof typeSchema === 'object') {
  32. return Array.isArray(typeSchema)? 'array' : 'dictionary';
  33. } else {
  34. throw new Error('Could not parse unrecognized type schema: `'+typeSchema+'`');
  35. }
  36. };