Skip to content

Commit

Permalink
feat: extract formatter to sep file
Browse files Browse the repository at this point in the history
  • Loading branch information
FrantisekMichalSebestyen committed Oct 6, 2023
1 parent 4fbc956 commit f9ecc88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion resources/js/components/catalog-new/AuthorFormatter.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<template>
{{ value.replace(/^([^,]*),\s*(.*)$/, '$2 $1') }}
{{ formatAuthorName }}
</template>

<script>
import { formatAuthorName } from './formatters'
export default {
props: {
value: String,
},
computed: {
formatAuthorName: function () {
return formatAuthorName(this.value)
},
},
}
</script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script>
import { matchSorter } from 'match-sorter'
import { formatAuthorName } from './formatters'
export default {
props: ['options', 'selected'],
Expand All @@ -22,7 +23,7 @@ export default {
.map((selected) => ({ value: selected, count: 0, checked: true })),
]
return matchSorter(optionsWithSelected, this.search, {
keys: [(option) => option.value.replace(/^([^,]*),\s*(.*)$/, '$2 $1')],
keys: [(option) => formatAuthorName(option.value)],
})
},
},
Expand Down
3 changes: 3 additions & 0 deletions resources/js/components/catalog-new/formatters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function formatAuthorName(value) {
return value.replace(/^([^,]*),\s*(.*)$/, '$2 $1')
}

0 comments on commit f9ecc88

Please sign in to comment.