Skip to content

Commit d4e32cf

Browse files
authored
refactor: item name capitalization improvements (#1730)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent e64ecca commit d4e32cf

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/components/common/SystemCommands.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@
8787
<span
8888
v-bind="attrs"
8989
class="text-wrap"
90-
style="text-transform: capitalize;"
9190
v-on="on"
92-
>{{ service.name }}</span>
91+
>{{ $filters.prettyCase(service.name) }}</span>
9392
</template>
94-
<span style="text-transform: capitalize;">{{ service.active_state }} ({{ service.sub_state }})</span>
93+
<span>{{ $filters.prettyCase(`${service.active_state} (${service.sub_state})`) }}</span>
9594
</v-tooltip>
9695
</v-list-item-title>
9796
</v-list-item-content>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import stringFormatters from '../string-formatters'
2+
3+
describe('prettyCase', () => {
4+
const sf = stringFormatters()
5+
6+
it.each([
7+
['_ hello _ _world_ ', 'Hello World'],
8+
['raspberry pi 3b+', 'Raspberry Pi 3b+'],
9+
['Raspberry Pi 3B+', 'Raspberry Pi 3B+'],
10+
['active (running)', 'Active (Running)'],
11+
])('Expects pretty case of "%s" to be "%s"', (input, expected) => {
12+
expect(sf.prettyCase(input)).toBe(expected)
13+
})
14+
})

src/util/string-formatters.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ const stringFormatters = () => {
1111
const instance = {
1212
prettyCase: (value: string) => {
1313
return value
14-
.split(/[ _]/g)
15-
.filter(x => x)
16-
.map(upperFirst)
17-
.join(' ')
14+
.replace(/[_ ]+/g, ' ')
15+
.trim()
16+
.replace(/\w+/g, match => upperFirst(match))
1817
},
1918

2019
getPixelsString: (value: number | string | undefined | null) => {

0 commit comments

Comments
 (0)