TypeScript types and utility functions for handling Web Annotations.

web-annotation-utils/lib/ multiplicity-utils.js
15 lines
362 B

  1. export function asArray(value) {
  2. if (Array.isArray(value))
  3. return value;
  4. if (value === undefined || value === null)
  5. return [];
  6. return [value];
  7. }
  8. export function asSingleValue(value) {
  9. if (value instanceof Array)
  10. return value[0];
  11. if (value === undefined || value === null)
  12. return undefined;
  13. return value;
  14. }