28 lines
766 B
TypeScript
28 lines
766 B
TypeScript
import app from '@adonisjs/core/services/app'
|
|
|
|
export function capitalize(str: string) {
|
|
return str.charAt(0).toUpperCase() + str.slice(1)
|
|
}
|
|
|
|
export function camelCase(str: string) {
|
|
return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase())
|
|
}
|
|
|
|
export function pascalCase(str: string) {
|
|
return capitalize(camelCase(str))
|
|
}
|
|
|
|
// Naive singularization used for generated file names ("posts" -> "post"):
|
|
// simply drops the trailing character.
|
|
export function singularize(str: string) {
|
|
return str.slice(0, str.length - 1)
|
|
}
|
|
|
|
export function tableToModelName(tableName: string): string {
|
|
return app.generators.modelName(tableName)
|
|
}
|
|
|
|
export function tableToModelSchemaName(tableName: string): string {
|
|
return app.generators.modelName(tableName) + 'Schema'
|
|
}
|