pluralizer.js 495 B

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. const singulars = {
  3. pronoun: 'it',
  4. is: 'is',
  5. was: 'was',
  6. this: 'this'
  7. }
  8. const plurals = {
  9. pronoun: 'they',
  10. is: 'are',
  11. was: 'were',
  12. this: 'these'
  13. }
  14. module.exports = class Pluralizer {
  15. constructor (singular, plural) {
  16. this.singular = singular
  17. this.plural = plural
  18. }
  19. pluralize (count) {
  20. const one = count === 1
  21. const keys = one ? singulars : plurals
  22. const noun = one ? this.singular : this.plural
  23. return { ...keys, count, noun }
  24. }
  25. }