{"id":17138141,"url":"https://github.com/pglongo/pglformatter","last_synced_at":"2025-10-29T14:33:38.520Z","repository":{"id":28815950,"uuid":"32339215","full_name":"PGLongo/PGLFormatter","owner":"PGLongo","description":"Simple container of NSFormatter and useful functions to format numbers and dates","archived":false,"fork":false,"pushed_at":"2017-11-24T13:18:44.000Z","size":66,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T21:18:04.685Z","etag":null,"topics":["bytecountformatter","datecomponentsformatter","dateformatter","formatter","lengthformatter","massformatter","numberformatter","swift"],"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/PGLongo.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}},"created_at":"2015-03-16T16:48:38.000Z","updated_at":"2024-05-17T16:43:09.000Z","dependencies_parsed_at":"2022-08-20T21:50:29.378Z","dependency_job_id":null,"html_url":"https://github.com/PGLongo/PGLFormatter","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PGLongo%2FPGLFormatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PGLongo%2FPGLFormatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PGLongo%2FPGLFormatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PGLongo%2FPGLFormatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PGLongo","download_url":"https://codeload.github.com/PGLongo/PGLFormatter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248695302,"owners_count":21146952,"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":["bytecountformatter","datecomponentsformatter","dateformatter","formatter","lengthformatter","massformatter","numberformatter","swift"],"created_at":"2024-10-14T20:08:52.950Z","updated_at":"2025-10-29T14:33:38.439Z","avatar_url":"https://github.com/PGLongo.png","language":"Swift","readme":"# PGLFormatter\nPGLFormatter is a simple container of NSFormatter and useful functions  \n[![Build Status](https://travis-ci.org/PGLongo/PGLFormatter.svg?branch=master)](https://travis-ci.org/PGLongo/PGLFormatter)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods](https://img.shields.io/cocoapods/v/PGLFormatter.svg)](https://cocoapods.org/pods/PGLFormatter) \n\n##Reason\nFormatters are extremely expensive to create so it's very important to reuse the formatter as much as you can. \n\nThis project is inspired from this [article](http://nshipster.com/nsformatter/) published on [NSHipster](http://nshipster.com/)\n\nIf you use the same formatter in the entire project you can set in a single point (e.g. AppDelegate) and then forget about the NSFormatter and simple use the function that PGLFormatter offers, for format() to format Double Float Int (see the example), otherwise you should remember to set the behavior every time\n## Add PGLFormatter to your project\n\n#### Cocoapods\n\nTo integrate PGLFormatter into your Xcode project using [Cocoapods](http://cocoapods.org/), specify it in your Podfile:\n\n\tuse_frameworks!\n\tpod 'PGLFormatter'\n\n#### Carthage\n\nTo integrate PGLFormatter into your Xcode project using [Carthage](https://github.com/Carthage/Carthage), specify it in your Cartfile:\n\n\tgithub \"PGLongo/PGLFormatter\"\n\t\n## Example\n\n### Double Float Int\n```swift\nlet price:Double = 12356789.4200\n\nvar formatter = PGLFormatter.numberFormatter\n// set the formatter behavior\nformatter.numberStyle = .CurrencyStyle\n\nprice.format() // $12,356,789.42\n```\n\n#### Formatting Byte\n\n```swift\nvar formatter = PGLFormatter.byteFormatter\n// set the formatter behavior\n\n42.formatToByte() // \"42 bytes\"\n42000.formatToByte() // \"42 KB\"\nInt64(42000000000).formatToByte() // 42 GB\n```\n\n#### Formatting Lenght\n\n```swift\nvar formatter = PGLFormatter.lenghtFormatter\n// set the formatter behavior\n\n42.formatLenght(.Meter) // 42 m\n42.formatLenghtFromMeters() // 45.931 yd\n```\n\n#### Formatting Mass\n\n```swift\nvar formatter = PGLFormatter.massFormatter\n// set the formatter behavior\n\n42.formatMass(.Gram) // 42 g\n42.formatMassFromKilograms() // 92.594 lb\n```\n\n### NSDate\n```swift\nlet calendar = NSCalendar.currentCalendar()\nlet components = NSDateComponents()\ncomponents.year = 1988\ncomponents.month = 11\ncomponents.day = 30\ncomponents.hour = 0\ncomponents.minute = 0\ncomponents.second = 0\nlet date = calendar.dateFromComponents(components)\n\ndate.format() // 11/30/88, 12:00 AM\n\n```\n\n### TimeFormatter\n```swift\nPGLFormatter.timeFormatter\nformatter.unitsStyle = .Abbreviated\n// set the formatter behavior\n\n42.formatTime()! // 42s\n4200.formatTime()! // 1h 10m\n\n```\n\n## Documentation\nDocumentation is generated and manteined by Cocoapods. You can read the latest documentation at the following [URL](http://cocoadocs.org/docsets/PGLFormatter) and add the docs to [Dash](http://kapeli.com/dash).\n\n- [0.0.1](http://cocoadocs.org/docsets/PGLFormatter/0.0.1/)\n- [0.0.2](http://cocoadocs.org/docsets/PGLFormatter/0.0.2/)\n- [0.0.3](http://cocoadocs.org/docsets/PGLFormatter/0.0.3/)\n- [0.0.3](http://cocoadocs.org/docsets/PGLFormatter/0.0.3/)\n- [1.0](http://cocoadocs.org/docsets/PGLFormatter/1.0/)\n- [1.1](http://cocoadocs.org/docsets/PGLFormatter/1.1/)\n- [2.0](http://cocoadocs.org/docsets/PGLFormatter/2.0/)\n- [2.1](http://cocoadocs.org/docsets/PGLFormatter/2.1/)\n- [3.0](http://cocoadocs.org/docsets/PGLFormatter/3.0/)\n- [3.1.0](http://cocoadocs.org/docsets/PGLFormatter/3.1.0/)\n\n\n\n## Task\n- [x] Support Cocoapods\n- [x] Support Carthage\n- [x] Add installation instruction\n- [x] Add other formatters\n- [x] Add documentation\n- [ ] Implements other useful functions\n\n\n## License\n\nPGLFormatter is released under the MIT license. See LICENSE for details.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpglongo%2Fpglformatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpglongo%2Fpglformatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpglongo%2Fpglformatter/lists"}