moniker
moniker copied to clipboard
Passing instance of Dictionary to generator() results in error
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; };
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. 😦
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"]);