{"id":15038487,"url":"https://github.com/openalloc/swiftcompactor","last_synced_at":"2025-04-09T23:40:45.529Z","repository":{"id":63919500,"uuid":"428891303","full_name":"openalloc/SwiftCompactor","owner":"openalloc","description":"Formatters for the concise display of Numbers, Currency, and Time Intervals","archived":false,"fork":false,"pushed_at":"2023-05-01T23:59:30.000Z","size":106,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-03-15T11:51:31.303Z","etag":null,"topics":["currency","currency-format","formatter","number","number-format","swift-format","swift-lang","swift-language","swift-library","time-format","timeinterval"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openalloc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2021-11-17T03:07:49.000Z","updated_at":"2023-10-25T04:11:09.000Z","dependencies_parsed_at":"2024-09-24T20:48:50.637Z","dependency_job_id":null,"html_url":"https://github.com/openalloc/SwiftCompactor","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"5caf0b3d43ee139fc34673df89c5ad93d2f5078f"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftCompactor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftCompactor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftCompactor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openalloc%2FSwiftCompactor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openalloc","download_url":"https://codeload.github.com/openalloc/SwiftCompactor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131465,"owners_count":21052819,"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":["currency","currency-format","formatter","number","number-format","swift-format","swift-lang","swift-language","swift-library","time-format","timeinterval"],"created_at":"2024-09-24T20:38:39.697Z","updated_at":"2025-04-09T23:40:45.507Z","avatar_url":"https://github.com/openalloc.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftCompactor\n\nFormatters for the concise display of Numbers, Currency, and Time Intervals\n\nWhy _SwiftCompactor_? First, use where precision isn’t critical, but space is at a premium. Second, compact values like `$8.6M` are more easily grasped over values like `$8,603,842.35`, lowering the cognitive load for the user.\n\nAvailable as an open source Swift library to be incorporated in other apps.\n\n_Compactor_ is part of the [OpenAlloc](https://github.com/openalloc) family of open source Swift software tools.\n\n\u003cimg src=\"https://github.com/openalloc/SwiftCompactor/blob/main/Images/examples.png\" width=\"800\" height=\"305\"/\u003e\n\n## NumberCompactor\n\n```swift\nlet c = NumberCompactor()\nprint(c.string(from: 1_234_567))\n\n=\u003e \"1.2M\"\n```\n\nBy default, values will show up to one fractional decimal point of the value, rounded if necessary.\n\n### Options\n\n* `ifZero` (default: `(String?)nil`) - if nil and value is zero, a zero value will be shown. If !nil and value is zero, the specified string value will be shown\n* `roundSmallToWhole` (default: `false`) - if true, fractional parts excluded from values within `-100...100`\n\n### Suffixes\n\n| suffix | description         | value  |\n| ------ | ------------------- | ------ |\n|   k    | kilo (thousand)     | 1000^1 |\n|   M    | mega (million)      | 1000^2 |\n|   G    | giga (billion)      | 1000^3 |\n|   T    | tera (trillion)     | 1000^4 |\n|   P    | peta (quadrillion)  | 1000^5 |\n|   E    | exa (quintillion)   | 1000^6 |\n\nFor more detail see the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) page at Wikipedia.\n\n## CurrencyCompactor\n\n```swift\nlet c = CurrencyCompactor()\nprint(c.string(from: 1_234_567))\n\n=\u003e \"$1.2M\"\n```\n\nBy default, values within `-100...100` will have no fractional part, and are rounded where necessary. Outside that one fractional decimal point of the value is shown, rounded if necessary.\n\n### Options\n\n* `ifZero` (default: `(String?)nil`) - if nil and value is zero, a zero value will be shown. If !nil and value is zero, the specified string value will be shown\n* `roundSmallToWhole` (default: `true`) - if true, fractional parts excluded from values within `-100...100`\n\nNote that `roundSmallToWhole` is true by default, because `$1.1` looks awkward when we’re accustomed to fractions in pennies.\n\n### Suffixes\n\nThe same as used with `NumberCompactor()`.\n\n## TimeCompactor\n\nWith `TimeCompactor()` you provide it a `TimeInterval` value to be transformed into a string value.\n\n```swift\nlet c = TimeCompactor()\nprint(c.string(from: 1_234_567))\n\n=\u003e \"14.3d\"\n\nlet f = TimeCompactor(style: .full)\nprint(f.string(from: 1_234_567))\n\n=\u003e \"14.3 days\"\n```\n\nBy default, values will show up to one fractional decimal point of the value, rounded if necessary.\n\n### Options\n\n* `ifZero` (default: `(String?)nil`) - if nil and value is zero, a zero value will be shown. If !nil and value is zero, the specified string value will be shown\n* `style` (default: `.short`) - the style of suffix used\n* `roundSmallToWhole` (default: `false`) - if true, fractional parts excluded from values within `-100...100`\n\n### Suffixes\n\nThe suffix will depend on the style, of which there is currently `.short` (default), `.medium`, and `.full`.\n\n| short  | medium | full                | value      |\n| ------ | ------ | ------------------- | ---------- |\n|   s    |  sec   | second              | 1          |\n|   m    |  min   | minute              | 60         |\n|   h    |  hr    | hour                | 3,600      |\n|   d    |  day   | day                 | 86,400     |\n|   y    |  yr    | year                | d × 365.25 |\n|   c    |  cent  | century             | y × 100    |\n|   ky   |  ky    | millennium          | y × 1000   |\n\nNote that `.medium` and `.full` include plural forms.\n\n## See Also\n\nThis library is a member of the _OpenAlloc Project_.\n\n* [_OpenAlloc_](https://openalloc.github.io) - product website for all the _OpenAlloc_ apps and libraries\n* [_OpenAlloc Project_](https://github.com/openalloc) - Github site for the development project, including full source code\n\n## License\n\nCopyright 2021, 2022 OpenAlloc LLC\n\nLicensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n\n## Contributing\n\nContributions are welcome. You are encouraged to submit pull requests to fix bugs, improve documentation, or offer new features. \n\nThe pull request need not be a production-ready feature or fix. It can be a draft of proposed changes, or simply a test to show that expected behavior is buggy. Discussion on the pull request can proceed from there.\n\nContributions should ultimately have adequate test coverage. See tests for current entities to see what coverage is expected.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenalloc%2Fswiftcompactor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenalloc%2Fswiftcompactor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenalloc%2Fswiftcompactor/lists"}