json-schema-generator icon indicating copy to clipboard operation
json-schema-generator copied to clipboard

Using the library in the browser?

Open wpoosanguansit opened this issue 9 years ago • 3 comments

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.

wpoosanguansit avatar Jul 13 '15 14:07 wpoosanguansit

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.

nickyout avatar Aug 08 '15 11:08 nickyout

Thank you.

Sent from my iPhone

On Aug 8, 2015, at 7:58 AM, nickyout [email protected] 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.

wpoosanguansit avatar Aug 11 '15 19:08 wpoosanguansit

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 :-)

krg7880 avatar Aug 11 '15 19:08 krg7880