krg7880 / json-schema-generator

Generates draft v4 schema from a local file or a remote JSON url.
MIT License
174 stars 53 forks source link

Using the library in the browser? #11

Open wpoosanguansit opened 9 years ago

wpoosanguansit commented 9 years ago

Hi,

Is it possible to use the library in the browser? If yes, how do I package all the js file into a single for the purpose? Thanks for your help.

nickyout commented 9 years ago

Use browserify.

(edit: ./index.js already exposes ./lib/index.js nowadays)

I browserified ./index.js and that exposes the function you'll want. For example, do:

$ npm install -g browserify
$ browserify ./json-schema-generator/index.js -s jsonSchemaGenerator > jsg-browser.js

Then in a page with jsg-browser.js loaded, use:

var schema = jsonSchemaGenerator({ object: { to: { schemafiy: true } } });
// check:
console.log(JSON.stringify(schema, null, 2));

I just confirmed that this works.

wpoosanguansit commented 9 years ago

Thank you.

Sent from my iPhone

On Aug 8, 2015, at 7:58 AM, nickyout notifications@github.com wrote:

Use browserify.

I browserified ./lib/index.js and that exposes the function you'll want. For example, do:

$ npm install -g browserify $ browserify json-schema-generator/lib/index.js -s jsonSchemaGenerator > jsg-browser.js Then in a page with jsg-browser.js loaded, use:

var schema = jsonSchemaGenerator({ object: { to: { schemafiy: true } } }); // check: console.log(JSON.stringify(schema, null, 2)); I just confirmed that this works. The fact that you have to use ./lib/index.js instead of ./index.js is a bit non-intuitive though...

— Reply to this email directly or view it on GitHub.

krg7880 commented 9 years ago

Sorry @wpoosanguansit - Been very busy. Thanks @nickyout for following up. Perhaps I'll find sometime to have it readily available. Also, good to know it works with Browserify :-)