X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=resources%2Fjs%2Fhelpers%2FTechnique.js;h=410f01595657de34f339d8c0f88b529bbdab316c;hb=0586e04204885088f31ac9861446eb0759cc8d2f;hp=7ec22d3b90e01df1aa9b3918643d37f9200829ff;hpb=a655f476292d8081a23653fc1b9228f4fb64faa4;p=alttp.git diff --git a/resources/js/helpers/Technique.js b/resources/js/helpers/Technique.js index 7ec22d3..410f015 100644 --- a/resources/js/helpers/Technique.js +++ b/resources/js/helpers/Technique.js @@ -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, };