{"id":17090847,"url":"https://github.com/phimage/valuetransformerkit","last_synced_at":"2026-03-01T15:33:20.180Z","repository":{"id":54501786,"uuid":"87729785","full_name":"phimage/ValueTransformerKit","owner":"phimage","description":"ValueTransformer toolkit for swift","archived":false,"fork":false,"pushed_at":"2023-02-20T15:18:06.000Z","size":67,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T21:11:40.578Z","etag":null,"topics":["binding","closure","mapping","string","swift","valuetransformer"],"latest_commit_sha":null,"homepage":"","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/phimage.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"phimage","patreon":"phimage","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://www.paypal.com/paypalme2/ericphimage"}},"created_at":"2017-04-09T18:24:10.000Z","updated_at":"2023-02-20T15:17:13.000Z","dependencies_parsed_at":"2024-10-14T14:06:55.384Z","dependency_job_id":null,"html_url":"https://github.com/phimage/ValueTransformerKit","commit_stats":{"total_commits":28,"total_committers":4,"mean_commits":7.0,"dds":0.6428571428571428,"last_synced_commit":"8f40b14dd2d243898970141bb7d3d97d0026951d"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FValueTransformerKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FValueTransformerKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FValueTransformerKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phimage%2FValueTransformerKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phimage","download_url":"https://codeload.github.com/phimage/ValueTransformerKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248639484,"owners_count":21137850,"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":["binding","closure","mapping","string","swift","valuetransformer"],"created_at":"2024-10-14T13:56:53.589Z","updated_at":"2026-03-01T15:33:20.119Z","avatar_url":"https://github.com/phimage.png","language":"Swift","readme":"# ValueTransformerKit\n\n[![Build Status][build-shield]][build-url]\n[![Swift 5.1][swift-shield]][swift-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n[![MIT License][license-shield]][license-url]\n[![Sponsor][sponsor-shield]][sponsor-url]\n\u003ca href=\"https://www.patreon.com/phimage\"\u003e\n\u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" alt=\"Become a Patron!\" height=\"20\"\u003e\n\u003c/a\u003e\n\u003ca href=\"https://paypal.me/ericphimage\"\u003e\n\u003cimg src=\"https://buymecoffee.intm.org/img/button-paypal-white.png\" alt=\"Buy me a coffee\" height=\"20\"\u003e\n\u003c/a\u003e\n\nA closure and protocol based framework for [`ValueTransformer`](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ValueTransformers/ValueTransformers.html), helpful functions to register `ValueTransformer` by identifier.\n\nSee [Some implementations](#some-implementations)\n\n## Create a `ValueTransformer`\n### Using closures\n```swift\nlet transformer = ValueTransformer.closure { object in\n   return ...\n}\n```\nA `ValueTransformer` subclass is no more necessary using this method.\n\n### Using protocol implementation\nImplement `ValueTransformerType` or `ResersableValueTransformerType` and an a computed property `transformer` will be accessible.\n\n#### Using enum\nDefine your `enum`, a list of all your enum case in `transformers`, implement the function `transformedValue` of `ValueTransformerType` protocol\n```swift\nenum StringTransformers: String, ValueTransformers, ValueTransformerType {\n    case capitalized, lowercased, uppercased\n\n    public static let transformers: [StringTransformers] = [.capitalized, .lowercased, .uppercased]\n\n    public func transformedValue(_ value: Any?) -\u003e Any? { ../* string manipulation */ }\n}\n```\n\n## Register it\nYou can retrieve a value transformer using optional initializer of `ValueTransformer`: `init?(forName: NSValueTransformerName)`\n\nA protocol `ValueTransformerRegisterable` help you to register your  `ValueTransformer`\nBy providing a value transformer and an identifier `name`, a new method will be available\n```swift\nmyValueTransformer.register()\n```\n\nSo just defined an identifier `name` in your `ValueTransformerType`\n```swift\nstruct MyTransformer: ValueTransformerType, ValueTransformerRegisterable {\n    var name = NSValueTransformerName(rawValue: \"MyTransformation\")\n```\n\n### For a singleton instance\nYou can define a singleton instance using `ValueTransformerSingleton`\n```swift\nstruct MyTransformer: ValueTransformerType, ValueTransformerRegisterable, ValueTransformerSingleton {\n    var name = NSValueTransformerName(rawValue: \"MyTransformation\")\n    public static let instance = MyTransformer()\n```\nor a static function will help you to register it\n```swift\nMyTransformer.register() // same as MyTransformer.instance.register()\n```\n\n### For the previous enum example\n```swift\nenum StringTransformers: String, ValueTransformers, ValueTransformerType {\n  ...\n  var name: NSValueTransformerName {\n     return NSValueTransformerName(\"String\" + self.rawValue.capitalized)\n  }\n```\nthen you can register one by one\n```swift\nStringTransformers.capitalized.register()\n```\nor all case\n```swift\nStringTransformers.register()\n```\n\n## Some implementations ##\n\n### String\n\n- capitalized\n- uppercased\n- lowercased\n\n### Image\n\n- PNG Representation\n- JPEG Representation\n\n### Date and Time\n\n- [RFC 2822](https://www.ietf.org/rfc/rfc2822) Timestamp*\n- Using  `DateFormatter.Style`\n\n### Number\n\n- Using `NumberFormatter.Style`\n\n### Locale component\n\n- Using `NSLocale.Key`\n\n### Check if empty or not\n\n- Using `IsEmpty`(resp. `IsNotEmpty`) you could transform `String`, `NSString`, `Array`, `NSArray`, `Dictionnary`, etc... to boolean. `true`(resp. `false`) if empty\n\n## Apple Doc\nhttps://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ValueTransformers/ValueTransformers.html\n\n## License\n\nValueTransformerKit is available under the MIT license. See the LICENSE file for more info.\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n[stars-shield]: https://img.shields.io/github/stars/phimage/ValueTransformerKit.svg?style=flat\n[stars-url]: https://github.com/phimage/ValueTransformerKit/stargazers\n[issues-shield]: https://img.shields.io/github/issues/phimage/ValueTransformerKit.svg?style=flat\n[issues-url]: https://github.com/phimage/ValueTransformerKit/issues\n[license-shield]: https://img.shields.io/github/license/phimage/ValueTransformerKit.svg?style=flat\n[license-url]: https://github.com/phimage/ValueTransformerKit/blob/master/LICENSE\n[swift-shield]: https://img.shields.io/badge/Swift-5.1-orange.svg?style=flat\n[swift-url]: https://developer.apple.com/swift/\n[build-shield]: https://github.com/phimage/ValueTransformerKit/workflows/CI/badge.svg\n[build-url]: https://github.com/phimage/ValueTransformerKit/actions?workflow=CI\n[sponsor-shield]: https://img.shields.io/badge/Sponsor-%F0%9F%A7%A1-white.svg?style=flat\n[sponsor-url]: https://github.com/sponsors/phimage\n","funding_links":["https://github.com/sponsors/phimage","https://patreon.com/phimage","https://www.paypal.com/paypalme2/ericphimage","https://www.patreon.com/phimage","https://paypal.me/ericphimage"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fvaluetransformerkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphimage%2Fvaluetransformerkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphimage%2Fvaluetransformerkit/lists"}