Skip to content

Commit

Permalink
add kebab case formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
badetitou committed Mar 14, 2023
1 parent 72dd221 commit e898b2e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ PharoStringCaseFormaterTest >> setUp [
formater := PharoStringCaseFormater new
]

{ #category : #test }
PharoStringCaseFormaterTest >> testAsKebabCase [

self
assert: (formater
string: 'HelloWorld';
asKebabCase)
equals: 'hello-world'
]

{ #category : #test }
PharoStringCaseFormaterTest >> testAsRealCamelCaseAlreadyCamelCase [

Expand Down
21 changes: 21 additions & 0 deletions src/PharoStringCaseFormating/PharoStringCaseFormater.class.st
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"
[wiki link](https://en.wikipedia.org/wiki/Naming_convention_programming)
"
Class {
#name : #PharoStringCaseFormater,
#superclass : #Object,
Expand All @@ -7,6 +10,14 @@ Class {
#category : #PharoStringCaseFormating
}

{ #category : #'instance creation' }
PharoStringCaseFormater class >> on: aString [

^ self new
string: aString;
yourself
]

{ #category : #converting }
PharoStringCaseFormater >> asCamelCase [
^ self string asCamelCase
Expand Down Expand Up @@ -40,6 +51,16 @@ PharoStringCaseFormater >> asExpendedString [
stream nextPut: char ] ]
]

{ #category : #converting }
PharoStringCaseFormater >> asKebabCase [

^ String streamContents: [ :stream |
self string uncapitalized do: [ :char |
char isUppercase
ifTrue: [ stream << '-' << char asLowercase ]
ifFalse: [ stream << char ] ] ]
]

{ #category : #converting }
PharoStringCaseFormater >> asRealCamelCase [

Expand Down

0 comments on commit e898b2e

Please sign in to comment.