cfinke / Typo.js

A client-side JavaScript spellchecker that uses Hunspell-style dictionaries.
Other
501 stars 110 forks source link

Relative paths for dictionary directories [node] #38

Open JuanCaicedo opened 8 years ago

JuanCaicedo commented 8 years ago

I found that if I try to give Typo a relative path to my dictionaries in node, it throws an error like

Path ../../dictionaries/en_US/en_US.dic does not exist.

I think that's happening because of this check, which will be relative to node_module/typo-js/typo.js

if (fs.existsSync(path)) {

I think it can be fixed by something like, which works for me locally.

var _path = require('path')
...
path = _path.join(__dirname, path);
if (fs.existsSync(path)) {

I can make a PR to update this

JuanCaicedo commented 8 years ago

Actually, it might be better to just document that the user should provide an absolute path to Typo, which they can get using the path.join. I think that's more robust in the long run

cfinke commented 8 years ago

Agreed on just documenting the path argument as an absolute path.

mstamatiadou commented 8 years ago

Hi,

I am trying to use the library and I 'm still getting Error: ENOENT, no such file or directory for the dictionaries path. Giving the absolute path still doesn't work for me. I also saw in your code that fs.existsSync(path) (line 167) is deprecated and I changed it to fs.statSync(path) but it did not work either.

Could you please suggest something?

JuanCaicedo commented 8 years ago

@Stoup I think it would be best for you to open up a stackoverflow question and post some more details about your code, otherwise it's difficult to help