-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormatter.ts
executable file
·34 lines (33 loc) · 1.02 KB
/
Formatter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { Column } from './DataGridVue'
/**
* @group Utilities
*/
export default {
/**
* Converts camel-cased field name to be title-cased.
* For example, firstName -> First Name
* @param value The value to convert.
*/
fromCamelCase(value: string): string {
const withSpaces = value.replace(/[A-Z]/g, (s: string): string => {
return ' ' + s
})
return withSpaces[0].toUpperCase() + withSpaces.substring(1)
},
/**
* Gets the column's title. If the column does not have a title the
* column's field name is converted to title case.
* @param column The column to create title for.
*/
columnTitle(column: Column) {
return column.title ?? this.fromCamelCase(column.field.fieldName)
},
/**
* Creates an ARIA label for the column.
* @param column The column to create label for..
*/
ariaColumnLabel(column: Column, prefix: string = '') {
const title = this.columnTitle(column)
return `${prefix} ${title ? title : 'The column does not have a title specified.'}`
},
}