@postxl/generator 0.44.0 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@ const toPascalCase = (str) => {
40
40
  return s.charAt(0).toUpperCase() + s.slice(1);
41
41
  };
42
42
  exports.toPascalCase = toPascalCase;
43
- const irregularPlurals = {
43
+ const IRREGULAR_PLURALS = Object.entries({
44
44
  alumnus: 'alumni',
45
45
  analysis: 'analyses',
46
46
  appendix: 'appendices',
@@ -68,14 +68,24 @@ const irregularPlurals = {
68
68
  syllabus: 'syllabi',
69
69
  synopsis: 'synopses',
70
70
  thesis: 'theses',
71
- };
71
+ });
72
72
  /**
73
73
  * Returns a pluralized version of the given string based on the count.
74
74
  */
75
75
  const pluralize = (s, count = 2) => {
76
+ // NOTE: If there's one of something we simply use the singluar form.
76
77
  if (count === 1) {
77
78
  return s;
78
79
  }
80
+ // NOTE: For plural forms, we first check whether a word is irregular.
81
+ const lower = s.toLowerCase();
82
+ for (const [singular, plural] of IRREGULAR_PLURALS) {
83
+ // NOTE: We check that items *end with* a given word becase we use combined words
84
+ // like `UserHistory` as input values of this function.
85
+ if (lower.endsWith(singular)) {
86
+ return s.slice(0, -singular.length + 1) + plural.slice(1);
87
+ }
88
+ }
79
89
  if (s.endsWith('y') &&
80
90
  !s.endsWith('ay') &&
81
91
  !s.endsWith('ey') &&
@@ -87,13 +97,6 @@ const pluralize = (s, count = 2) => {
87
97
  if (s.endsWith('s')) {
88
98
  return s;
89
99
  }
90
- //check if word ends with any irregular plurals
91
- const lower = s.toLowerCase();
92
- for (const [irregularPlural, irregularSingular] of Object.entries(irregularPlurals)) {
93
- if (lower.endsWith(irregularPlural)) {
94
- return s.slice(0, -irregularPlural.length + 1) + irregularSingular.slice(1);
95
- }
96
- }
97
100
  return s + 's';
98
101
  };
99
102
  exports.pluralize = pluralize;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postxl/generator",
3
- "version": "0.44.0",
3
+ "version": "0.44.1",
4
4
  "main": "./dist/generator.js",
5
5
  "typings": "./dist/generator.d.ts",
6
6
  "bin": {