The namegen5 website.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

64 lines
1.3 KiB

import wasm from "./Cargo.toml";
let rust = null;
const promise = wasm().then((res) => {
console.log(res);
rust = res;
}).catch(err => {
console.error("Rust failed to load.")
console.error("Error:", err);
return Promise.reject(err);
})
export function load() {
return promise
}
export default class NameGenerator {
constructor(data) {
console.log(rust);
if (data != null) {
this._gen = rust.WasmNameGenerator.load(JSON.stringify(data));
} else {
this._gen = rust.WasmNameGenerator.new();
}
}
get data() {
return this._gen.data();
}
generate(formatName, seed) {
return this._gen.generate_one(formatName, seed);
}
generateMany(formatName, amount, seed) {
return this._gen.generate_many(formatName, amount, seed);
}
addPart(options) {
return this._gen.add_part(options);
}
addFormat(formatName, formatStr) {
return this._gen.add_format(formatName, formatStr);
}
learn(partName, sampleSet) {
try {
this._gen.learn(partName, sampleSet)
} catch(err) {
throw new Error(err);
}
}
toJSON() {
return this.data;
}
free() {
this._gen.free();
}
}