{"id":16431440,"url":"https://github.com/stephencelis/formatting","last_synced_at":"2025-03-16T17:35:21.364Z","repository":{"id":66258160,"uuid":"62000777","full_name":"stephencelis/Formatting","owner":"stephencelis","description":"Type-safe, functional string formatting in Swift.","archived":false,"fork":false,"pushed_at":"2017-02-11T22:57:00.000Z","size":19,"stargazers_count":248,"open_issues_count":3,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-08T19:47:42.456Z","etag":null,"topics":["composability","formatter","functional-programming","string-formatter","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/stephencelis.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}},"created_at":"2016-06-26T17:41:47.000Z","updated_at":"2024-02-15T15:45:09.000Z","dependencies_parsed_at":"2023-02-22T16:30:30.607Z","dependency_job_id":null,"html_url":"https://github.com/stephencelis/Formatting","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2FFormatting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2FFormatting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2FFormatting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephencelis%2FFormatting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephencelis","download_url":"https://codeload.github.com/stephencelis/Formatting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243823319,"owners_count":20353649,"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":["composability","formatter","functional-programming","string-formatter","swift"],"created_at":"2024-10-11T08:30:13.401Z","updated_at":"2025-03-16T17:35:21.107Z","avatar_url":"https://github.com/stephencelis.png","language":"Swift","readme":"# Formatting\n\nType-safe, functional string formatting in Swift.\n\nInspired by Chris Done's excellent [Haskell library](https://github.com/chrisdone/formatting).\n\n``` swift\nimport Formatting\n\nformat(\"Hello, \" % string % \"!\", \"world\")\n// \"Hello, world!\"\n```\n\n\n## Introduction\n\nTraditional string formatting methods (interpolation, `printf`, and template strings) can lead to subtle (and not so subtle) runtime bugs.\n\n``` swift\nprint(\"Hello, \\(thing)!\")              // Hello, nil!\nprint(\"Hello, \\(thing)!\")              // Hello, Optional(\"world\")!\n```\n\n``` objective-c\nNSLog(@\"Hello, %@!\", thing);           // Hello, (null)!\n```\n\n**Formatting** brings compile-time checks.\n\n``` swift\nprint(\"Hello, \" % string % \"!\", thing) // Value of optional type String? not unwrapped\n```\n\nAnd composability.\n\n``` swift\nlet greet =\n  format(\"Hello, \" % string % \"!\")\n\ngreet(\"world\")                         // Hello, world!\n```\n\n\u003c!-- ## Formatters --\u003e\n\n## Composing formatters\n\nUse `%` to build a formatter with strings and other formatters.\n\n``` swift\nformat(string % \" is \" % int % \"years old.\", \"Alice\", 25)\n// \"Alice is 25 years old.\"\n```\n\nUse `\u003c\u003e` to pass the previous formatter argument to the next formatter.\n\n``` swift\nformat(yyyy % \"-\" \u003c\u003e MM % \"-\" \u003c\u003e dd, Date())\n// \"2016-06-28\"\n```\n\nUse `.%` to feed the result of one formatter into another.\n\n``` swift\nformat(left(2, \"0\") .% hex, 10)\n// \"0a\"\n```\n\nCall `format` without arguments to return a curried formatter function.\n\n``` swift\nlet log =\n  format(right(5) % \" -- [\" % iso8601 % \"] \" % string)\n\nlet infoLog = log(\"INFO\")\nlet debugLog = log(\"DEBUG\")\n\ninfoLog(Date())(\"Logging in...\")\n// \"INFO  -- [2016-06-28T12:34:56Z] Logging in...\"\ndebugLog(Date())(\"Logged in successfully!\")\n// \"DEBUG -- [2016-06-28T12:34:56Z] Logged in successfully!\"\n```\n\n## License\n\nFormatting is available under the MIT license. See [the LICENSE\nfile](./LICENSE.txt) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephencelis%2Fformatting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephencelis%2Fformatting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephencelis%2Fformatting/lists"}