How to use the singular function from pluralize

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

pluralize.singular converts a plural word to its corresponding singular form.

218
219
220
221
222
223
224
225
226

  this.copyHandleBarsTemplate('routes/route.hbs', routesPath, {
    modelName: this.getModelNameFromTableName(modelName),
    modelNameDasherized,
    modelNameReadablePlural: plural(readableModelName),
    modelNameReadableSingular: singular(readableModelName),
    isMongoDB: dbDialect === 'mongodb',
  });
}
fork icon2
star icon51
watch icon10

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
function embed(resource, e) {
  e &&
    [].concat(e).forEach((externalResource) => {
      if (db.get(externalResource).value) {
        const query = {}
        const singularResource = pluralize.singular(name)
        query[`${singularResource}${opts.foreignKeySuffix}`] = resource.id
        resource[externalResource] = db
          .get(externalResource)
          .filter(query)
fork icon0
star icon2
watch icon1

How does pluralize.singular work?

pluralize.singular() is a function that takes a string as input and returns its singular form by applying a set of predefined rules for converting plural nouns to singular nouns.

It checks the string against a list of irregular nouns and applies the corresponding transformation, and if no match is found, it applies a set of regular expression rules to transform the string to its singular form.

9
10
11
12
13
14
15
16
17
18
19
20
const splitCamelCase = (string) => {
  return string.split(/(?=[A-Z])/).map((s) => s.toLowerCase())[0]
}


const getSchemaName = (rawName) => {
  const schemaName = pluralize.singular(changeCase.pascalCase(splitCamelCase(rawName)))
  return `${schemaName}Schema`
}


const getSchemaImportName = (name) => {
fork icon0
star icon2
watch icon1

+ 29 other calls in file

10
11
12
13
14
15
16
17
18
19
20
21
const splitCamelCase = (string) => {
  return string.split(/(?=[A-Z])/).map((s) => s.toLowerCase())[0]
}


const getSchemaImportName = (rawName) => {
  const singularName = pluralize.singular(lowercaseFirstLetter(splitCamelCase(rawName)))
  return `${singularName}.schema`
}


const getSchemaName = (rawName) => {
fork icon0
star icon2
watch icon1

+ 5 other calls in file

Ai Example

1
2
3
4
5
6
7
const pluralize = require("pluralize");
console.log(pluralize.singular("cats")); // 'cat'
console.log(pluralize.singular("dogs")); // 'dog'
console.log(pluralize.singular("people")); // 'person'
console.log(pluralize.singular("sheep")); // 'sheep'
console.log(pluralize.singular("goose")); // 'goose'
console.log(pluralize.singular("mice")); // 'mouse'

In the above example, pluralize.singular() takes a plural word and returns its singular form based on the predefined rules.

584
585
586
587
588
589
590
591
592
593
}

// for example, "crew member" or "photon torpedo"
// TODO account for modifier a complex phrase for example "hot (chicken strips)"
kindOfConcept({ config, modifier, object }) {
  const objectId = pluralize.singular(object)
  const modifierId = pluralize.singular(modifier)
  const modifierObjectId = `${modifierId}_${objectId}`

  const objectSingular = pluralize.singular(object)
fork icon0
star icon1
watch icon2

+ 19 other calls in file

417
418
419
420
421
422
423
424
425
426
notes: 'wants is xfx between wanter and wantee',
match: ({context}) => context.same && context.same.marker == 'xfx',
// debug: 'call3',
apply: ({context, km, config}) => {
  const papi = km('properties').api
  const singular = pluralize.singular(context.word)
  const plural = pluralize.plural(context.word)
  const args = context.same.arguments.value;
  papi.createBinaryRelation(config, singular, [singular, plural], args[0].word, args[1].word)
},
fork icon0
star icon1
watch icon2

+ 23 other calls in file

130
131
132
133
134
135
136
137
138
139
    verbatim: `I don't know about ${g({ ...one, paraphrase: true})}` 
  }
  context.isResponse = true
  return
}
const twoId = pluralize.singular(two.value);
if (!api.conceptExists(twoId)) {
  context.evalue = {
    verbatim: `I don't know about ${g({ ...two, paraphrase: true})}` 
  }
fork icon0
star icon1
watch icon2

+ 23 other calls in file

91
92
93
94
95
96
97
98
99
100
101
102


wordNumber = (word, toPlural) => {
  if (toPlural) {
    return pluralize.plural(word)
  } else {
    return pluralize.singular(word)
  }
}


module.exports = {
fork icon0
star icon1
watch icon0

26
27
28
29
30
31
32
33
34
35

function embed(resource, e) {
  e && [].concat(e).forEach(externalResource => {
    if (db.get(externalResource).value) {
      const query = {};
      const singularResource = pluralize.singular(name);
      query[`${singularResource}${opts.foreignKeySuffix}`] = resource.id;
      resource[externalResource] = db.get(externalResource).filter(query).value();
    }
  });
fork icon0
star icon0
watch icon1

78
79
80
81
82
83
84
85
86
87
}

var entity = names.entity;

// Create singular version:
var singular = pluralize.singular(entity);

// A or an. This part is naive - "a umbrella" "a unicorn" would be outputted, but it's close enough!
var vowelRegex = '^[aieouAIEOU].*';
var startsWithVowel = singular.match(vowelRegex);
fork icon0
star icon0
watch icon2

+ 8 other calls in file

504
505
506
507
508
509
510
511
512
513
  res.end({ error: "undefined search query" });
}
let item = req.params.item.toLowerCase();

// take the spaces out and convert to a singluar version
item = pluralize.singular(item.replace(/\s/g, ""));

console.log("In Controller getProducts: item:", item);

if (staticProducts.includes(item)) {
fork icon0
star icon0
watch icon2

+ 2 other calls in file

146
147
148
149
150
151
152
153
154
155
    },

    singular: (rule) => {
        let func_name = "Rule:scope:singular";
        console.log(`${func_name}`);
        return pluralize.singular(rule.scope);
    },
},
assets: {
    selected: {
fork icon0
star icon0
watch icon1

13
14
15
16
17
18
19
20
21
22
23
24
25
export default function SearchLandingPage(props) {


  let searchQuery = props.match.params.searchQuery


  if (pluralize.isPlural(searchQuery)) {
    searchQuery = pluralize.singular(searchQuery)
  }


  var externalRecipes = useSelector((state) => state.externalRecipes)
  var searchConfig = useSelector((state) => state.searchConfig)
fork icon0
star icon0
watch icon0