@benev/slate
Version:
frontend web stuff
29 lines • 942 B
JavaScript
import { Bytes } from "../bytes.js";
export class Nomen {
dictionary;
patterns;
constructor(dictionary, patterns) {
this.dictionary = dictionary;
this.patterns = patterns;
}
static dictionary = (dictionary) => ({
patterns: (patterns) => (new this(dictionary, patterns)),
});
generate([firstByte, ...bytes]) {
const pattern = this.patterns[firstByte % this.patterns.length];
let index = 0;
const obtainWordChunk = (key) => {
const dictionary = this.dictionary[key];
const byte = bytes[(index++) % bytes.length];
return dictionary[byte % dictionary.length];
};
return pattern
.map(wordpattern => wordpattern.map(obtainWordChunk).join(""))
.join(" ");
}
random() {
const buffer = Bytes.random(32);
return this.generate(buffer);
}
}
//# sourceMappingURL=nomen.js.map