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

configurable splitPattern in line-navigator.js #3

Closed
frasator opened this issue Mar 29, 2016 · 5 comments
Closed

configurable splitPattern in line-navigator.js #3

frasator opened this issue Mar 29, 2016 · 5 comments

Comments

@frasator
Copy link

Could be possible to set the splitPattern variable using the options object in the FileNavigator and LineNavigator constructor?

@anpur
Copy link
Collaborator

anpur commented Mar 29, 2016

Added, you can pass it to FileNavigator or LineNavigator constructor as you've asked:

var navigator = new FileNavigator(file, undefined, { 
    newLineCode: '\n'.charCodeAt(0), 
    splitPattern: /\r?\n/
});

Please notice, that both newLineCode and splitPattern are used for splitting: newLineCode used to split data to big chunks and then they are separated to lines via splitPattern.

That is limiting in the sense that every line have to end with newLineCode byte and any newLineCode will be treated as line end, so one can't have line separator with two or more characters.

For example: You can't use "END" as separator for "EXAMPLE DATA:ENDLine oneENDline twoENDline threeEND" file, as newLineCode have to by 'D'.charCodeAt(0) so line could be accidentally spited here: "EXAMPLE DATA"

P.S. - module now available as NPM package too.

@frasator
Copy link
Author

Thanks for the update.

I want to explain my case, first of all (we all know this):
The operative systems uses different characters to delimit lines. Windows uses two characters the CR LF sequence; Unix only uses LF and MacIntosh CR.
Which CR is \r and LF is \n.

So,
When I use the library with a file that uses only '\r' to delimit lines it only reads one line, in the other cases ('\r\n' and '\n') works fine.

Is it possible to make it work when using '\r' too?.
I thought it would be possible using newLineCode and splitPattern but maybe there is a better workaround.

Thanks again.

@anpur
Copy link
Collaborator

anpur commented Mar 29, 2016

Right now line navigator supports both \r\n and \n line endings by default, as you've said.

You can also make it Mac OS friendly by accepting \r line endings with this new options:

var navigator = new FileNavigator(file, undefined, { 
    newLineCode: '\r'.charCodeAt(0), 
    splitPattern: /\r/
});

So far I see only one technical possibility to make line-navigator to accept both types simultaniously, but this will require more complex, error-prone logic, which I don't want to mix there.

Thanks for your interest and let me know if this solution fits your case.

@frasator
Copy link
Author

It's OK, I will detect it before use navigator to pass the options according to the case.

Thank you again.

@anpur
Copy link
Collaborator

anpur commented Jul 31, 2016

Hey, just in case you're still using line-navigator check out latest version. Now it supports all types of line endings: CR LF, LF, CR.

Also, it was totally refactored, cleaned, and few hidden issues fixed.

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