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

Passing instance of Dictionary to generator() results in error #2

Open
fortress-of-solitude opened this issue Mar 9, 2014 · 2 comments

Comments

@fortress-of-solitude
Copy link

It appears that when an instance of Dictionary is passed into generator(dictionaries, options) the error 'unrecognized dictionary type' is encountered.

Generator.prototype.use = function(dict, opt) {
var dicts = this.dicts;

if (dict instanceof Dictionary)
dicts.push(dict);
if (typeof dict == 'string')
dicts.push((new Dictionary()).read(dict, opt));
else if (typeof dict == 'function')
dicts.push(dict(opt));
else
next(new Error('unrecognized dictionary type'));

return this;
};

@artlogic
Copy link

I'm seeing this problem as well. The second if should be an else if. Also, the next should probably be throw, like so:

Generator.prototype.use = function(dict, opt) {
  var dicts = this.dicts;

  if (dict instanceof Dictionary)
    dicts.push(dict);
  else if (typeof dict == 'string')
    dicts.push((new Dictionary()).read(dict, opt));
  else if (typeof dict == 'function')
    dicts.push(dict(opt));
  else
    throw new Error('unrecognized dictionary type');

  return this;
};

I'd be happy to submit a pull request... but it's not clear if this repo is abandoned. 😦

@megalon
Copy link

megalon commented Aug 25, 2018

This issue still exists.
You can work around it by simply passing the path to your text files instead of the dictionary instances.

Example:

var monikerNames = Moniker.generator(["./adjectives.txt", "./nouns.txt"]);

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

3 participants