draft-redmine_users_from_csv/utils.ts

37 lines
786 B
TypeScript
Raw Normal View History

export function sanitize(str: string): string {
2024-01-15 21:59:22 +01:00
return str.replaceAll(' ', '_')
}
export function capitalize(str: string): string {
2024-01-15 21:59:22 +01:00
return str
.split(' ')
.map((word) => word.split(''))
.map(([firstLetter, ...tail]) =>
`${firstLetter.toLocaleUpperCase()}${tail.join().toLocaleLowerCase()}`
)
.join(' ')
}
export function toLogin(firstname: string, lastname: string): string {
2024-01-15 21:59:22 +01:00
return `${sanitize(firstname.toLocaleLowerCase())}.${
sanitize(lastname.toLocaleLowerCase())
}`
}
export const log = {
info(message: string) {
console.log(
`%c[info]%c ${message}`,
'color: cyan; font-weight: bold',
'color: white',
)
},
error(message: string) {
console.error(
`%c[error]%c ${message}`,
'color: red; font-weight: bold',
'color: white',
)
},
}