{"id":13847133,"url":"https://github.com/martinandert/inflected","last_synced_at":"2025-05-16T13:03:27.070Z","repository":{"id":14678433,"uuid":"17397588","full_name":"martinandert/inflected","owner":"martinandert","description":"A port of ActiveSupport's inflector to Node.js and the browser.","archived":false,"fork":false,"pushed_at":"2021-08-11T02:31:23.000Z","size":243,"stargazers_count":166,"open_issues_count":7,"forks_count":22,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T08:34:10.360Z","etag":null,"topics":["inflection","javascript","pluralization","transliteration"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/martinandert.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}},"created_at":"2014-03-04T10:00:05.000Z","updated_at":"2025-01-12T20:04:54.000Z","dependencies_parsed_at":"2022-09-16T22:51:26.337Z","dependency_job_id":null,"html_url":"https://github.com/martinandert/inflected","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinandert%2Finflected","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinandert%2Finflected/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinandert%2Finflected/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinandert%2Finflected/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinandert","download_url":"https://codeload.github.com/martinandert/inflected/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535826,"owners_count":22087398,"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":["inflection","javascript","pluralization","transliteration"],"created_at":"2024-08-04T18:00:55.310Z","updated_at":"2025-05-16T13:03:27.048Z","avatar_url":"https://github.com/martinandert.png","language":"JavaScript","readme":"# inflected\n\n[![Travis build status](https://img.shields.io/travis/martinandert/inflected/master.svg)](https://travis-ci.org/martinandert/inflected)\n[![npm downloads](https://img.shields.io/npm/dm/inflected.svg)](https://npmjs.com/package/inflected)\n[![no dependencies](https://img.shields.io/badge/dependencies-none-brightgreen.svg)](https://npmjs.com/package/inflected)\n[![license](https://img.shields.io/github/license/martinandert/inflected.svg)](https://github.com/martinandert/inflected/blob/master/LICENSE.txt)\n\nA port of ActiveSupport's inflector to Node.js. Also usable in the browser.\n\n\n## Installation\n\nInstall via npm:\n\n```bash\n% npm install inflected\n```\n\nOr via yarn:\n\n```bash\n% yarn add inflected\n```\n\nThe UMD build is also available on [unpkg](https://unpkg.com/), adding a `Inflector` object to the global scope.\n\n```html\n\u003cscript src=\"https://unpkg.com/inflected/dist/umd/inflected.min.js\"\u003e\u003c/script\u003e\n```\n\n\n## Usage\n\nThe module exports an object with several utility functions.\n\n```js\nvar Inflector = require('inflected');\n\nInflector.pluralize('Category')  // =\u003e 'Categories'\n```\n\nIf using ES modules, you can cherry-pick only the functions you're interested in:\n\n```js\nimport { pluralize } from 'inflected';\n\npluralize('Category')  // =\u003e 'Categories'\n```\n\nHere is the complete API reference:\n\n\n### Inflector.pluralize\n\n```js\nstring pluralize(string word[, string locale])\n```\n\nReturns the plural form of the word in the string.\n\nIf passed an optional `locale` parameter, the word will be pluralized using rules defined for that language. By default, this parameter is set to \"en\".\n\n```js\nInflector.pluralize('post')          // =\u003e 'posts'\nInflector.pluralize('octopus')       // =\u003e 'octopi'\nInflector.pluralize('sheep')         // =\u003e 'sheep'\nInflector.pluralize('words')         // =\u003e 'words'\nInflector.pluralize('CamelOctopus')  // =\u003e 'CamelOctopi'\nInflector.pluralize('ley', 'es')     // =\u003e 'leyes'\n```\n\n\n### Inflector.singularize\n\n```js\nstring singularize(string word[, string locale])\n```\n\nThe reverse of `pluralize`, returns the singular form of a word in a string.\n\nIf passed an optional `locale` parameter, the word will be singularized using rules defined for that language. By default, this parameter is set to \"en\".\n\n```js\nInflector.singularize('posts')        // =\u003e 'post'\nInflector.singularize('octopi')       // =\u003e 'octopus'\nInflector.singularize('sheep')        // =\u003e 'sheep'\nInflector.singularize('word')         // =\u003e 'word'\nInflector.singularize('CamelOctopi')  // =\u003e 'CamelOctopus'\nInflector.singularize('leyes', 'es')  // =\u003e 'ley'\n```\n\n\n### Inflector.camelize\n\n```js\nstring camelize(string term[, boolean uppercaseFirstLetter])\n```\n\nBy default, `camelize` converts strings to UpperCamelCase. If the second argument is set to `false` then `camelize` produces lowerCamelCase.\n\n```js\nInflector.camelize('foo_bar')         // =\u003e 'FooBar'\nInflector.camelize('foo_bar', false)  // =\u003e 'fooBar'\n```\n\nAs a rule of thumb you can think of `camelize` as the inverse of `underscore`, though there are cases where that does not hold:\n\n```js\nInflector.camelize(Inflector.underscore('SSLError'))  // =\u003e 'SslError'\n```\n\n### Inflector.underscore\n\n```js\nstring underscore(string camelCasedWord)\n```\n\nMakes an underscored, lowercase form from the expression in the string.\n\n```js\nInflector.underscore('FooBar')  // =\u003e 'foo_bar'\n```\n\nAs a rule of thumb you can think of `underscore` as the inverse of `camelize`, though there are cases where that does not hold:\n\n```js\nInflector.camelize(Inflector.underscore('SSLError'))  // =\u003e 'SslError'\n```\n\n\n### Inflector.humanize\n\n```js\nstring humanize(string lowerCaseAndUnderscoredWord[, object options])\n```\n\nCapitalizes the first word, turns underscores into spaces, and strips a trailing \"_id\" if present.\n\nLike `titleize`, this is meant for creating pretty output.\n\nThe capitalization of the first word can be turned off by setting the `capitalize` option key to `false`. By default, this option is `true`.\n\n```js\nInflector.humanize('employee_salary')                   // =\u003e 'Employee salary'\nInflector.humanize('author_id')                         // =\u003e 'Author'\nInflector.humanize('author_id', { capitalize: false })  // =\u003e 'author'\n```\n\n\n### Inflector.titleize\n\n```js\nstring titleize(string sentence)\n```\n\nCapitalizes all the words and replaces some characters in the string to create a nicer looking title. `titleize` is meant for creating pretty output.\n\n```js\nInflector.titleize('man from the boondocks')   // =\u003e 'Man From The Boondocks'\nInflector.titleize('x-men: the last stand')    // =\u003e 'X Men: The Last Stand'\nInflector.titleize('TheManWithoutAPast')       // =\u003e 'The Man Without A Past'\nInflector.titleize('raiders_of_the_lost_ark')  // =\u003e 'Raiders Of The Lost Ark'\n```\n\n\n### Inflector.tableize\n\n```js\nstring tableize(string className)\n```\n\nCreate the name of a table like Rails does for models to table names. This method uses the `pluralize` method on the last word in the string.\n\n```js\nInflector.tableize('RawScaledScorer')  // =\u003e 'raw_scaled_scorers'\nInflector.tableize('egg_and_ham')      // =\u003e 'egg_and_hams'\nInflector.tableize('fancyCategory')    // =\u003e 'fancy_categories'\n```\n\n\n### Inflector.classify\n\n```js\nstring classify(string tableName)\n```\n\nCreate a class name from a plural table name like Rails does for table names to models.\n\n```js\nInflector.classify('egg_and_hams')  // =\u003e 'EggAndHam'\nInflector.classify('posts')         // =\u003e 'Post'\n```\n\nSingular names are not handled correctly:\n\n```js\nInflector.classify('business')  // =\u003e 'Busines'\n```\n\n\n### Inflector.dasherize\n\n```js\nstring dasherize(string underscoredWord)\n```\n\nReplaces underscores with dashes in the string.\n\n```js\nInflector.dasherize('puni_puni')  // =\u003e 'puni-puni'\n```\n\n\n### Inflector.foreignKey\n\n```js\nstring foreignKey(string className[, boolean separateClassNameAndIdWithUnderscore])\n```\n\nCreates a foreign key name from a class name. `separateClassNameAndIdWithUnderscore` sets whether the method should put \"_\" between the name and \"id\" (default: `true`).\n\n```js\nInflector.foreignKey('Message')         // =\u003e 'message_id'\nInflector.foreignKey('Message', false)  // =\u003e 'messageid'\n```\n\n\n### Inflector.ordinal\n\n```js\nstring ordinal(object number)\n```\n\nReturns the suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.\n\n```js\nInflector.ordinal(1)      // =\u003e 'st'\nInflector.ordinal(2)      // =\u003e 'nd'\nInflector.ordinal(1002)   // =\u003e 'nd'\nInflector.ordinal(1003)   // =\u003e 'rd'\nInflector.ordinal(-11)    // =\u003e 'th'\nInflector.ordinal(-1021)  // =\u003e 'st'\n```\n\n\n### Inflector.ordinalize\n\n```js\nstring ordinalize(object number)\n```\n\nTurns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.\n\n```js\nInflector.ordinalize(1)      // =\u003e '1st'\nInflector.ordinalize(2)      // =\u003e '2nd'\nInflector.ordinalize(1002)   // =\u003e '1002nd'\nInflector.ordinalize(1003)   // =\u003e '1003rd'\nInflector.ordinalize(-11)    // =\u003e '-11th'\nInflector.ordinalize(-1021)  // =\u003e '-1021st'\n```\n\n\n### Inflector.inflections\n\n```js\nInflections inflections([string locale])\ninflections([string locale], [function(Inflections) fn])\n```\n\nA singleton instance of the internal Inflections class is yielded by this function, which can then be used to specify additional inflection rules. If passed an optional locale, rules for other languages can be specified. The default locale is \"en\". Only rules for English are provided by this library.\n\n```js\nInflector.inflections('en', function(inflect) {\n  inflect.plural(/^(ox)$/i, '$1$2en');\n  inflect.singular /^(ox)en/i, '$1');\n\n  inflect.irregular('octopus', 'octopi');\n\n  inflect.uncountable('equipment', 'snow');\n});\n```\n\nNew rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the pluralization and singularization rules that is run. This guarantees that your rules run before any of the rules that may already have been loaded.\n\n\n### Inflector.transliterate\n\n```js\nstring transliterate(string sentence[, object options])\n```\n\nReplaces non-ASCII characters with an ASCII approximation, or if none exists, a replacement character which defaults to \"?\".\n\n```js\nInflector.transliterate('Ærøskøbing')  // =\u003e 'AEroskobing'\n```\n\nDefault approximations are provided for Western/Latin characters, e.g, \"ø\", \"ñ\", \"é\", \"ß\", etc.\n\nThis method is I18n-aware, so you can set up custom approximations for a locale. This can be useful, for example, to transliterate German's \"ü\" and \"ö\" to \"ue\" and \"oe\", or to add support for transliterating Russian to ASCII.\n\nIn order to make your custom transliterations available, you must set them using the `approximate` helper function:\n\n```js\nInflector.transliterations('de', function(t) {\n  t.approximate('ü', 'ue');\n  t.approximate('ö', 'oe');\n});\n```\n\nNow you can have different transliterations for each locale:\n\n```js\nInflector.transliterate('Jürgen')                    // =\u003e 'Jurgen'\nInflector.transliterate('Jürgen', { locale: 'de' })  // =\u003e 'Juergen'\n```\n\n\n### Inflector.parameterize\n\n```js\nstring parameterize(string sentence[, object options])\n```\n\nReplaces special characters in a string so that it may be used as part of a 'pretty' URL.\n\n```js\nInflector.parameterize('Donald E. Knuth')                      // =\u003e 'donald-e-knuth'\nInflector.parameterize('Donald E. Knuth', { separator: '+' })  // =\u003e 'donald+e+knuth'\n```\n\nAs of v2.1, there's also a `preserveCase` option:\n\n```js\nInflector.parameterize('Donald E. Knuth', { preserveCase: true })  // =\u003e 'Donald-E-Knuth'\n```\n\n\n### Inflector.constantify\n\n```js\nstring constantify(string words)\n```\n\nConverts words (camelCased, under_scored, or dasherized) to CONSTANT_CASE.\n\n```js\nInflector.constantify('bankAccount')   // =\u003e 'BANK_ACCOUNT'\nInflector.constantify('bank-account')  // =\u003e 'BANK_ACCOUNT'\nInflector.constantify('bank_account')  // =\u003e 'BANK_ACCOUNT'\nInflector.constantify('Bank Account')  // =\u003e 'BANK_ACCOUNT'\n```\n\n\n\n## Contributing\n\nHere's a quick guide:\n\n1. Fork the repo and `make install`.\n2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: `make test`.\n3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or are fixing a bug, we need a test!\n4. Make the test pass.\n5. Push to your fork and submit a pull request.\n\n\n## Licence\n\nReleased under The MIT License.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinandert%2Finflected","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinandert%2Finflected","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinandert%2Finflected/lists"}