{"id":17256510,"url":"https://github.com/rwbutler/lettercase","last_synced_at":"2025-04-14T06:08:35.387Z","repository":{"id":56919721,"uuid":"222729096","full_name":"rwbutler/LetterCase","owner":"rwbutler","description":"𝐓 String letter case conversion and JSON decoding / encoding strategies","archived":false,"fork":false,"pushed_at":"2025-01-20T22:51:26.000Z","size":130,"stargazers_count":20,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T06:08:29.501Z","etag":null,"topics":["carthage","codable","json","jsondecoder","jsonencoder","keydecodingstrategy","keyencodingstrategy","letter-cases","lettercase","swift","xcode"],"latest_commit_sha":null,"homepage":"https://medium.com/@rwbutler/supercharge-codable-by-implementing-a-json-key-decoding-strategy-a46fedacabc4","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rwbutler.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-19T15:32:24.000Z","updated_at":"2025-02-11T21:39:07.000Z","dependencies_parsed_at":"2022-08-20T21:50:17.627Z","dependency_job_id":null,"html_url":"https://github.com/rwbutler/LetterCase","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwbutler%2FLetterCase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwbutler%2FLetterCase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwbutler%2FLetterCase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rwbutler%2FLetterCase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rwbutler","download_url":"https://codeload.github.com/rwbutler/LetterCase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830397,"owners_count":21168272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["carthage","codable","json","jsondecoder","jsonencoder","keydecodingstrategy","keyencodingstrategy","letter-cases","lettercase","swift","xcode"],"created_at":"2024-10-15T07:14:38.030Z","updated_at":"2025-04-14T06:08:35.325Z","avatar_url":"https://github.com/rwbutler.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![LetterCase](https://github.com/rwbutler/LetterCase/raw/master/docs/images/letter-case-banner.png)\n\n[![CI Status](https://img.shields.io/travis/rwbutler/LetterCase.svg?style=flat)](https://travis-ci.org/rwbutler/LetterCase)\n[![Version](https://img.shields.io/cocoapods/v/LetterCase.svg?style=flat)](https://cocoapods.org/pods/LetterCase)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frwbutler%2FLetterCase%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/rwbutler/LetterCase)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frwbutler%2FLetterCase%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/rwbutler/LetterCase)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![License](https://img.shields.io/cocoapods/l/LetterCase.svg?style=flat)](https://cocoapods.org/pods/LetterCase)\n[![Twitter](https://img.shields.io/badge/twitter-@ross_w_butler-blue.svg?style=flat)](https://twitter.com/ross_w_butler)\n\nLightweight library written in Swift for converting the letter case of a String. For more information take a look at the [blog post](https://medium.com/@rwbutler/supercharge-codable-by-implementing-a-json-key-decoding-strategy-a46fedacabc4) or the table of contents below:\n\n- [Features](#features)\n- [Installation](#installation)\n\t- [Cocoapods](#cocoapods)\n\t- [Carthage](#carthage)\n\t- [Swift Package Manager](#swift-package-manager)\n- [Letter Cases](#letter-cases)\n- [Usage](#usage)\n- [Author](#author)\n- [License](#license)\n- [Additional Software](#additional-software)\n\t- [Frameworks](#frameworks)\n\t- [Tools](#tools)\n\n## Features\n\n- [x] Converts Strings to a variety of supported cases including: capitalized, kebab case, lower case, lower camel case, macro case, snake case, upper case and upper camel case.\n- [x] Provides conversion from any letter case to another e.g. `\"the-quick-brown-fox-jumped-over-the-lazy-dog\".convert(from: .kebab, to: .macro)` prints THE_QUICK_BROWN_FOX_JUMPED_OVER_THE_LAZY_DOG\n- [x] Implementations of `JSONDecoder.KeyDecodingStrategy` and `JSONEncoder.KeyEncodingStrategy` for decoding / encoding of JSON using `Codable` keys in just about any letter case.\n- [x] Provides convenience methods on `String` for each of the supported cases e.g. `\"The Quick Brown Fox\".kebabCased()` emits \"the-quick-brown-fox\".\n\n## Installation\n\n### Cocoapods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager which integrates dependencies into your Xcode workspace. To install it using [Ruby gems](https://rubygems.org/) run:\n\n```bash\ngem install cocoapods\n```\n\nTo install LetterCase using Cocoapods, simply add the following line to your Podfile:\n\n```ruby\npod \"LetterCase\"\n```\n\nThen run the command:\n\n```ruby\npod install\n```\n\nFor more information [see here](https://cocoapods.org/#getstarted).\n\n### Carthage\n\nCarthage is a dependency manager which produces a binary for manual integration into your project. It can be installed via [Homebrew](https://brew.sh/) using the commands:\n\n```bash\nbrew update\nbrew install carthage\n```\n\nIn order to integrate LetterCase into your project via Carthage, add the following line to your project's Cartfile:\n\n```ogdl\ngithub \"rwbutler/LetterCase\"\n```\n\nFrom the macOS Terminal run `carthage update --platform iOS` to build the framework then drag `LetterCase.framework` into your Xcode project.\n\nFor more information [see here](https://github.com/Carthage/Carthage#quick-start).\n\n### Swift Package Manager\n\nOnce you have your Swift package set up, adding LetterCase as a dependency is as easy as adding it to the dependencies value of your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/rwbutler/LetterCase\", from: \"1.6.1\")\n]\n```\n\n##### Using Xcode package list:\n\nXcode 11 includes support for [Swift Package Manager](https://swift.org/package-manager/). In order to add LetterCase to your project using Xcode, from the `File` menu select `Swift Packages` and then select `Add Package Dependency`.\n\nA dialogue will request the package repository URL which is:\n\n```\nhttps://github.com/rwbutler/LetterCase\n```\n\nAfter verifying the URL, Xcode will prompt you to select whether to pull a specific branch, commit or versioned release into your project. \n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/rwbutler/Connectivity/raw/main/docs/images/package-options.png\" alt=\"Xcode 11 Package Options\"\u003e\n\u003c/div\u003e\n\nProceed to the next step by where you will be asked to select the package product to integrate into a target. There will be a single package product named `LetterCase` which should be pre-selected. Ensure that your main app target is selected from the rightmost column of the dialog then click Finish to complete the integration.\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/rwbutler/Connectivity/raw/main/docs/images/add-package.png\" alt=\"Xcode 11 Add Package\"\u003e\n\u003c/div\u003e\n\n## Letter Cases\n\n    case regular                     // No transformation applied.\n    case capitalized                 // e.g. Capitalized Case\n    case kebab                       // e.g. kebab-case\n    case lower                       // e.g. lower case\n    case lowerCamel                  // e.g. lowerCamelCase\n    case macro                       // e.g. MACRO_CASE\n    case snake                       // e.g. snakecase\n    case upper                       // e.g. UPPER CASE\n    case upperCamel                  // e.g. UpperCamelCase\n    \n## Usage\n\nIn order to use LetterCase first import it using:\n`import LetterCase`. Then invoke one the convenience methods on `String` as follows:\n\n```swift\nlet exampleString = \"The quick brown fox jumped over the lazy dog.\"\nlet result = exampleString.letterCase(.kebab)\nprint(result)\n```\n\nResults in the following being printed:\n\n`the-quick-brown-fox-jumped-over-the-lazy-dog`\n\nAlternatively:\n\n```swift\nlet exampleString = \"The quick brown fox jumped over the lazy dog.\"\nlet result = exampleString.kebabCased()\nprint(result)\n```\n\n### LetterCase Conversion\n\nUse the convert function to convert from one letter case to another as follows:\n\n```swift\nlet input = \"the-quick-brown-fox-jumped-over-the-lazy-dog\"\nlet result = input.convert(from: .kebab, to: .capitalized)\nprint(result) // Prints \"The Quick Brown Fox Jumped Over The Lazy Dog\"\n```\n\n### JSON Decoding\n\nTo decode JSON with keys in [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) e.g.\n\n```json\n{\n    \"vehicles\": [{\n        \"name\": \"car\",\n        \"travels-on\": \"road\",\n        \"number-of-wheels\": 4\n    }, {\n        \"name\": \"boat\",\n        \"travels-on\": \"water\",\n        \"number-of-wheels\": 0\n    }, {\n        \"name\": \"train\",\n        \"travels-on\": \"rail\",\n        \"number-of-wheels\": 80\n    }, {\n        \"name\": \"plane\",\n        \"travels-on\": \"air\",\n        \"number-of-wheels\": 18\n    }]\n}\n```\n\nSpecify the `keyDecodingStrategy` as follows:\n\n```swift\nlet jsonData = try Data(contentsOf: jsonResourceURL)\nlet decoder = JSONDecoder()\ndecoder.keyDecodingStrategy = .convertFromKebabCase\nlet vehicles try decoder.decode(Vehicles.self, from: jsonData)\n```\n\nAvailable strategies include:\n\n- convertFromCapitalized\n- convertFromDashCase\n- convertFromKebabCase\n- convertFromLispCase\n- convertFromLowerCase\n- convertFromLowerCamelCase\n- convertFromMacroCase\n- convertFromScreamingSnakeCase\n- convertFromTrainCase\n- convertFromUpperCase\n- convertFromUpperCamelCase\n\n### JSON Encoding\n\nTo encode a Swift structure to JSON with keys in [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) specify the `keyEncodingStrategy` as follows:\n\n```swift\nlet encoder = JSONEncoder()\nencoder.keyEncodingStrategy = .convertToKebabCase\nlet jsonData = try encoder.encode(vehicles)\n```\n\nAvailable strategies include:\n\n- convertToCapitalized\n- convertToDashCase\n- convertToKebabCase\n- convertToLispCase\n- convertToLowerCase\n- convertToLowerCamelCase\n- convertToMacroCase\n- convertToScreamingSnakeCase\n- convertToTrainCase\n- convertToUpperCase\n- convertToUpperCamelCase\n\n## Author\n\n[Ross Butler](https://github.com/rwbutler)\n\n## License\n\nLetterCase is available under the MIT license. See the [LICENSE file](./LICENSE) for more info.\n\n## Additional Software\n\n### Controls\n\n* [AnimatedGradientView](https://github.com/rwbutler/AnimatedGradientView) - Powerful gradient animations made simple for iOS.\n\n|[AnimatedGradientView](https://github.com/rwbutler/AnimatedGradientView) |\n|:-------------------------:|\n|[![AnimatedGradientView](https://raw.githubusercontent.com/rwbutler/AnimatedGradientView/master/docs/images/animated-gradient-view-logo.png)](https://github.com/rwbutler/AnimatedGradientView) \n\n### Frameworks\n\n* [Cheats](https://github.com/rwbutler/Cheats) - Retro cheat codes for modern iOS apps.\n* [Connectivity](https://github.com/rwbutler/Connectivity) - Improves on Reachability for determining Internet connectivity in your iOS application.\n* [FeatureFlags](https://github.com/rwbutler/FeatureFlags) - Allows developers to configure feature flags, run multiple A/B or MVT tests using a bundled / remotely-hosted JSON configuration file.\n* [FlexibleRowHeightGridLayout](https://github.com/rwbutler/FlexibleRowHeightGridLayout) - A UICollectionView grid layout designed to support Dynamic Type by allowing the height of each row to size to fit content.\n* [LetterCase](https://github.com/rwbutler/LetterCase) - Lightweight library written in Swift for converting the letter case of a String.\n* [Skylark](https://github.com/rwbutler/Skylark) - Fully Swift BDD testing framework for writing Cucumber scenarios using Gherkin syntax.\n* [TailorSwift](https://github.com/rwbutler/TailorSwift) - A collection of useful Swift Core Library / Foundation framework extensions.\n* [TypographyKit](https://github.com/rwbutler/TypographyKit) - Consistent \u0026 accessible visual styling on iOS with Dynamic Type support.\n* [Updates](https://github.com/rwbutler/Updates) - Automatically detects app updates and gently prompts users to update.\n\n|[Cheats](https://github.com/rwbutler/Cheats) |[Connectivity](https://github.com/rwbutler/Connectivity) | [FeatureFlags](https://github.com/rwbutler/FeatureFlags) | [Skylark](https://github.com/rwbutler/Skylark) | [TypographyKit](https://github.com/rwbutler/TypographyKit) | [Updates](https://github.com/rwbutler/Updates) |\n|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:|\n|[![Cheats](https://raw.githubusercontent.com/rwbutler/Cheats/master/docs/images/cheats-logo.png)](https://github.com/rwbutler/Cheats) |[![Connectivity](https://github.com/rwbutler/Connectivity/raw/main/ConnectivityLogo.png)](https://github.com/rwbutler/Connectivity) | [![FeatureFlags](https://raw.githubusercontent.com/rwbutler/FeatureFlags/master/docs/images/feature-flags-logo.png)](https://github.com/rwbutler/FeatureFlags) | [![Skylark](https://github.com/rwbutler/Skylark/raw/master/SkylarkLogo.png)](https://github.com/rwbutler/Skylark) | [![TypographyKit](https://raw.githubusercontent.com/rwbutler/TypographyKit/master/docs/images/typography-kit-logo.png)](https://github.com/rwbutler/TypographyKit) | [![Updates](https://raw.githubusercontent.com/rwbutler/Updates/master/docs/images/updates-logo.png)](https://github.com/rwbutler/Updates)\n\n### Tools\n\n* [Clear DerivedData](https://github.com/rwbutler/ClearDerivedData) - Utility to quickly clear your DerivedData directory simply by typing `cdd` from the Terminal.\n* [Config Validator](https://github.com/rwbutler/ConfigValidator) - Config Validator validates \u0026 uploads your configuration files and cache clears your CDN as part of your CI process.\n* [IPA Uploader](https://github.com/rwbutler/IPAUploader) - Uploads your apps to TestFlight \u0026 App Store.\n* [Palette](https://github.com/rwbutler/TypographyKitPalette) - Makes your [TypographyKit](https://github.com/rwbutler/TypographyKit) color palette available in Xcode Interface Builder.\n\n|[Config Validator](https://github.com/rwbutler/ConfigValidator) | [IPA Uploader](https://github.com/rwbutler/IPAUploader) | [Palette](https://github.com/rwbutler/TypographyKitPalette)|\n|:-------------------------:|:-------------------------:|:-------------------------:|\n|[![Config Validator](https://raw.githubusercontent.com/rwbutler/ConfigValidator/master/docs/images/config-validator-logo.png)](https://github.com/rwbutler/ConfigValidator) | [![IPA Uploader](https://raw.githubusercontent.com/rwbutler/IPAUploader/master/docs/images/ipa-uploader-logo.png)](https://github.com/rwbutler/IPAUploader) | [![Palette](https://raw.githubusercontent.com/rwbutler/TypographyKitPalette/master/docs/images/typography-kit-palette-logo.png)](https://github.com/rwbutler/TypographyKitPalette)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwbutler%2Flettercase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frwbutler%2Flettercase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frwbutler%2Flettercase/lists"}