This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/src/buildTemplate.js

24 lines
719 B
JavaScript
Raw Normal View History

2020-07-22 13:19:23 -07:00
import {Template} from "./classes";
import Compressor from "./compressor";
import {templates} from "./data";
2020-07-24 07:26:03 -07:00
const templatesWithAliases = {}
for (let base in templates) {
if (templates.hasOwnProperty(base)) {
const template = templates[base];
templatesWithAliases[base] = template;
for (let alias of template.aliases) {
templatesWithAliases[alias] = template;
}
}
}
2020-07-22 13:19:23 -07:00
export default (path) => {
const templateStr = path.split(',');
2020-07-24 07:26:03 -07:00
const base = templatesWithAliases[templateStr[0]]
2020-07-22 13:19:23 -07:00
return templateStr.length === 1
2020-07-24 07:26:03 -07:00
? templatesWithAliases[templateStr[0]]
2020-07-22 13:19:23 -07:00
: Template.from(Compressor.uncompress(templateStr, base ? base.toArray() : null));
}