Export namespaced browser global and support config #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently this module exports lots of global variables for the browser, this may be undesired and inflexible.
This change exports everything under a global namespaced object
parseCss
instead for the browser (Use "Css" to prevent conflict with a potential official API, which generally uses "CSS"). For other platforms like Node.js/CommonJs/AMD there is no difference.Another commit adds a
config
object to allow the user to configure the behavior of this module, such as a custom error handle for the tokenizer and parser, which can resolve issue #41. An example usage look like:Though this is still sub-optimal since a manual cleanup and a memory of the input is required before each call. For a more elegant implementation I would recommend refactoring the
tokenize()
andparse*()
methods to be classes, so that it can be like:and for parser:
Also note that this PR doesn't include a change for README yet. A thorough discussion before applying may be needed, as this is a breaking change. Any suggestion is welcome.