rust-search-extension/extension/deminifier.js

19 lines
445 B
JavaScript
Raw Normal View History

2022-05-29 11:44:36 +00:00
class Deminifier {
constructor(mapping) {
this.mapping = mapping;
}
2022-05-29 11:44:36 +00:00
deminify(rawDescription) {
if (rawDescription === null) return null;
// Regex to globally, case-sensitively match words.
return rawDescription
.replace(/[@$^&][0-9a-zA-Z]/g, (value) => {
return this.mapping[value];
});
}
2022-05-29 11:44:36 +00:00
setMapping(mapping) {
this.mapping = mapping;
}
}