moniker icon indicating copy to clipboard operation
moniker copied to clipboard

Passing instance of Dictionary to generator() results in error

Open fortress-of-solitude opened this issue 10 years ago • 2 comments

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; };

fortress-of-solitude avatar Mar 09 '14 21:03 fortress-of-solitude

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. 😦

artlogic avatar Sep 16 '16 17:09 artlogic

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"]);

megalon avatar Aug 25 '18 06:08 megalon