Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency on fs #1

Open
Awnage opened this issue Oct 13, 2017 · 1 comment
Open

Dependency on fs #1

Awnage opened this issue Oct 13, 2017 · 1 comment

Comments

@Awnage
Copy link

Awnage commented Oct 13, 2017

Is there a way of doing a validation without needing the fs library? Given the README example it seems like it would be possible.
var results = validator.validate(xml, schematron);
both the xml and schematron variables are strings after toString().

@TimLuq
Copy link

TimLuq commented Mar 17, 2018

My PR #2 resolves this issue by only loading readFile from fs if necessary. If you never use any file paths it will never import the library. It still has a guaranteed runtime dependency to the xpath library, though.

It is unclear from your comment if you're sending objects with a toString() method to validate() or you're sending strings (perhaps from earlier call to toString()) as parameters? The function call expects the parameters to already be strings and detects if it's a filepath/URL or serialized XML by checking if the first non-whitespace character is <.

After my PR is applied fs is imported when it detects a filepath, node-fetch is imported when it detects an URL and no fetch() is available in the global scope, and otherwise no library for loading external data is imported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants