{"id":13685075,"url":"https://github.com/FormatterKit/FormatterKit","last_synced_at":"2025-05-01T01:30:24.945Z","repository":{"id":56911601,"uuid":"2103283","full_name":"FormatterKit/FormatterKit","owner":"FormatterKit","description":"`stringWithFormat:` for the sophisticated hacker set","archived":true,"fork":false,"pushed_at":"2019-07-07T22:04:27.000Z","size":947,"stargazers_count":4123,"open_issues_count":0,"forks_count":447,"subscribers_count":117,"default_branch":"master","last_synced_at":"2024-10-30T08:16:21.262Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","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/FormatterKit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-07-25T20:27:48.000Z","updated_at":"2024-10-22T13:13:54.000Z","dependencies_parsed_at":"2022-08-21T03:20:11.583Z","dependency_job_id":null,"html_url":"https://github.com/FormatterKit/FormatterKit","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormatterKit%2FFormatterKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormatterKit%2FFormatterKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormatterKit%2FFormatterKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FormatterKit%2FFormatterKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FormatterKit","download_url":"https://codeload.github.com/FormatterKit/FormatterKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222535297,"owners_count":16999232,"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-08-02T14:00:43.367Z","updated_at":"2024-11-12T06:31:10.174Z","avatar_url":"https://github.com/FormatterKit.png","language":"Objective-C","readme":"# FormatterKit\n\n\u003e This library is no longer being maintained.\n\u003e Since its initial release in 2011,\n\u003e Apple has filled in many of the gaps FormatterKit was created to fill\n\u003e in Foundation and other SDK frameworks:\n\n| Deprecated FormatterKit API     | Apple SDK API                                                                          | Availability             |\n| ------------------------------- | -------------------------------------------------------------------------------------- | ------------------------ |\n| `TTTAddressFormatter`           | [`CNPostalAddressFormatter`][cnpostaladdressformatter]                                 | iOS 9.0+ / macOS 10.11+  |\n| `TTTArrayFormatter`             | [`NSListFormatter`][nslistformatter]                                                   | iOS 13.0+ / macOS 10.15+ |\n| `TTTNameFormatter`              | [`NSPersonNameComponentsFormatter`][nspersonnamecomponentsformatter]                   | iOS 9.0+ / macOS 10.11+  |\n| `TTTLocationFormatter`          | [`NSMeasurementFormatter` + `NSUnitDistance` / `NSUnitAngle`][nsmeasurementformatter]  | iOS 10.0+ / macOS 10.12+ |\n| `TTTOrdinalNumberFormatter`     | [`NSNumberFormatter` + `NSNumberFormatterOrdinalStyle`][nsnumberformatterordinalstyle] | iOS 9.0+ / macOS 10.11+  |\n| `TTTTimeIntervalFormatter`      | [`NSRelativeDateTimeFormatter`][nsrelativedatetimeformatter]                           | iOS 13.0+ / macOS 10.15+ |\n| `TTTUnitOfInformationFormatter` | [`NSMeasurementFormatter` + `NSUnitInformationStorage`][nsunitinformationstorage]      | iOS 13.0+ / macOS 10.15+ |\n\n\u003e You can continue to use FormatterKit in your projects,\n\u003e but we recommend switching to the corresponding Apple APIs\n\u003e as soon as it makes sense to do so.\n\u003e\n\u003e Going forward, we plan to spin out non-deprecated formatters\n\u003e into their own repositories for future development\n\u003e as well as any new projects.\n\u003e This repository will remain archived here\n\u003e for compatibility with existing installations.\n\n---\n\n`FormatterKit` is a collection of well-crafted `NSFormatter` subclasses for things like units of information, distance, and relative time intervals. Each formatter abstracts away the complex business logic of their respective domain, so that you can focus on the more important aspects of your application.\n\nIn short, use this library if you're manually formatting any of the following (with string interpolation or the like):\n\n- **Addresses**: Create formatted address strings from components _(e.g. 221b Baker St / Paddington / Greater London / NW1 6XE / United Kingdom )_\n- **Arrays**: Display `NSArray` elements in a comma-delimited list _(e.g. \"Russell, Spinoza \u0026 Rawls\")_\n- **Colors**: RGB, CMYK, and HSL your ROY G. BIV in style. _(e.g. `#BADF00D`, `rgb(255, 100, 42)`)_\n- **Location, Distance \u0026 Direction**: Show `CLLocationDistance`, `CLLocationDirection`, and `CLLocationSpeed` in metric or imperial units _(eg. \"240ft Northwest\" / \"45 km/h SE\")_\n- **Names**: Display personal names in the correct format, according to the current locale and source language _(eg. \"山田花子\" for the Japanese first name \"花子\" (Hanako) and last name \"山田\" (Yamada))_\n- **Ordinal Numbers**: Convert cardinal `NSNumber` objects to their ordinal in most major languages _(eg. \"1st, 2nd, 3rd\" / \"1ère, 2ème, 3ème\")_\n- **Time Intervals**: Show relative time distance between any two `NSDate` objects _(e.g. \"3 minutes ago\" / \"yesterday\")_\n- **Units of Information**: Humanized representations of quantities of bits and bytes _(e.g. \"2.7 MB\")_\n- **URL Requests**: Print out `cURL` or `Wget` command equivalents for any `NSURLRequest` _(e.g. `curl -X POST \"https://www.example.com/\" -H \"Accept: text/html\"`)_\n\n## Installation\n\n### CocoaPods\n\nYou can install `FormatterKit` via CocoaPods,\nby adding the following line to your `Podfile`:\n\n```ruby\npod 'FormatterKit', '~\u003e 1.9.0'\n```\n\nRun the `pod install` command to download the library\nand integrate it into your Xcode project.\n\n### Carthage\n\nTo use `FormatterKit` in your Xcode project using Carthage,\nspecify it in `Cartfile`:\n\n```\ngithub \"FormatterKit/FormatterKit\" ~\u003e 1.9.0\n```\n\nThen run the `carthage update` command to build the framework,\nand drag the built FormatterKit.framework into your Xcode project.\n\n## Demo\n\nBuild and run the `FormatterKit Example` project in Xcode to see an inventory of the available `FormatterKit` components.\n\n---\n\n## TTTAddressFormatter\n\nAddress formats vary greatly across different regions.\n`TTTAddressFormatter` ties into the\n[Address Book frameworks](https://developer.apple.com/documentation/addressbookui?language=objc)\nto help your users find their place in the world.\n\nFor example, addresses in the United States take the form:\n\n    Street Address\n    City State ZIP\n    Country\n\nWhereas addresses in Japan follow a different convention:\n\n    Postal Code\n    Prefecture Municipality\n    Street Address\n    Country\n\n\u003e Requires that the `AddressBook` and `AddressBookUI` frameworks are linked\n\u003e with `#import` statements in `Prefix.pch`.\n\u003e `TTTAddressFormatter` isn't available on OS X.\n\n### Example Usage\n\n```objective-c\nTTTAddressFormatter *addressFormatter = [[TTTAddressFormatter alloc] init];\nNSLog(@\"%@\", [addressFormatter stringFromAddressWithStreet:street locality:locality region:region postalCode:postalCode country:country]);\n```\n\n## TTTArrayFormatter\n\nThink of this as a production-ready alternative to\n`NSArray -componentsJoinedByString:`.\n`TTTArrayFormatter` comes with internationalization baked-in\nand provides a concise API that allows you to configure for any edge cases.\n\n### Example Usage\n\n```objective-c\nNSArray *list = [NSArray arrayWithObjects:@\"Russel\", @\"Spinoza\", @\"Rawls\", nil];\nTTTArrayFormatter *arrayFormatter = [[TTTArrayFormatter alloc] init];\n[arrayFormatter setUsesAbbreviatedConjunction:YES]; // Use '\u0026' instead of 'and'\n[arrayFormatter setUsesSerialDelimiter:NO]; // Omit Oxford Comma\nNSLog(@\"%@\", [arrayFormatter stringFromArray:list]); // # =\u003e \"Russell, Spinoza \u0026 Rawls\"\n```\n\n## TTTColorFormatter\n\nRGB, CMYK, and HSL your ROY G. BIV in style.\n`TTTColorFormatter` provides string representations of colors.\n\n### Example Usage\n\n```objective-c\nTTTColorFormatter *colorFormatter = [[TTTColorFormatter alloc] init];\nNSString *RGB = [colorFormatter RGBStringFromColor:[UIColor orangeColor]];\n```\n\n## TTTLocationFormatter\n\nWhen working with `CoreLocation`,\nyou can use your favorite unit for distance...\nso long as your favorite unit is the meter.\nIf you want to take distance calculations and display them to the user,\nyou may want to use kilometers instead --- or maybe even miles\nif you're of the [Imperial](http://en.wikipedia.org/wiki/Imperial_units) persuasion.\n\n`TTTLocationFormatter` gives you a lot of flexibility in the display of\ncoordinates, distances, direction, speed, and velocity.\nChoose Metric or Imperial, cardinal directions, abbreviations, or degrees,\nand configure everything else (number of significant digits, etc.)\nwith the associated `NSNumberFormatter`.\n\n### Example Usage\n\n```objective-c\nTTTLocationFormatter *locationFormatter = [[TTTLocationFormatter alloc] init];\nCLLocation *austin = [[CLLocation alloc] initWithLatitude:30.2669444 longitude:-97.7427778];\nCLLocation *pittsburgh = [[CLLocation alloc] initWithLatitude:40.4405556 longitude:-79.9961111];\n```\n\n#### Distance in Metric Units with Cardinal Directions\n\n```objective-c\nNSLog(@\"%@\", [locationFormatter stringFromDistanceAndBearingFromLocation:pittsburgh toLocation:austin]);\n// \"2,000 km Southwest\"\n```\n\n#### Distance in Imperial Units with Cardinal Direction Abbreviations\n\n```objective-c\n[locationFormatter.numberFormatter setMaximumSignificantDigits:4];\n[locationFormatter setBearingStyle:TTTBearingAbbreviationWordStyle];\n[locationFormatter setUnitSystem:TTTImperialSystem];\nNSLog(@\"%@\", [locationFormatter stringFromDistanceAndBearingFromLocation:pittsburgh toLocation:austin]);\n// \"1,218 miles SW\"\n```\n\n#### Speed in Imperial Units with Bearing in Degrees\n\n```objective-c\n[locationFormatter setBearingStyle:TTTBearingNumericStyle];\nNSLog(@\"%@ at %@\", [locationFormatter stringFromSpeed:25],[locationFormatter stringFromBearingFromLocation:pittsburgh toLocation:austin]);\n// \"25 mph at 310°\"\n```\n\n#### Coordinates\n\n```objective-c\n[locationFormatter.numberFormatter setUsesSignificantDigits:NO];\nNSLog(@\"%@\", [locationFormatter stringFromLocation:austin]);\n// (30.2669444, -97.7427778)\n```\n\n## TTTNameFormatter\n\n`TTTNameFormatter` formats names according to the internationalization standards\nof the AddressBook framework, which determine, for example,\nthe display order of names and whether or not to delimit components with whitespace.\n\n\u003e `TTTNameFormatter` isn't available on OS X.\n\n### Example Usage\n\n```objective-c\nTTTNameFormatter *nameFormatter = [[TTTNameFormatter alloc] init];\nNSString *frenchName = [nameFormatter stringFromPrefix:nil firstName:@\"Guillaume\" middleName:@\"François\" lastName:@\"Antoine\" suffix:@\"Marquis de l'Hôpital\"];\nNSLog(@\"%@\", frenchName);\n// \"Guillaume François Antoine Marquis de l'Hôpital\"\n\nNSString *japaneseName = [nameFormatter stringFromFirstName:@\"孝和\" lastName:@\"関\"];\nNSLog(@\"%@\", japaneseName);\n// \"関孝和\"\n```\n\n## TTTOrdinalNumberFormatter\n\n`NSNumberFormatter` is great for [Cardinal numbers](http://en.wikipedia.org/wiki/Cardinal_number) (17, 42, 69, etc.), but it doesn't have built-in support for [Ordinal numbers](\u003chttp://en.wikipedia.org/wiki/Ordinal_number_(linguistics)\u003e) (1st, 2nd, 3rd, etc.)\n\nA naïve implementation might be as simple as throwing the one's place in a switch statement and appending \"-st\", \"-nd\", etc. But what if you want to support French, which appends \"-er\", \"-ère\", and \"-eme\" in various contexts? How about Spanish? Japanese?\n\n`TTTOrdinalNumberFormatter` supports English, Spanish, French, German, Irish, Italian, Japanese, Dutch, Portuguese, Simplified Chinese and Swedish. For other languages, you can use the standard default, or override it with your own. For languages whose ordinal indicator depends upon the grammatical properties of the predicate, `TTTOrdinalNumberFormatter` can format according to a specified gender and/or plurality.\n\n### Example Usage\n\n```objective-c\nTTTOrdinalNumberFormatter *ordinalNumberFormatter = [[TTTOrdinalNumberFormatter alloc] init];\n[ordinalNumberFormatter setLocale:[NSLocale currentLocale]];\n[ordinalNumberFormatter setGrammaticalGender:TTTOrdinalNumberFormatterMaleGender];\nNSNumber *number = [NSNumber numberWithInteger:2];\nNSLog(@\"%@\", [NSString stringWithFormat:NSLocalizedString(@\"You came in %@ place!\", nil), [ordinalNumberFormatter stringFromNumber:number]]);\n```\n\nAssuming you've provided localized strings for \"You came in %@ place!\", the output would be:\n\n- English: \"You came in 2nd place!\"\n- French: \"Vous êtes arrivé à la 2e place !\"\n- Spanish: \"Usted llegó en 2.o lugar!\"\n\n## TTTTimeIntervalFormatter\n\nNearly every application works with time in some way or another.\nAnd when we display temporal information to users,\nit's typically in relative terms to the present,\nlike \"3 minutes ago\", \"10 months ago\", or \"last month\".\n`TTTTimeIntervalFormatter` defaults to a\nsmart, relative display of an `NSTimeInterval` value,\nwith options to extend that behavior to your particular use case.\n\n### Example Usage\n\n```objective-c\nTTTTimeIntervalFormatter *timeIntervalFormatter = [[TTTTimeIntervalFormatter alloc] init];\n[timeIntervalFormatter stringForTimeInterval:0]; // \"just now\"\n[timeIntervalFormatter stringForTimeInterval:-100]; // \"1 minute ago\"\n[timeIntervalFormatter stringForTimeInterval:-8000]; // \"2 hours ago\"\n\n// Turn idiomatic deictic expressions on / off\n[timeIntervalFormatter stringForTimeInterval:-100000]; // \"1 day ago\"\n[timeIntervalFormatter setUsesIdiomaticDeicticExpressions:YES];\n[timeIntervalFormatter stringForTimeInterval:-100000]; // \"yesterday\"\n\n// Customize the present tense deictic expression for\n[timeIntervalFormatter setPresentDeicticExpression:@\"seconds ago\"];\n[timeIntervalFormatter stringForTimeInterval:0]; // \"seconds ago\"\n\n// Expand the time interval for present tense\n[timeIntervalFormatter stringForTimeInterval:-3]; // \"3 seconds ago\"\n[timeIntervalFormatter setPresentTimeIntervalMargin:10];\n[timeIntervalFormatter stringForTimeInterval:-3]; // \"seconds ago\"\n```\n\n## TTTUnitOfInformationFormatter\n\nNo matter how far abstracted from its underlying hardware an application may be,\nthere comes a day when it has to communicate the size of a file to the user.\n`TTTUnitOfInformationFormatter` transforms a number of bits or bytes\ninto a humanized representation,\nusing either SI decimal or IEC binary unit prefixes.\n\n### Example Usage\n\n```objective-c\nTTTUnitOfInformationFormatter *unitOfInformationFormatter = [[TTTUnitOfInformationFormatter alloc] init];\n[unitOfInformationFormatter stringFromNumberOfBits:[NSNumber numberWithInteger:416]]; // \"56 bytes\"\n\n// Display in either bits or bytes\n[unitOfInformationFormatter setDisplaysInTermsOfBytes:NO];\n[unitOfInformationFormatter stringFromNumberOfBits:[NSNumber numberWithInteger:416]]; // \"416 bits\"\n\n// Use IEC Binary prefixes (base 2 rather than SI base 10; see http://en.wikipedia.org/wiki/IEC_60027)\n[unitOfInformationFormatter setUsesIECBinaryPrefixesForCalculation:NO];\n[unitOfInformationFormatter stringFromNumberOfBits:[NSNumber numberWithInteger:8660]]; // \"8.66 Kbit\"\n\n[unitOfInformationFormatter setUsesIECBinaryPrefixesForCalculation:YES];\n[unitOfInformationFormatter setUsesIECBinaryPrefixesForDisplay:YES];\n[unitOfInformationFormatter stringFromNumberOfBits:[NSNumber numberWithInteger:416]]; // \"8.46 Kibit\"\n```\n\n## TTTURLRequestFormatter\n\n`NSURLRequest` objects encapsulate all of the information made in a network request,\nincluding url, headers, body, etc.\nThis isn't something you'd normally want to show to a user,\nbut it'd be nice to have a way to make it more portable for debugging.\nEnter: `TTTURLRequestFormatter`.\nIn addition to formatting requests simply as `POST http://www.example.com/`,\nit also generates `cURL` and `Wget` commands\nwith all of its headers and data fields intact to debug in the console.\n\n### Example Usage\n\n```objective-c\nNSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@\"http://www.example.com/\"]];\n[request setHTTPMethod:@\"POST\"];\n[request addValue:@\"text/html\" forHTTPHeaderField:@\"Accept\"];\n[TTTURLRequestFormatter cURLCommandFromURLRequest:request];\n```\n\n    curl -X POST \"https://www.example.com/\" -H \"Accept: text/html\"\n\n## Localizations\n\nFormatterKit comes fully internationalized,\nwith `.strings` files for the following locales:\n\n- Catalan (`ca`)\n- Chinese (Simplified) (`zh_Hans`)\n- Chinese (Traditional) (`zh_Hant`)\n- Czech (`cs`)\n- Danish (`da`)\n- Dutch (`nl`)\n- English (`en`)\n- French (`fr`)\n- German (`de`)\n- Greek (`el`)\n- Hebrew (`he`)\n- Hungarian (`hu`)\n- Indonesian (`id`)\n- Italian (`it`)\n- Korean (`ko`)\n- Norwegian Bokmål (`nb`)\n- Norwegian Nynorsk (`nn`)\n- Polish (`pl`)\n- Portuguese (Brazilian) (`pt_BR`)\n- Russian (`ru`)\n- Spanish (`es`)\n- Swedish (`sv`)\n- Turkish (`tr`)\n- Ukranian (`uk`)\n- Vietnamese (`vi`)\n\n---\n\n## License\n\nFormatterKit is available under the MIT license.\nSee the LICENSE file for more info.\n\n[cnpostaladdressformatter]: https://developer.apple.com/documentation/contacts/cnpostaladdressformatter?language=objc\n[nslistformatter]: https://developer.apple.com/documentation/foundation/nslistformatter?language=objc\n[nspersonnamecomponentsformatter]: https://developer.apple.com/documentation/foundation/NSPersonNameComponentsFormatter\n[nsmeasurementformatter]: https://developer.apple.com/documentation/foundation/NSMeasurementFormatter\n[nsnumberformatterordinalstyle]: https://developer.apple.com/documentation/foundation/nsnumberformatterstyle/nsnumberformatterordinalstyle?language=objc\n[nsrelativedatetimeformatter]: https://developer.apple.com/documentation/foundation/NSRelativeDateTimeFormatter\n[nsunitinformationstorage]: https://developer.apple.com/documentation/foundation/NSUnitInformationStorage\n","funding_links":[],"categories":["Objective-C","etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFormatterKit%2FFormatterKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFormatterKit%2FFormatterKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFormatterKit%2FFormatterKit/lists"}