How to use the pluralize function from inflection

Find comprehensive JavaScript inflection.pluralize code examples handpicked from public code repositorys.

inflection.pluralize is a function that returns the plural form of a word in English.

105
106
107
108
109
110
111
112
113
114
115
116
  return inflection.singularize(str);
}
exports.singularize = singularize;


function pluralize(str) {
  return inflection.pluralize(str);
}
exports.pluralize = pluralize;


function format(arr, dialect) {
fork icon0
star icon3
watch icon0

1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
/// Return: string
///   The name the model in plural form.
///
/// See: Model.static getSingularName
static getPluralModelName() {
  return Inflection.pluralize(this.getSingularName());
}

getPluralModelName() {
  return this.constructor.getPluralModelName();
fork icon0
star icon3
watch icon2

How does inflection.pluralize work?

inflection.pluralize is a function provided by the Inflection library that returns the plural form of a given word or phrase, using pre-defined rules or custom rules defined by the user. The function takes a string as input and returns the pluralized string. The pluralization rules are applied based on the language specified or the default language used by the library. The library can handle irregular plurals and uncountable nouns.

5
6
7
8
9
10
11
12
13
14
15
16
const singularName = (name) => {
  return inflection.singularize(name)
}


const pluralName = (name) => {
  return inflection.pluralize(name)
}


const singularVariable = (name) => {
  return inflection.camelize(inflection.singularize(name), true)
fork icon0
star icon0
watch icon1

1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
if (typeof(opts) == "function") { callback = opts; opts = undefined; }

var self = this;

//connector info
var connectorType = inflection.pluralize(this.get('type'));
var connector = this.getEntityId(this);
if (!connector) {
  if (typeof(callback) === 'function') {
    var error = 'Error in getConnections - no uuid specified.';
fork icon0
star icon0
watch icon1

+ 2 other calls in file

Ai Example

1
2
3
4
5
6
const inflection = require("inflection");

const singular = "person";
const plural = inflection.pluralize(singular);

console.log(plural); // "people"

In this example, we first import the inflection library using the require statement. We then define a string variable called singular with a value of 'person'. We then call the inflection.pluralize function, passing in the singular string as an argument. This function returns the plural form of the string, which we store in a new variable called plural. Finally, we log the value of plural to the console, which should output 'people'.

120
121
122
123
124
125
126
127
128
129
130
 */
ModelBuilder.prototype.define = function defineClass(className, properties, settings, parent) {
  const modelBuilder = this;
  const args = slice.call(arguments);
  const pluralName = (settings && settings.plural) ||
    inflection.pluralize(className);


  const httpOptions = (settings && settings.http) || {};
  let pathName = httpOptions.path || pluralName;

fork icon0
star icon0
watch icon1

705
706
707
708
709
710
711
712
713
714
    blueprintName = options.blueprintName.slice(0, options.blueprintName.indexOf('-test'));
  }
  if (options.pod && options.hasPathToken) {
    return path.join(options.podPath, options.dasherizedModuleName);
  }
  return inflector.pluralize(blueprintName);
},
__root__(options) {
  if (options.inRepoAddon) {
    let addon = findAddonByName(project, options.inRepoAddon);
fork icon0
star icon0
watch icon159

+ 13 other calls in file

733
734
735
736
737
738
739
740
741
742
    var name = this.wzName;
    this.name = name.toLowerCase();
    this.nameCap = inflection.capitalize(name);
    this.sqlName = isEmpty(this.sqlName) ? name : this.sqlName;
    this.label = isEmpty(this.label) ? this.wzName : this.label;
    this.namePlural = isEmpty(this.namePlural) ? inflection.pluralize(name) : this.namePlural.toLowerCase();
    this.namePluralCap = inflection.capitalize(this.namePlural);
    this.labelPlural = isEmpty(this.labelPlural) ? inflection.pluralize(this.wzName) : this.labelPlural;
    _md.rdbmsitem.prototype.wzInitialize.call(this, ctx);
}
fork icon0
star icon0
watch icon1

+ 11 other calls in file

31
32
33
34
35
36
37
38
39
40
});
Handlebars.registerHelper("camelCase", function (input, type) {
    return `${inflection.camelize(input.replace("-", "_"), true)}${type || ""}`;
});
Handlebars.registerHelper("pluralize", function (input) {
    return inflection.pluralize(input);
});
Handlebars.registerHelper("camelize", function (input) {
    return inflection.pluralize(inflection.camelize(input.replace("-", "_"), true));
});
fork icon0
star icon0
watch icon1

+ 9 other calls in file