cfinke / Typo.js

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

ERR_NAME_NOT_RESOLVED #85

Closed mhomol closed 3 months ago

mhomol commented 3 months ago

I'm assuming that I just don't fully understand how to use this library and need a little education.

When I try to make the following call in my web applications (within a React component, but hopefully that's not important):

const dictionary = new Typo("en_US");

I get the following error: ERR_NAME_NOT_RESOLVED

The URL it is trying to use to get a dictionary is https://dictionaries/en_US/en_US.aff. Am I supposed to bring a dictionary to the party or does this try to find one in the Chromium browser?

Any assistance anyone can lend would be greatly appreciated.

cfinke commented 3 months ago

You do need to supply the dictionary, but Typo ships with one. You could try

const dictionary = new Typo("en_US", false, false, { dictionaryPath: "typo/dictionaries" });

to get it to load the dictionary locally, assuming that the dictionary file is in typo/dictionaries/en_US/en_US.dic

mhomol commented 3 months ago

thank you. This is helping me understand it better. This is all in a React component that I'm using within a SharePoint Framework webpart, so I'm developing with Typescript and packaging it with Webpack. I think my big hurdle at the moment is in getting the dictionaries to package in the webpack and then pass the correct link to the constructor. One other thing I'm seeing in TypeScript is that the 2nd and 3rd parameters in the constructor for Typo expect a string | null parameter, so I've been passing in null, thinking that this would still default to false. Is that correct?

mhomol commented 3 months ago

Just as an FYI, the way I got through this was by passing the aff and dic as strings in the constructor.

cfinke commented 3 months ago

One other thing I'm seeing in TypeScript is that the 2nd and 3rd parameters in the constructor for Typo expect a string | null parameter, so I've been passing in null, thinking that this would still default to false. Is that correct?

Yes. In an ideal world, I would have originally chosen a better method for instantiating Typo when both affData and wordsData were going to be null, but passing null or false for those should be equivalent.