start implementing docusaurus bizmodel exporting

This commit is contained in:
timurgordon
2025-02-18 05:09:56 +03:00
parent 2317dd2d4c
commit 5e468359a1
5 changed files with 122 additions and 20 deletions

View File

@@ -0,0 +1,38 @@
module texttools
pub fn snake_case(s string) string {
return separate_words(s).join('_')
}
pub fn title_case(s string) string {
return separate_words(s).join(' ').title()
}
pub fn pascal_case(s string) string {
mut pascal := s.replace('_', ' ')
return pascal.title().replace(' ', '')
}
pub fn camel_case(s string) string {
return pascal_case(s).uncapitalize()
}
const separators = ['.', '_', '-', '/', ' ', ':', ',', ';']
fn separate_words(s string) []string {
mut words := []string{}
mut word := ''
for i, c in s {
if (c.is_capital() || c.ascii_str() in separators) && word != '' {
words << word.to_lower()
word = ''
}
if c.ascii_str() !in separators {
word += c.ascii_str().to_lower()
}
}
if word != '' {
words << word.to_lower()
}
return words
}