grantila / suretype

Typesafe JSON (Schema) validator
508 stars 9 forks source link

Browser support #15

Closed hborchardt closed 3 years ago

hborchardt commented 3 years ago

Hello, I am looking into using suretype in a web project using angular, and the browser complains that the dependency awesome-ajv-errors depends on terminal-link, which depends on ansi-escapes, which is a node.js-only library.

It would be super helpful to be able to validate backend responses in my frontend using suretype, so I would like to inquire if you see any possibility to make suretype run in a browser.

If you could layout how to approach this and don't oppose the idea, I would also be happy to help with implementing this.

hborchardt commented 3 years ago

Turns out you just need to add an empty polyfill for the process.env global to the polyfills.js that is part of every angular project:

(window as any).process = {
  env: { },
};

I don't know if it should be mentioned somewhere or if this is basic knowledge. Anyway, I am glad it works now.