pandastrike / jsck

JSON Schema Compiled checK
MIT License
158 stars 14 forks source link

Is the browser a supported platform? #89

Closed tvjg closed 9 years ago

tvjg commented 9 years ago

The README says:

JSCK is the one of the fastest JSON Schema validators for Node.js.

Is jsck only intending to target Node.js? Has anyone tried running it in the browser? jsck is quite a nice looking library -- it seems a shame to limit it to the server.

automatthew commented 9 years ago

It should be bundleable with browserify or similar. I'll look into getting the tests running in browsers.

automatthew commented 9 years ago

@tvjg Proof of concept app here:

https://github.com/pandastrike/jsck/tree/89-browser-support/test/arkify

It uses another Panda Strike project, Ark, to bundle an application that uses JSCK.

Given the lack of external dependencies, it should be simple to use browserify to produce a bundle that can be used in more traditional ways.

tvjg commented 9 years ago

Thanks you for the example -- I'll dig into it more later. If I understand correctly then, any tool like browserify or ark that handles shimming the node stdlib should do fine, right?

automatthew commented 9 years ago

Yes, but even better, it looks like we don't even use any node stdlib:

$ grep -r 'require ' src
src/draft3/logical.coffee:URI = require "../uri"
src/draft3.coffee:    require "./draft3/logical"
src/draft3.coffee:    require "./draft3/numeric"
src/draft3.coffee:    require "./draft3/objects"
src/draft3.coffee:    require "./draft3/strings"
src/draft4.coffee:    require "./draft4/type"
src/draft4.coffee:    require "./draft4/logical"
src/draft4.coffee:    require "./draft4/numeric"
src/draft4.coffee:    require "./draft4/objects"
src/draft4.coffee:    require "./draft4/strings"
src/index.coffee:  draft3: require "./draft3"
src/index.coffee:  draft4: require "./draft4"
src/validator.coffee:URI = require "./uri"
src/validator.coffee:{escape, Runtime, Context} = require "./util"
src/validator.coffee:      "type": require "./common/type"
src/validator.coffee:      "numeric": require "./common/numeric"
src/validator.coffee:      "comparison": require "./common/comparison"
src/validator.coffee:      "arrays": require "./common/arrays"
src/validator.coffee:      "objects": require "./common/objects"
src/validator.coffee:      "strings": require "./common/strings"

Probably we should commit to that, so that bundling for the browser only demands support for CommonJS requires.

automatthew commented 9 years ago

Added task to use cjsify for browser build. Haven't tested the result yet.

https://github.com/pandastrike/jsck/blob/master/tasks/build/browser.coffee