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 PriceQuizzes to priceQuiz #1

Merged
merged 1 commit into from
Oct 24, 2022

Conversation

marcemira
Copy link

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.

@marcemira marcemira merged commit eb39728 into main Oct 24, 2022
Martinarbez added a commit that referenced this pull request Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant