Skip to content
New issue

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

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

Already on GitHub? Sign in 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 merged commit 572394f into kurierjs:main Oct 24, 2022
@joelalejandro joelalejandro added this to the 1.2.1 milestone Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants