You have a try/catch here but you use Stream.prototype.on here
Not a big deal, but I would humbly suggest either dropping the try/catch and all the checking here or adding some kind of on/emit logic to support browsers or other non-node environments.
Your documentation implies you want to support browsers and CommonJS environments so does that mean you want a pull request for a simple on/emit?
I'm using sax-js in browser, and it tries to load stream.js
@seebees how to avoid it?
Are you objecting to the try/catch? It should not throw an error. The problem is when SAXStream tries to emit anything.
The Stream class created in the try/catch block needs to implement an on and an emit
The complexity and efficiency should be commensurate with your needs.
I just would like to avoid unnecessary 404 request of stream.js . What is correct way for it? May be there should be configurable option for disabling stream retrieving?
@danyaPostfactum Can't you use https://github.com/substack/node-browserify ?
The require('stream') call also causes issues using sax in a RequireJS environment. The problem is, that require is also defined in RequireJS but it works completely different and catches and reports the error internally. You could have a look at https://github.com/umdjs/umd for a way to load other modules in different environments.
I'm not too familiar with node, but does requiring "stream" make any sense at all when running in a browser? Maybe we could add a check for typeof window !== "undefined"?
typeof window !== "undefined"
You can do process.browser which is supported by browserify and webpack