{"id":15042872,"url":"https://github.com/sindresorhus/percentage","last_synced_at":"2025-04-06T16:12:01.162Z","repository":{"id":42364174,"uuid":"212025821","full_name":"sindresorhus/Percentage","owner":"sindresorhus","description":"A percentage type for Swift","archived":false,"fork":false,"pushed_at":"2024-07-23T17:46:44.000Z","size":26,"stargazers_count":274,"open_issues_count":5,"forks_count":23,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T15:22:02.818Z","etag":null,"topics":["number","percent","percentage","swift-package","type","type-safety"],"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/sindresorhus.png","metadata":{"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"},"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":"2019-10-01T06:20:00.000Z","updated_at":"2025-04-05T08:31:06.000Z","dependencies_parsed_at":"2024-11-05T23:34:41.726Z","dependency_job_id":"af8319a7-e16d-4484-bc89-f85be0c43818","html_url":"https://github.com/sindresorhus/Percentage","commit_stats":{"total_commits":25,"total_committers":5,"mean_commits":5.0,"dds":"0.16000000000000003","last_synced_commit":"fb281e5d511c848b719285f0c7b44fd015d88ecd"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FPercentage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FPercentage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FPercentage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2FPercentage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/Percentage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509224,"owners_count":20950232,"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":["number","percent","percentage","swift-package","type","type-safety"],"created_at":"2024-09-24T20:48:10.371Z","updated_at":"2025-04-06T16:12:01.139Z","avatar_url":"https://github.com/sindresorhus.png","language":"Swift","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":[],"sub_categories":[],"readme":"# Percentage\n\n\u003e A percentage type for Swift\n\nMakes percentages more readable and type-safe, for example, for APIs that currently accept a fraction `Double`.\n\n```diff\n-.opacity(0.45)\n+.opacity(45%)\n```\n\n## Install\n\nAdd the following to `Package.swift`:\n\n```swift\n.package(url: \"https://github.com/sindresorhus/Percentage\", from: \"1.2.0\")\n```\n\n[Or add the package in Xcode.](https://developer.apple.com/documentation/xcode/adding_package_dependencies_to_your_app)\n\n## Usage\n\nSee the [source](Sources/Percentage/Percentage.swift) for docs.\n\n```swift\nimport Percentage\n\n10% + 5.5%\n//=\u003e 15.5%\n\n-10% / 2\n//=\u003e -5%\n\n(40% + 93%) * 3\n//=\u003e 399%\n\n50% * 50%\n//=\u003e 25%\n\n30% \u003e 25%\n//=\u003e true\n\n50%.of(200)\n//=\u003e 100\n\nPercentage(50)\n//=\u003e 50%\n\nPercentage(fraction: 0.5)\n//=\u003e 50%\n\n50%.fraction\n//=\u003e 0.5\n\n10%.rawValue\n//=\u003e 10\n\n110%.clampedZeroToHundred\n//=\u003e 100%\n\nprint(\"\\(1%)\")\n//=\u003e \"1%\"\n\nPercent.random(in: 10%...20%)\n//=\u003e \"14.3%\"\n```\n\nThe type conforms to `Hashable`, `Codable`, `RawRepresentable`, `Comparable`, `ExpressibleByFloatLiteral`, `ExpressibleByIntegerLiteral`, `Numeric`, and supports all the arithmetic operators.\n\n### Codable\n\nThe percentage value is encoded as a single value:\n\n```swift\nstruct Foo: Codable {\n\tlet alpha: Percentage\n}\n\nlet foo = Foo(alpha: 1%)\nlet data = try! JSONEncoder().encode(foo)\nlet string = String(data: data, encoding: .utf8)!\n\nprint(string)\n//=\u003e \"{\\\"alpha\\\":1}\"\n```\n\n## FAQ\n\n#### Can you support Carthage and CocoaPods?\n\nNo, but you can still use Swift Package Manager for this package even though you mainly use Carthage or CocoaPods.\n\n## Related\n\n- [Regex](https://github.com/sindresorhus/Regex) - Swifty regular expressions\n- [Defaults](https://github.com/sindresorhus/Defaults) - Swifty and modern UserDefaults\n- [Preferences](https://github.com/sindresorhus/Preferences) - Add a preferences window to your macOS app\n- [KeyboardShortcuts](https://github.com/sindresorhus/KeyboardShortcuts) - Add user-customizable global keyboard shortcuts to your macOS app\n- [LaunchAtLogin](https://github.com/sindresorhus/LaunchAtLogin) - Add \"Launch at Login\" functionality to your macOS app\n- [More…](https://github.com/search?q=user%3Asindresorhus+language%3Aswift)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpercentage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fpercentage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fpercentage/lists"}