Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix/Replaces pluralize with inflector, fails to singularize resource with multiple words #323

Merged

Conversation

marcemira
Copy link
Contributor

@marcemira marcemira commented Oct 24, 2022

Scopes:

  • 🐞 Fix

Summary

Given a resource name called "PriceQuiz", an endpoint "/priceQuizzes" was expected, but due to the singularize method of the pluralize library, it produces the string priceQuizz instead.

Quick test app

console.log("----------------- Using Pluralize Package -------------------------")

var pluralize = require('pluralize')
console.log(`Pluralize "quiz" -> ${pluralize('quiz')}`)
console.log(`Singularize "quizzes" -> ${pluralize.singular('quizzes')}`)
console.log(`Pluralize "priceQuiz" -> ${pluralize('priceQuiz')}`)
console.log(`Singularize "priceQuizzes" -> ${pluralize.singular('priceQuizzes')}`)

console.log("----------------- Using Inflection Package -------------------------")

var inflection = require( 'inflection' );
console.log(`Pluralize "quiz" -> ${inflection.pluralize('quiz')}`)
console.log(`Singularize "quizzes" -> ${inflection.singularize('quizzes')}`)
console.log(`Pluralize "priceQuiz" -> ${inflection.pluralize('priceQuiz')}`)
console.log(`Singularize "priceQuizzes" -> ${inflection.singularize('priceQuizzes')}`)

Results

----------------- Using Pluralize Package -------------------------
Pluralize "quiz" -> quizzes
Singularize "quizzes" -> quiz
Pluralize "priceQuiz" -> priceQuizs
Singularize "priceQuizzes" -> priceQuizz

----------------- Using Inflection Package -------------------------
Pluralize "quiz" -> quizzes
Singularize "quizzes" -> quiz
Pluralize "priceQuiz" -> priceQuizzes
Singularize "priceQuizzes" -> priceQuiz

Digging into the main issue

According to plurals/pluralize#177, the library produces several inconsistencies across a large number of english words. Several other individual issues might point out that the library fails on a lot more words.

Proposal

Use Inflection (https://github.com/dreamerslab/node.inflection) as an alternative to pluralize.

Copy link
Member

@joelalejandro joelalejandro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@joelalejandro joelalejandro self-requested a review October 24, 2022 19:05
@joelalejandro joelalejandro reopened this Oct 24, 2022
@joelalejandro joelalejandro merged commit 572394f into kurierjs:main Oct 24, 2022
@joelalejandro joelalejandro added this to the 1.2.1 milestone Oct 24, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants