{"id":21619088,"url":"https://github.com/bannzai/utilitytype","last_synced_at":"2025-03-16T00:07:29.948Z","repository":{"id":174297041,"uuid":"650897112","full_name":"bannzai/UtilityType","owner":"bannzai","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-13T05:42:36.000Z","size":115,"stargazers_count":90,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-10T16:01:44.726Z","etag":null,"topics":[],"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/bannzai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-06-08T03:45:21.000Z","updated_at":"2025-02-20T21:53:30.000Z","dependencies_parsed_at":"2025-01-07T22:19:29.007Z","dependency_job_id":null,"html_url":"https://github.com/bannzai/UtilityType","commit_stats":null,"previous_names":["bannzai/utilitytype"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FUtilityType","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FUtilityType/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FUtilityType/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bannzai%2FUtilityType/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bannzai","download_url":"https://codeload.github.com/bannzai/UtilityType/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243806070,"owners_count":20350775,"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":[],"created_at":"2024-11-24T23:07:51.973Z","updated_at":"2025-03-16T00:07:29.928Z","avatar_url":"https://github.com/bannzai.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## UtilityType\nUtilityType is an innovative library designed to realize TypeScript's UtilityTypes in Swift. This groundbreaking library allows Swift developers to incorporate the simplicity and power of TypeScript's UtilityTypes directly into their codebase.\nSee more details: https://www.typescriptlang.org/docs/handbook/utility-types.html\n\nThe UtilityTypes supported are as follows:\n\n- Partial\n- Required\n- Pick\n- Omit\n- Exclude\n- Extract\n- Parameters\n- ReturnType\n\nUtilityType offers an extensive set of tools to enhance your flexibility and productivity when coding in Swift, by capitalizing on its robust type system. By exploiting the capabilities of Swift's Macro feature, we've succeeded in reproducing TypeScript's UtilityTypes, offering a more refined and sophisticated Swift programming experience. Experience the difference with UtilityType!\n\n### Partial\nConstructs a type with all properties of Type set to optional. This utility will return a type that represents all subsets of a given type.\n\nExample\n\n```swift\n@Partial\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    let optional: Void?\n}\n\n// All properties are to optional.\nlet partialUser = User.Partial(id: nil, name: nil, age: nil, optional: nil)\n\n// OR\nlet user = User(id: .init(), name: \"bannzai\", age: 30, optional: nil)\nlet partialUser = User.Partial(user: user)\n\n```\n\n### Required\nConstructs a type consisting of all properties of Type set to required. The opposite of [Partial](./#Partial).\n\nExample\n\n```swift\n@Required\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    let optional: Void?\n}\n\n// All properties are to non optional.\nlet requiredUser = User.Required(id: UUID(), name: \"bannzai\", age: 30, optional: ())\n\n// OR\nlet user = User(id: UUID(), name: \"bannzai\", age: 30, optional: ())\nlet partialUser = User.Partial(user: user)\n```\n\n### Readonly\nConstructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be modify.\n\nExample\n\n```swift\n@Readonly\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    var optional: Void?\n}\n\nlet readOnlyUser = User.Readonly(id: UUID(), name: \"bannzai\", age: 30, optional: nil)\n\n```\n\n### Pick\nConstructs a type by picking the set of specific properties keys (only string literal) from attached Type.\n\nExample\n\n```swift\n@Pick(\"Picked\", properties: \"id\", \"name\")\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    let optional: Void?\n}\n\n// Pick is picked properties from User.\nlet pickedUser = User.Picked(id: UUID(), name: \"bannzai\")\n\n// OR\nlet user = User(id: UUID(), name: \"bannzai\", age: 30, optional: ())\nlet pickedUser = User.Picked(user: user)\n```\n\n### Omit\nConstructs a type by picking all properties from Type and then removing specific properties (only string literal). The opposite of Pick.\n\nExample\n\n```swift\n@Omit(\"Omitted\", properties: \"id\")\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    let optional: Void?\n}\n\n// Omit is omitted properties from User.\nlet omittedUser = User.Omitted(name: \"bannzai\", age: 30, optional: nil)\n\n// OR\nlet user = User(id: UUID(), name: \"bannzai\", age: 30, optional: ())\nlet omittedUser = User.Omitted(user: user)\n```\n\n### Exclude\nConstructs a type by excluding from enum all cases that are assignable to `exlcudes`.\n\nExample\n\n```swift\n@Exclude(\"ExcludedThree\", exlcudes: \"three\")\npublic enum Enum {\n    case one\n    case two(Int)\n    case three(String, Int)\n    case four(a: String, b: Int)\n}\n\nlet testEnum = Enum.four(a: \"value\", b: 10)\nlet excluded = Enum.ExcludedThree(testEnum)\n\n// The switch statement without `three`.\nswitch excluded {\ncase .one:\n    print(\"one\")\ncase .two(let value):\n    print(\"two: value:\\(value)\")\ncase .four(a: let a, b: let b):\n    print(\"four: a:\\(a), b: \\(b)\")\ncase nil:\n    print(\"nil\")\n}\n\n```\n\n### Extract\nConstructs a type by extracting from enum all cases that are assignable to `extracts`.\n\nExample\n\n```swift\n@Extract(\"ExtractedOne\", extracts: \"one\")\npublic enum Enum {\n    case one\n    case two(Int)\n    case three(String, Int)\n    case four(a: String, b: Int)\n}\n\nlet testEnum2 = Enum.one\nlet extracted = Enum.ExtractedOne(testEnum2)\n\n// The switch statement only `one`.\nswitch extracted {\ncase .one:\n    print(\"one\")\ncase nil:\n    print(\"nil\")\n}\n\n```\n\n### Parameters\nConstructs a tuple type from the types used in the parameters of a function type.\n\n\nExample\n\n```swift\n\n@Parameters(\"FunctionArgs\")\nfunc function(a: Int, b: String, c: @escaping () -\u003e Void, e: () -\u003e Void) -\u003e Int {\n    return 1\n}\n\nlet args: FunctionArgs = (a: 10, b: \"value\", c: { print(\"c\") }, e: { print(\"e\") })\n\n```\n\n### ReturnType\nConstructs a type consisting of the return type of function.\n\nExample\n\n```swift\n@ReturnType(\"FunctionReturnType\")\nfunc function(a: Int, b: String, c: @escaping () -\u003e Void, e: () -\u003e Void) -\u003e Int {\n    return 1\n}\n\nlet returnType = FunctionReturnType(_ rawValue: 100)\n\n```\n\n### ConstructorParameters\nConstructs a tuple or array type from the types of a constructor. It produces a tuple type with all the parameter types\n\nExample\n\n```swift\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    let optional: Void?\n\n    @ConstructorParameters(\"InitValue\")\n    init(id: UUID, name: String, age: Int, optional: Void?) {\n        self.id = id\n        self.name = name\n        self.age = age\n        self.optional = optional\n    }\n}\n\nlet initValue: User.InitValue = (id: UUID(), name: \"bannzai\", age: 30, optional: nil)\nlet userFromConstructorParameters = User(initValue: initValue)\n\n```\n\n\n## Nested Macro\n**UtilityType** macro allow attached other macro that pass macro string literal to `macros:`.\n\nFor example:\n\n```swift\n@Pick(\"PickedNest\", properties: \"id\", \"name\", macros: #\"@Required\"#, #\"@Partial\"#, #\"@Omit(\"Omitted\", properties: \"id\")\"#)\n@Omit(\"OmittedNest\", properties: \"name\", macros: #\"@Required\"#, #\"@Partial\"#, #\"@Pick(\"Picked\", properties: \"id\")\"#)\npublic struct User {\n    let id: UUID\n    let name: String\n    let age: Int\n    let optional: Void?\n}\n\nlet pickedNestRequierd = User.PickedNest.Required(id: UUID), name: \"bannzai\")\nlet pickedNestPartial = User.PickedNest.Partial(id: UUID), name: \"bannzai\")\nlet pickedNestOmit = User.PickedNest.Omitted(name: \"bannzai\")\nlet omittedNestPartial = User.OmittedNest.Partial(id: nil, age: nil, optional: nil)\nlet omittedNestRequired = User.OmittedNest.Required(id: UUID(), age: 30, optional: ())\nlet omittedNestPick = User.OmittedNest.Picked(id: UUID())\n\n```\n## LICENSE\n[UtilityType](https://github.com/bannzai/UtilityType/) is released under the MIT license. See [LICENSE](./LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Futilitytype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbannzai%2Futilitytype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbannzai%2Futilitytype/lists"}