]> git.localhorst.tv Git - alttp.git/blobdiff - resources/js/helpers/Technique.js
tech relations
[alttp.git] / resources / js / helpers / Technique.js
index 7ec22d3b90e01df1aa9b3918643d37f9200829ff..410f01595657de34f339d8c0f88b529bbdab316c 100644 (file)
@@ -1,3 +1,12 @@
+import i18n from '../i18n';
+
+export const getRelations = (tech, type) => {
+       const rs = (tech && tech.relations) || [];
+       return type ? rs.filter(r => r && r.pivot && r.pivot.type === type) : rs;
+};
+
+export const hasRelations = (tech, type) => getRelations(tech, type).length > 0;
+
 export const getTranslation = (tech, prop, lang) => {
        const direct = tech.translations.find(t => t.locale === lang);
        if (direct) {
@@ -13,6 +22,12 @@ export const getTranslation = (tech, prop, lang) => {
 export const compareTranslation = (prop, lang) => (a, b) =>
        getTranslation(a, prop, lang).localeCompare(getTranslation(b, prop, lang));
 
+export const sorted = (techs) => [...techs].sort(compareTranslation('title', i18n.language));
+
 export default {
+       compareTranslation,
+       getRelations,
        getTranslation,
+       hasRelations,
+       sorted,
 };