{"id":17996725,"url":"https://github.com/cosmo/grammaticalnumber","last_synced_at":"2025-07-19T06:03:41.077Z","repository":{"id":63907235,"uuid":"205518404","full_name":"Cosmo/GrammaticalNumber","owner":"Cosmo","description":"1️⃣🔜🔢 Turns singular words to the plural and vice-versa in Swift.","archived":false,"fork":false,"pushed_at":"2019-09-29T16:15:31.000Z","size":16,"stargazers_count":34,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-15T09:33:34.255Z","etag":null,"topics":[],"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/Cosmo.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":"2019-08-31T08:36:12.000Z","updated_at":"2025-05-17T20:40:29.000Z","dependencies_parsed_at":"2022-11-28T22:52:38.522Z","dependency_job_id":null,"html_url":"https://github.com/Cosmo/GrammaticalNumber","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Cosmo/GrammaticalNumber","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FGrammaticalNumber","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FGrammaticalNumber/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FGrammaticalNumber/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FGrammaticalNumber/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cosmo","download_url":"https://codeload.github.com/Cosmo/GrammaticalNumber/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cosmo%2FGrammaticalNumber/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265895900,"owners_count":23845403,"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-10-29T21:15:41.569Z","updated_at":"2025-07-19T06:03:40.825Z","avatar_url":"https://github.com/Cosmo.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GrammaticalNumber\n\nTurning singular words to plural can be [very hard](https://en.wikipedia.org/wiki/English_plurals) in some spoken languages, while other languages have [simple rules](https://en.wikipedia.org/wiki/Turkish_grammar#Inflectional_suffixes).\n\n`GrammaticalNumber` is heavily inspired by [`ActiveSupport::Inflector`](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb) known from the [Ruby on Rails](https://rubyonrails.org) web framework.\n\n\n## Usage\n\n### Turn singular words to plural\n\n```swift\n\"person\".pluralized()               // people\n\"center\".pluralized()               // centers\n\"sheep\".pluralized()                // sheep\n\"knife\".pluralized()                // knives\n\"mouse\".pluralized()                // mice\n\"money\".pluralized()                // money\n\"axis\".pluralized()                 // axes\n\"item\".pluralized()                 // items\n\"status\".pluralized()               // statuses\n\"fox\".pluralized()                  // foxes\n\"move\".pluralized()                 // moves\n\"tooth\".pluralized()                // teeth\n\"foxes\".pluralized()                // foxes\n\"millennium\".pluralized()           // millennia\n\"child\".pluralized()                // children\n\"matrix\".pluralized()               // matrices\n\"man\".pluralized()                  // men\n\"ox\".pluralized()                   // oxen\n\"radius\".pluralized()               // radii\n\"grandchild\".pluralized()           // grandchildren\n```\n\n### Turn plural words to singular\n\n```swift\n\"children\".singularized()           // child\n\"tables\".singularized()             // table\n\"computers\".singularized()          // computer\n\"mice\".singularized()               // mouse\n\"teeth\".singularized()              // tooth\n\"axes\".singularized()               // axis\n\"women\".singularized()              // woman\n\"grandchildren\".singularized()      // grandchild\n```\n\n### Case Sensitivity\n\n`GrammaticalNumber` will try to match the letter casing of your input word.\nLowercased, uppercased and capitalized words are supported.\n\n```swift\n\"tooth\".pluralized()                // teeth\n\"TOOTH\".pluralized()                // TOOTH\n\"Tooth\".pluralized()                // Teeth\n```\n\n### Add count to words\n\nPrepends the pluralized `String` with `count`.\nIf the `count` is `0`, the singular word will be used. \n\n```swift\n\"child\".pluralized(count: 0)        // 0 children\n\"child\".pluralized(count: 1)        // 1 child\n\"child\".pluralized(count: 3)        // 3 children\n\n\"knife\".pluralized(count: 0)        // 0 knives\n\"knife\".pluralized(count: 1)        // 1 knife\n\"knife\".pluralized(count: 3)        // 3 knives\n\n\"sheep\".pluralized(count: 0)        // 0 sheep\n\"sheep\".pluralized(count: 1)        // 1 sheep\n\"sheep\".pluralized(count: 3)        // 3 sheep\n```\n\n## Define Custom Rules\n\n### Uncountable Rule\n\n```swift\nlet rule: GrammaticalNumberRule = .uncountable(\"money\")\n```\n\n`money` will never change.\n\n### Irregular Rule: Singular from plural\n\n```swift\nlet rule: GrammaticalNumberRule = .irregular(\"tooth\", \"teeth\")\n```\n\nTurns `tooth` to `teeth` when used with `pluralized()`.\nTurns `teeth` to `tooth` when used with `singularized()`.\n\n### Plural Rule: Plural from singular with regular expression\n\n```swift\nlet rule: GrammaticalNumberRule = .plural(#\"^(m|l)ouse$\"#, #\"$1ice\"#)\n```\n\n`mouse` becomes `mice` and `louse` becomes `lice`.\n\n### Singular Rule: Singular from plural with regular expression\n\n```swift\nlet rule: GrammaticalNumberRule = .singular(#\"(matr)ices$\"#, #\"$1ix\"#)\n```\n\nTurns `matrices` to `matrix`.\n\n### Apply rule, so it becomes available\n\n```swift\nGrammaticalNumberRule.add(rule)\n```\n\n## Support other languages\n\nIn order to support other languages, pass the `language` parameter to your custom rules.\nCall `.pluralized(language: yourLanguage)` with the same `language` value — like so: `.pluralized(language: \"tr\")`\n\n### Example for the turkish language (`tr`)\n\n```swift\nGrammaticalNumberRule.add(.plural(#\"([aoıu][^aoıueöiü]{0,6})$\"#, #\"$1lar\"#), language: \"tr\")\nGrammaticalNumberRule.add(.plural(#\"([eöiü][^aoıueöiü]{0,6})$\"#, #\"$1ler\"#), language: \"tr\")\nGrammaticalNumberRule.add(.singular(#\"l[ae]r$\"#, #\"\"#), language: \"tr\")\n```\n\n```swift\n\"kitap\".pluralized(language: \"tr\")              // kitaplar\n\"yemek\".pluralized(language: \"tr\")              // yemekler\n```\n\n## Contact\n\n* Devran \"Cosmo\" Uenal\n* Twitter: [@maccosmo](http://twitter.com/maccosmo)\n* LinkedIn: [devranuenal](https://www.linkedin.com/in/devranuenal)\n\n## Other Projects\n\n* [BinaryKit](https://github.com/Cosmo/BinaryKit) — BinaryKit helps you to break down binary data into bits and bytes and easily access specific parts.\n* [Clippy](https://github.com/Cosmo/Clippy) — Clippy from Microsoft Office is back and runs on macOS! Written in Swift.\n* [HackMan](https://github.com/Cosmo/HackMan) — Stop writing boilerplate code yourself. Let hackman do it for you via the command line.\n* [ISO8859](https://github.com/Cosmo/ISO8859) — Convert ISO8859 1-16 Encoded Text to String in Swift. Supports iOS, tvOS, watchOS and macOS.\n* [SpriteMap](https://github.com/Cosmo/SpriteMap) — SpriteMap helps you to extract sprites out of a sprite map. Written in Swift.\n* [StringCase](https://github.com/Cosmo/StringCase) — Converts String to lowerCamelCase, UpperCamelCase and snake_case. Tested and written in Swift.\n* [TinyConsole](https://github.com/Cosmo/TinyConsole) — TinyConsole is a micro-console that can help you log and display information inside an iOS application, where having a connection to a development computer is not possible.\n\n## License\n\nGrammaticalNumber is released under the [MIT License](http://www.opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmo%2Fgrammaticalnumber","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcosmo%2Fgrammaticalnumber","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcosmo%2Fgrammaticalnumber/lists"}