lenses.js 717 B

12345678910111213141516171819202122232425262728
  1. import jsonLens from "./jsonLens"
  2. import rawLens from "./rawLens"
  3. import imageLens from "./imageLens"
  4. import htmlLens from "./htmlLens"
  5. import xmlLens from "./xmlLens"
  6. export const lenses = [jsonLens, imageLens, htmlLens, xmlLens, rawLens]
  7. export function getSuitableLenses(response) {
  8. const contentType = response.headers.find((h) => h.key === "content-type")
  9. if (!contentType) return [rawLens]
  10. const result = []
  11. for (const lens of lenses) {
  12. if (lens.isSupportedContentType(contentType.value)) result.push(lens)
  13. }
  14. return result
  15. }
  16. export function getLensRenderers() {
  17. const response = {}
  18. for (const lens of lenses) {
  19. response[lens.renderer] = lens.rendererImport
  20. }
  21. return response
  22. }