diff --git a/src/PharoStringCaseFormating-Tests/PharoStringCaseFormaterTest.class.st b/src/PharoStringCaseFormating-Tests/PharoStringCaseFormaterTest.class.st index 645d038..6dffc31 100644 --- a/src/PharoStringCaseFormating-Tests/PharoStringCaseFormaterTest.class.st +++ b/src/PharoStringCaseFormating-Tests/PharoStringCaseFormaterTest.class.st @@ -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 [ diff --git a/src/PharoStringCaseFormating/PharoStringCaseFormater.class.st b/src/PharoStringCaseFormating/PharoStringCaseFormater.class.st index a4b106f..2567fb8 100644 --- a/src/PharoStringCaseFormating/PharoStringCaseFormater.class.st +++ b/src/PharoStringCaseFormating/PharoStringCaseFormater.class.st @@ -1,3 +1,6 @@ +" +[wiki link](https://en.wikipedia.org/wiki/Naming_convention_programming) +" Class { #name : #PharoStringCaseFormater, #superclass : #Object, @@ -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 @@ -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 [