Swift package
Consistent tokenization and casing for identifiers, filenames, and generated code
Project-local casing helpers tend to disagree around acronyms, separators, and numbers. Casification tokenizes first, then applies a reusable modifier with consistent policy.
"some URL value".case(.camel) // someURLValue
"some URL value".case(.pascal) // SomeURLValue
"some URL value".case(.snake) // some_url_value
"some URL value".case(.kebab) // some-url-value
"some URL value".case(.dot) // some.url.value
Configure application-wide acronym policy during startup when the same vocabulary should apply everywhere.
String.Casification.prepareConfiguration {
$0.acronyms.formUnion(["uml", "Uml", "UML"])
$0.camelCase.acronyms.processingPolicy = .alwaysCapitalize
}
"uml_diagram".case(.pascal) // UMLDiagram
prepareConfiguration changes the shared baseline, so feature code should not call it repeatedly.
Generated code often has a vocabulary that should not affect the rest of an application. withAcronyms scopes those spellings to a single transformation:
let symbolName = withAcronyms({
$0.formUnion(["gpu", "Gpu", "GPU"])
}) {
"gpu_frame_time".case(.pascal)
}
// GPUFrameTime
Use withCasification when the operation needs to override more than its acronym set:
let propertyName = withCasification({
$0.acronyms.formUnion(["api", "Api", "API"])
$0.camelCase.acronyms.processingPolicy = .alwaysCapitalize
}) {
"api response value".case(.camel)
}
// APIResponseValue
Both helpers also provide actor-aware asynchronous overloads, so scoped policy can stay attached to asynchronous generation work without changing the application-wide baseline.
Modifiers compose from left to right, so more specialized transforms remain explicit and testable.
let normalized = "myString".case(
.lower.combined(with: .upperFirst)
)
When predefined modifiers are not enough, implement a direct Modifier or process semantic tokens through TokenProcessor and TokensProcessor. Prefer token processing for generated identifiers so word, number, acronym, and separator behavior remains visible.
| Layer | Reach for it when |
|---|---|
| Predefined modifiers | You need camel, Pascal, snake, kebab, dot, or direct letter transforms |
combined(with:) | Existing modifiers describe the transform in stages |
withAcronyms | One task needs a scoped acronym vocabulary |
withCasification | One operation needs a complete scoped configuration |
Modifier | A direct substring transform is enough |
TokenProcessor / TokensProcessor | Words, numbers, acronyms, and separators need semantic handling |
Choose the narrowest configuration scope that expresses the policy: startup configuration for application-wide conventions, withAcronyms for a local vocabulary, and withCasification for a complete local override.