@bccampus/utils 0.2.2 → 0.3.0

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.
Files changed (216) hide show
  1. package/README.md +3 -8
  2. package/dist/array/chunk.cjs +13 -5
  3. package/dist/array/chunk.d.ts +7 -0
  4. package/dist/array/chunk.js +14 -7
  5. package/dist/array/chunk.test.d.ts +1 -0
  6. package/dist/date/iso-date-time/constants.cjs +27 -0
  7. package/dist/date/iso-date-time/constants.d.ts +9 -0
  8. package/dist/date/iso-date-time/constants.js +19 -0
  9. package/dist/date/iso-date-time/index.cjs +8 -0
  10. package/dist/date/iso-date-time/index.d.ts +5 -0
  11. package/dist/date/iso-date-time/index.js +3 -0
  12. package/dist/date/iso-date-time/iso-date-time.arithmetic.test.d.ts +1 -0
  13. package/dist/date/iso-date-time/iso-date-time.cjs +232 -0
  14. package/dist/date/{iso-date-time.d.ts → iso-date-time/iso-date-time.d.ts} +3 -32
  15. package/dist/date/iso-date-time/iso-date-time.format.test.d.ts +1 -0
  16. package/dist/date/iso-date-time/iso-date-time.js +231 -0
  17. package/dist/date/iso-date-time/iso-date-time.test.d.ts +1 -0
  18. package/dist/date/iso-date-time/types.cjs +0 -0
  19. package/dist/date/iso-date-time/types.d.ts +25 -0
  20. package/dist/date/iso-date-time/types.js +0 -0
  21. package/dist/duration/add-durations.cjs +5 -8
  22. package/dist/duration/add-durations.js +5 -9
  23. package/dist/duration/duration.test.d.ts +1 -0
  24. package/dist/duration/is-duration.cjs +4 -3
  25. package/dist/duration/is-duration.js +5 -5
  26. package/dist/duration/to-number.cjs +11 -10
  27. package/dist/duration/to-number.d.ts +1 -1
  28. package/dist/duration/to-number.js +11 -11
  29. package/dist/format/formatter.cjs +31 -31
  30. package/dist/format/formatter.d.ts +4 -4
  31. package/dist/format/formatter.js +32 -37
  32. package/dist/format/formatter.test.d.ts +1 -0
  33. package/dist/format/stringfy.test.d.ts +1 -0
  34. package/dist/format/stringify.cjs +34 -40
  35. package/dist/format/stringify.d.ts +1 -1
  36. package/dist/format/stringify.js +35 -42
  37. package/dist/format/template.cjs +25 -32
  38. package/dist/format/template.d.ts +3 -3
  39. package/dist/format/template.js +24 -33
  40. package/dist/format/template.test.d.ts +1 -0
  41. package/dist/index.cjs +0 -4
  42. package/dist/index.d.ts +0 -1
  43. package/dist/index.js +0 -4
  44. package/dist/object/get.cjs +5 -5
  45. package/dist/object/get.d.ts +1 -1
  46. package/dist/object/get.js +6 -7
  47. package/dist/object/get.test.d.ts +1 -0
  48. package/dist/object/is-object.cjs +5 -2
  49. package/dist/object/is-object.d.ts +1 -1
  50. package/dist/object/is-object.js +6 -4
  51. package/dist/object/is-object.test.d.ts +1 -0
  52. package/dist/object/omit.cjs +14 -16
  53. package/dist/object/omit.d.ts +1 -1
  54. package/dist/object/omit.js +15 -18
  55. package/dist/object/omit.test.d.ts +1 -0
  56. package/dist/object/pick.cjs +10 -9
  57. package/dist/object/pick.d.ts +1 -1
  58. package/dist/object/pick.js +9 -9
  59. package/dist/object/pick.test.d.ts +1 -0
  60. package/dist/object/set.cjs +13 -12
  61. package/dist/object/set.d.ts +1 -1
  62. package/dist/object/set.js +14 -14
  63. package/dist/object/set.test.d.ts +1 -0
  64. package/dist/path/file-url-to-path.cjs +10 -6
  65. package/dist/path/file-url-to-path.js +11 -8
  66. package/dist/path/file-url-to-path.test.d.ts +1 -0
  67. package/dist/path/normalize.cjs +41 -27
  68. package/dist/path/normalize.d.ts +8 -2
  69. package/dist/path/normalize.js +41 -28
  70. package/dist/path/normalize.test.d.ts +1 -0
  71. package/dist/set/difference.cjs +5 -6
  72. package/dist/set/difference.d.ts +1 -1
  73. package/dist/set/difference.js +6 -8
  74. package/dist/set/intersection.cjs +6 -9
  75. package/dist/set/intersection.d.ts +1 -1
  76. package/dist/set/intersection.js +7 -11
  77. package/dist/set/is-superset.cjs +5 -8
  78. package/dist/set/is-superset.d.ts +1 -1
  79. package/dist/set/is-superset.js +6 -10
  80. package/dist/set/set.test.d.ts +1 -0
  81. package/dist/set/symmetric-difference.cjs +6 -10
  82. package/dist/set/symmetric-difference.d.ts +1 -1
  83. package/dist/set/symmetric-difference.js +7 -12
  84. package/dist/set/union.cjs +5 -6
  85. package/dist/set/union.d.ts +1 -1
  86. package/dist/set/union.js +6 -8
  87. package/dist/string/capitalize.cjs +5 -2
  88. package/dist/string/capitalize.d.ts +1 -1
  89. package/dist/string/capitalize.js +6 -4
  90. package/dist/string/capitalize.test.d.ts +1 -0
  91. package/dist/string/normalize.cjs +7 -2
  92. package/dist/string/normalize.js +8 -4
  93. package/dist/string/normalize.test.d.ts +1 -0
  94. package/dist/string/pluralize/index.cjs +5 -4
  95. package/dist/string/pluralize/index.js +4 -5
  96. package/dist/string/pluralize/pluralize.cjs +162 -208
  97. package/dist/string/pluralize/pluralize.d.ts +4 -8
  98. package/dist/string/pluralize/pluralize.js +158 -205
  99. package/dist/string/pluralize/pluralize.test.d.ts +1 -0
  100. package/dist/string/pluralize/rules/index.cjs +8 -9
  101. package/dist/string/pluralize/rules/index.js +1 -6
  102. package/dist/string/pluralize/rules/irregular.cjs +55 -59
  103. package/dist/string/pluralize/rules/irregular.js +56 -61
  104. package/dist/string/pluralize/rules/pluralization.cjs +28 -36
  105. package/dist/string/pluralize/rules/pluralization.js +29 -38
  106. package/dist/string/pluralize/rules/singularization.cjs +27 -44
  107. package/dist/string/pluralize/rules/singularization.js +28 -46
  108. package/dist/string/pluralize/rules/uncountable.cjs +104 -110
  109. package/dist/string/pluralize/rules/uncountable.js +105 -112
  110. package/dist/string/pluralize/types.cjs +0 -1
  111. package/dist/string/pluralize/types.js +0 -1
  112. package/dist/string/slugify/index.cjs +2129 -2246
  113. package/dist/string/slugify/index.js +2130 -2248
  114. package/dist/string/slugify/slugify.test.d.ts +1 -0
  115. package/dist/string/strip-html-tags.cjs +4 -3
  116. package/dist/string/strip-html-tags.js +5 -5
  117. package/dist/string/strip-html-tags.test.d.ts +1 -0
  118. package/dist/string/to-int.cjs +14 -6
  119. package/dist/string/to-int.js +15 -8
  120. package/dist/string/to-int.test.d.ts +1 -0
  121. package/dist/string/to-sentence-case.cjs +6 -6
  122. package/dist/string/to-sentence-case.d.ts +1 -1
  123. package/dist/string/to-sentence-case.js +7 -8
  124. package/dist/string/to-sentence-case.test.d.ts +1 -0
  125. package/dist/string/trim.cjs +8 -7
  126. package/dist/string/trim.js +9 -9
  127. package/dist/string/trim.test.d.ts +1 -0
  128. package/dist/string/truncate.cjs +16 -15
  129. package/dist/string/truncate.js +17 -17
  130. package/dist/string/truncate.test.d.ts +1 -0
  131. package/dist/value/is-empty.cjs +30 -12
  132. package/dist/value/is-empty.d.ts +1 -1
  133. package/dist/value/is-empty.js +31 -14
  134. package/dist/value/value.test.d.ts +1 -0
  135. package/package.json +183 -67
  136. package/dist/array/index.cjs +0 -4
  137. package/dist/array/index.d.ts +0 -1
  138. package/dist/array/index.js +0 -4
  139. package/dist/date/index.cjs +0 -8
  140. package/dist/date/index.d.ts +0 -1
  141. package/dist/date/index.js +0 -8
  142. package/dist/date/iso-date-time.cjs +0 -256
  143. package/dist/date/iso-date-time.js +0 -256
  144. package/dist/duration/index.cjs +0 -8
  145. package/dist/duration/index.d.ts +0 -3
  146. package/dist/duration/index.js +0 -8
  147. package/dist/format/index.cjs +0 -13
  148. package/dist/format/index.d.ts +0 -3
  149. package/dist/format/index.js +0 -13
  150. package/dist/object/index.cjs +0 -12
  151. package/dist/object/index.d.ts +0 -5
  152. package/dist/object/index.js +0 -12
  153. package/dist/path/index.cjs +0 -6
  154. package/dist/path/index.d.ts +0 -2
  155. package/dist/path/index.js +0 -6
  156. package/dist/set/index.cjs +0 -12
  157. package/dist/set/index.d.ts +0 -5
  158. package/dist/set/index.js +0 -12
  159. package/dist/string/index.cjs +0 -14
  160. package/dist/string/index.d.ts +0 -6
  161. package/dist/string/index.js +0 -14
  162. package/dist/value/index.cjs +0 -4
  163. package/dist/value/index.d.ts +0 -1
  164. package/dist/value/index.js +0 -4
  165. package/eslint.config.js +0 -19
  166. package/src/array/chunk.ts +0 -6
  167. package/src/array/index.ts +0 -1
  168. package/src/date/index.ts +0 -1
  169. package/src/date/iso-date-time.ts +0 -356
  170. package/src/duration/add-durations.ts +0 -16
  171. package/src/duration/index.ts +0 -3
  172. package/src/duration/is-duration.ts +0 -5
  173. package/src/duration/to-number.ts +0 -18
  174. package/src/format/formatter.ts +0 -37
  175. package/src/format/index.ts +0 -3
  176. package/src/format/stringify.ts +0 -87
  177. package/src/format/template.ts +0 -48
  178. package/src/index.ts +0 -1
  179. package/src/object/get.ts +0 -9
  180. package/src/object/index.ts +0 -5
  181. package/src/object/is-object.ts +0 -2
  182. package/src/object/omit.ts +0 -21
  183. package/src/object/pick.ts +0 -10
  184. package/src/object/set.ts +0 -15
  185. package/src/path/file-url-to-path.ts +0 -12
  186. package/src/path/index.ts +0 -2
  187. package/src/path/normalize.ts +0 -72
  188. package/src/set/difference.ts +0 -9
  189. package/src/set/index.ts +0 -5
  190. package/src/set/intersection.ts +0 -12
  191. package/src/set/is-superset.ts +0 -12
  192. package/src/set/symmetric-difference.ts +0 -12
  193. package/src/set/union.ts +0 -8
  194. package/src/string/capitalize.ts +0 -2
  195. package/src/string/index.ts +0 -6
  196. package/src/string/normalize.ts +0 -7
  197. package/src/string/pluralize/index.ts +0 -7
  198. package/src/string/pluralize/pluralize.ts +0 -296
  199. package/src/string/pluralize/rules/index.ts +0 -4
  200. package/src/string/pluralize/rules/irregular.ts +0 -59
  201. package/src/string/pluralize/rules/pluralization.ts +0 -40
  202. package/src/string/pluralize/rules/singularization.ts +0 -46
  203. package/src/string/pluralize/rules/uncountable.ts +0 -107
  204. package/src/string/pluralize/types.ts +0 -4
  205. package/src/string/slugify/index.ts +0 -3
  206. package/src/string/strip-html-tags.ts +0 -4
  207. package/src/string/to-int.ts +0 -20
  208. package/src/string/to-sentence-case.ts +0 -6
  209. package/src/string/trim.ts +0 -11
  210. package/src/string/truncate.ts +0 -44
  211. package/src/value/index.ts +0 -1
  212. package/src/value/is-empty.ts +0 -31
  213. package/tsconfig.json +0 -18
  214. package/tsconfig.lib.json +0 -37
  215. package/tsconfig.node.json +0 -25
  216. package/vite.config.ts +0 -76
@@ -2,209 +2,162 @@ import { IRREGULAR_WORDS } from "./rules/irregular.js";
2
2
  import { PLURALIZATION_RULES } from "./rules/pluralization.js";
3
3
  import { SINGULARIZATION_RULES } from "./rules/singularization.js";
4
4
  import { UNCOUNTABLE_WORDS } from "./rules/uncountable.js";
5
- const TagIndexRegExp = /\$(\d{1,2})/g;
6
- class Pluralize {
7
- // Rule storage - pluralize and singularize need to be run sequentially,
8
- // while other rules can be optimized using an object for instant lookups.
9
- pluralRules = [];
10
- singularRules = [];
11
- uncountables = {};
12
- irregularPlurals = {};
13
- irregularSingles = {};
14
- constructor() {
15
- for (let index = 0; index < IRREGULAR_WORDS.length; index += 1) {
16
- this.addIrregularRule(
17
- IRREGULAR_WORDS[index][0],
18
- IRREGULAR_WORDS[index][1]
19
- );
20
- }
21
- for (let index = 0; index < PLURALIZATION_RULES.length; index += 1) {
22
- this.addPluralRule(
23
- PLURALIZATION_RULES[index][0],
24
- PLURALIZATION_RULES[index][1]
25
- );
26
- }
27
- for (let index = 0; index < SINGULARIZATION_RULES.length; index += 1) {
28
- this.addSingularRule(
29
- SINGULARIZATION_RULES[index][0],
30
- SINGULARIZATION_RULES[index][1]
31
- );
32
- }
33
- for (let index = 0; index < UNCOUNTABLE_WORDS.length; index += 1) {
34
- this.addUncountableRule(UNCOUNTABLE_WORDS[index]);
35
- }
36
- }
37
- /**
38
- * Add a pluralization rule to the collection.
39
- */
40
- addPluralRule(rule, replacement) {
41
- this.pluralRules.push([this.sanitizeRule(rule), replacement]);
42
- }
43
- /**
44
- * Add a singularization rule to the collection.
45
- */
46
- addSingularRule(rule, replacement) {
47
- this.singularRules.push([this.sanitizeRule(rule), replacement]);
48
- }
49
- /**
50
- * Add an uncountable word rule.
51
- */
52
- addUncountableRule(word) {
53
- if (typeof word === "string") {
54
- this.uncountables[word.toLowerCase()] = true;
55
- return;
56
- }
57
- this.addPluralRule(word, "$0");
58
- this.addSingularRule(word, "$0");
59
- }
60
- /**
61
- * Add an irregular word definition.
62
- *
63
- * @param {string} single
64
- * @param {string} plural
65
- */
66
- addIrregularRule(single, plural) {
67
- plural = plural.toLowerCase();
68
- single = single.toLowerCase();
69
- this.irregularSingles[single] = plural;
70
- this.irregularPlurals[plural] = single;
71
- }
72
- /**
73
- * Sanitize a pluralization rule to a usable regular expression.
74
- */
75
- sanitizeRule(rule) {
76
- if (typeof rule === "string") {
77
- return new RegExp(`^${rule}$`, "i");
78
- }
79
- return rule;
80
- }
81
- /**
82
- * Pass in a word token to produce a function that can replicate the case on
83
- * another word.
84
- */
85
- restoreCase(word, token) {
86
- if (word === token) return token;
87
- if (word === word.toLowerCase()) return token.toLowerCase();
88
- if (word === word.toUpperCase()) return token.toUpperCase();
89
- if (word[0] === word[0].toUpperCase()) {
90
- return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
91
- }
92
- return token.toLowerCase();
93
- }
94
- /**
95
- * Interpolate a regexp string.
96
- *
97
- * @param {string} str
98
- * @param {Array} args
99
- * @return {string}
100
- */
101
- interpolate(str, args) {
102
- return str.replace(TagIndexRegExp, (match, index) => {
103
- return args[index] || "";
104
- });
105
- }
106
- /**
107
- * Replace a word using a rule.
108
- */
109
- replace(word, rule) {
110
- return word.replace(rule[0], (match, index, ...args) => {
111
- const result = this.interpolate(rule[1], args);
112
- if (match === "") {
113
- return this.restoreCase(word[index - 1], result);
114
- }
115
- return this.restoreCase(match, result);
116
- });
117
- }
118
- /**
119
- * Sanitize a word by passing in the word and sanitization rules.
120
- */
121
- sanitizeWord(token, word, rules) {
122
- if (!token.length || this.uncountables[token]) {
123
- return word;
124
- }
125
- let len = rules.length;
126
- while (len--) {
127
- const rule = rules[len];
128
- if (typeof rule[0] === "string" || rule[0].test(word))
129
- return this.replace(word, rule);
130
- }
131
- return word;
132
- }
133
- /**
134
- * Replace a word with the updated word.
135
- */
136
- old_replaceWord(replaceMap, keepMap, rules) {
137
- return (word) => {
138
- const token = word.toLowerCase();
139
- if (keepMap[token]) {
140
- return this.restoreCase(word, token);
141
- }
142
- if (replaceMap[token]) {
143
- return this.restoreCase(word, replaceMap[token]);
144
- }
145
- return this.sanitizeWord(token, word, rules);
146
- };
147
- }
148
- /**
149
- * Replace a word with the updated word.
150
- */
151
- replaceWord(word, direction) {
152
- const replaceMap = direction === "SingularToPlural" ? this.irregularSingles : this.irregularPlurals;
153
- const keepMap = direction === "SingularToPlural" ? this.irregularPlurals : this.irregularSingles;
154
- const rules = direction === "SingularToPlural" ? this.pluralRules : this.singularRules;
155
- const token = word.toLowerCase();
156
- if (keepMap[token]) {
157
- return this.restoreCase(word, token);
158
- }
159
- if (replaceMap[token]) {
160
- return this.restoreCase(word, replaceMap[token]);
161
- }
162
- return this.sanitizeWord(token, word, rules);
163
- }
164
- /**
165
- * Check if a word is part of the map.
166
- */
167
- checkWord(word, reason) {
168
- const replaceMap = reason === "Plurality" ? this.irregularSingles : this.irregularPlurals;
169
- const keepMap = reason === "Plurality" ? this.irregularPlurals : this.irregularSingles;
170
- const rules = reason === "Singularity" ? this.pluralRules : this.singularRules;
171
- const token = word.toLowerCase();
172
- if (keepMap[token]) return true;
173
- if (replaceMap[token]) return false;
174
- return this.sanitizeWord(token, token, rules) === token;
175
- }
176
- /**
177
- * Pluralize or singularize a word based on the passed in count.
178
- */
179
- pluralize(word, count, inclusive) {
180
- const pluralized = count === 1 ? this.singular(word) : this.plural(word);
181
- return (inclusive ? `${count} ` : "") + pluralized;
182
- }
183
- /**
184
- * Pluralize a word.
185
- */
186
- plural(singularWord) {
187
- return this.replaceWord(singularWord, "SingularToPlural");
188
- }
189
- /**
190
- * Check if a word is plural.
191
- */
192
- isPlural(word) {
193
- this.checkWord(word, "Plurality");
194
- }
195
- /**
196
- * Singularize a word.
197
- */
198
- singular(pluralWord) {
199
- return this.replaceWord(pluralWord, "PluralToSingular");
200
- }
201
- /**
202
- * Check if a word is singular.
203
- */
204
- isSingular(word) {
205
- this.checkWord(word, "Singularity");
206
- }
207
- }
208
- export {
209
- Pluralize
5
+ //#region src/string/pluralize/pluralize.ts
6
+ var TagIndexRegExp = /\$(\d{1,2})/g;
7
+ var Pluralize = class {
8
+ pluralRules = [];
9
+ singularRules = [];
10
+ uncountables = {};
11
+ irregularPlurals = {};
12
+ irregularSingles = {};
13
+ constructor() {
14
+ for (let index = 0; index < IRREGULAR_WORDS.length; index += 1) this.addIrregularRule(IRREGULAR_WORDS[index][0], IRREGULAR_WORDS[index][1]);
15
+ for (let index = 0; index < PLURALIZATION_RULES.length; index += 1) this.addPluralRule(PLURALIZATION_RULES[index][0], PLURALIZATION_RULES[index][1]);
16
+ for (let index = 0; index < SINGULARIZATION_RULES.length; index += 1) this.addSingularRule(SINGULARIZATION_RULES[index][0], SINGULARIZATION_RULES[index][1]);
17
+ for (let index = 0; index < UNCOUNTABLE_WORDS.length; index += 1) this.addUncountableRule(UNCOUNTABLE_WORDS[index]);
18
+ }
19
+ /**
20
+ * Add a pluralization rule to the collection.
21
+ */
22
+ addPluralRule(rule, replacement) {
23
+ this.pluralRules.push([this.sanitizeRule(rule), replacement]);
24
+ }
25
+ /**
26
+ * Add a singularization rule to the collection.
27
+ */
28
+ addSingularRule(rule, replacement) {
29
+ this.singularRules.push([this.sanitizeRule(rule), replacement]);
30
+ }
31
+ /**
32
+ * Add an uncountable word rule.
33
+ */
34
+ addUncountableRule(word) {
35
+ if (typeof word === "string") {
36
+ this.uncountables[word.toLowerCase()] = true;
37
+ return;
38
+ }
39
+ this.addPluralRule(word, "$0");
40
+ this.addSingularRule(word, "$0");
41
+ }
42
+ /**
43
+ * Add an irregular word definition.
44
+ *
45
+ * @param {string} single
46
+ * @param {string} plural
47
+ */
48
+ addIrregularRule(single, plural) {
49
+ plural = plural.toLowerCase();
50
+ single = single.toLowerCase();
51
+ this.irregularSingles[single] = plural;
52
+ this.irregularPlurals[plural] = single;
53
+ }
54
+ /**
55
+ * Sanitize a pluralization rule to a usable regular expression.
56
+ */
57
+ sanitizeRule(rule) {
58
+ if (typeof rule === "string") return new RegExp(`^${rule}$`, "i");
59
+ return rule;
60
+ }
61
+ /**
62
+ * Pass in a word token to produce a function that can replicate the case on
63
+ * another word.
64
+ */
65
+ restoreCase(word, token) {
66
+ if (word === token) return token;
67
+ if (word === word.toUpperCase()) return token.toUpperCase();
68
+ if (word[0] === word[0].toUpperCase()) return token.charAt(0).toUpperCase() + token.substring(1).toLowerCase();
69
+ return token.toLowerCase();
70
+ }
71
+ /**
72
+ * Interpolate a regexp string.
73
+ *
74
+ * @param {string} str
75
+ * @param {Array} args
76
+ * @return {string}
77
+ */
78
+ interpolate(str, args) {
79
+ return str.replace(TagIndexRegExp, (match, index) => {
80
+ return args[index] || "";
81
+ });
82
+ }
83
+ /**
84
+ * Replace a word using a rule.
85
+ */
86
+ replace(word, rule) {
87
+ return word.replace(rule[0], (...args) => {
88
+ const [match, index] = args;
89
+ const result = this.interpolate(rule[1], args);
90
+ if (match === "") return this.restoreCase(word[index - 1], result);
91
+ return this.restoreCase(match, result);
92
+ });
93
+ }
94
+ /**
95
+ * Sanitize a word by passing in the word and sanitization rules.
96
+ */
97
+ sanitizeWord(token, word, rules) {
98
+ if (!token.length || this.uncountables[token]) return word;
99
+ let len = rules.length;
100
+ while (len--) {
101
+ const rule = rules[len];
102
+ if (typeof rule[0] === "string" || rule[0].test(word)) return this.replace(word, rule);
103
+ }
104
+ return word;
105
+ }
106
+ /**
107
+ * Replace a word with the updated word.
108
+ */
109
+ replaceWord(word, direction) {
110
+ const replaceMap = direction === "SingularToPlural" ? this.irregularSingles : this.irregularPlurals;
111
+ const keepMap = direction === "SingularToPlural" ? this.irregularPlurals : this.irregularSingles;
112
+ const rules = direction === "SingularToPlural" ? this.pluralRules : this.singularRules;
113
+ const token = word.toLowerCase();
114
+ if (keepMap[token]) return this.restoreCase(word, token);
115
+ if (replaceMap[token]) return this.restoreCase(word, replaceMap[token]);
116
+ return this.sanitizeWord(token, word, rules);
117
+ }
118
+ /**
119
+ * Check if a word is part of the map.
120
+ */
121
+ checkWord(word, reason) {
122
+ const replaceMap = reason === "Plurality" ? this.irregularSingles : this.irregularPlurals;
123
+ const keepMap = reason === "Plurality" ? this.irregularPlurals : this.irregularSingles;
124
+ const rules = reason === "Plurality" ? this.pluralRules : this.singularRules;
125
+ const token = word.toLowerCase();
126
+ if (keepMap[token]) return true;
127
+ if (replaceMap[token]) return false;
128
+ return this.sanitizeWord(token, token, rules) === token;
129
+ }
130
+ /**
131
+ * Pluralize or singularize a word based on the passed in count.
132
+ */
133
+ pluralize(word, count, inclusive = false) {
134
+ const pluralized = count === 1 ? this.singular(word) : this.plural(word);
135
+ return (inclusive ? `${count} ` : "") + pluralized;
136
+ }
137
+ /**
138
+ * Pluralize a word.
139
+ */
140
+ plural(singularWord) {
141
+ return this.replaceWord(singularWord, "SingularToPlural");
142
+ }
143
+ /**
144
+ * Check if a word is plural.
145
+ */
146
+ isPlural(word) {
147
+ return this.checkWord(word, "Plurality");
148
+ }
149
+ /**
150
+ * Singularize a word.
151
+ */
152
+ singular(pluralWord) {
153
+ return this.replaceWord(pluralWord, "PluralToSingular");
154
+ }
155
+ /**
156
+ * Check if a word is singular.
157
+ */
158
+ isSingular(word) {
159
+ return this.checkWord(word, "Singularity");
160
+ }
210
161
  };
162
+ //#endregion
163
+ export { Pluralize };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,9 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const string_pluralize_rules_irregular = require("./irregular.cjs");
4
- const string_pluralize_rules_pluralization = require("./pluralization.cjs");
5
- const string_pluralize_rules_singularization = require("./singularization.cjs");
6
- const string_pluralize_rules_uncountable = require("./uncountable.cjs");
7
- exports.IRREGULAR_WORDS = string_pluralize_rules_irregular.IRREGULAR_WORDS;
8
- exports.PLURALIZATION_RULES = string_pluralize_rules_pluralization.PLURALIZATION_RULES;
9
- exports.SINGULARIZATION_RULES = string_pluralize_rules_singularization.SINGULARIZATION_RULES;
10
- exports.UNCOUNTABLE_WORDS = string_pluralize_rules_uncountable.UNCOUNTABLE_WORDS;
2
+ const require_string_pluralize_rules_irregular = require("./irregular.cjs");
3
+ const require_string_pluralize_rules_pluralization = require("./pluralization.cjs");
4
+ const require_string_pluralize_rules_singularization = require("./singularization.cjs");
5
+ const require_string_pluralize_rules_uncountable = require("./uncountable.cjs");
6
+ exports.IRREGULAR_WORDS = require_string_pluralize_rules_irregular.IRREGULAR_WORDS;
7
+ exports.PLURALIZATION_RULES = require_string_pluralize_rules_pluralization.PLURALIZATION_RULES;
8
+ exports.SINGULARIZATION_RULES = require_string_pluralize_rules_singularization.SINGULARIZATION_RULES;
9
+ exports.UNCOUNTABLE_WORDS = require_string_pluralize_rules_uncountable.UNCOUNTABLE_WORDS;
@@ -2,9 +2,4 @@ import { IRREGULAR_WORDS } from "./irregular.js";
2
2
  import { PLURALIZATION_RULES } from "./pluralization.js";
3
3
  import { SINGULARIZATION_RULES } from "./singularization.js";
4
4
  import { UNCOUNTABLE_WORDS } from "./uncountable.js";
5
- export {
6
- IRREGULAR_WORDS,
7
- PLURALIZATION_RULES,
8
- SINGULARIZATION_RULES,
9
- UNCOUNTABLE_WORDS
10
- };
5
+ export { IRREGULAR_WORDS, PLURALIZATION_RULES, SINGULARIZATION_RULES, UNCOUNTABLE_WORDS };
@@ -1,62 +1,58 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const IRREGULAR_WORDS = [
4
- // Pronouns.
5
- ["I", "we"],
6
- ["me", "us"],
7
- ["he", "they"],
8
- ["she", "they"],
9
- ["them", "them"],
10
- ["myself", "ourselves"],
11
- ["yourself", "yourselves"],
12
- ["itself", "themselves"],
13
- ["herself", "themselves"],
14
- ["himself", "themselves"],
15
- ["themself", "themselves"],
16
- ["is", "are"],
17
- ["was", "were"],
18
- ["has", "have"],
19
- ["this", "these"],
20
- ["that", "those"],
21
- ["my", "our"],
22
- ["its", "their"],
23
- ["his", "their"],
24
- ["her", "their"],
25
- // Words ending in with a consonant and `o`.
26
- ["echo", "echoes"],
27
- ["dingo", "dingoes"],
28
- ["volcano", "volcanoes"],
29
- ["tornado", "tornadoes"],
30
- ["torpedo", "torpedoes"],
31
- // Ends with `us`.
32
- ["genus", "genera"],
33
- ["viscus", "viscera"],
34
- // Ends with `ma`.
35
- ["stigma", "stigmata"],
36
- ["stoma", "stomata"],
37
- ["dogma", "dogmata"],
38
- ["lemma", "lemmata"],
39
- ["schema", "schemata"],
40
- ["anathema", "anathemata"],
41
- // Other irregular rules.
42
- ["ox", "oxen"],
43
- ["axe", "axes"],
44
- ["die", "dice"],
45
- ["yes", "yeses"],
46
- ["foot", "feet"],
47
- ["eave", "eaves"],
48
- ["goose", "geese"],
49
- ["tooth", "teeth"],
50
- ["quiz", "quizzes"],
51
- ["human", "humans"],
52
- ["proof", "proofs"],
53
- ["carve", "carves"],
54
- ["valve", "valves"],
55
- ["looey", "looies"],
56
- ["thief", "thieves"],
57
- ["groove", "grooves"],
58
- ["pickaxe", "pickaxes"],
59
- ["passerby", "passersby"],
60
- ["canvas", "canvases"]
2
+ //#region src/string/pluralize/rules/irregular.ts
3
+ var IRREGULAR_WORDS = [
4
+ ["I", "we"],
5
+ ["me", "us"],
6
+ ["he", "they"],
7
+ ["she", "they"],
8
+ ["them", "them"],
9
+ ["myself", "ourselves"],
10
+ ["yourself", "yourselves"],
11
+ ["itself", "themselves"],
12
+ ["herself", "themselves"],
13
+ ["himself", "themselves"],
14
+ ["themself", "themselves"],
15
+ ["is", "are"],
16
+ ["was", "were"],
17
+ ["has", "have"],
18
+ ["this", "these"],
19
+ ["that", "those"],
20
+ ["my", "our"],
21
+ ["its", "their"],
22
+ ["his", "their"],
23
+ ["her", "their"],
24
+ ["echo", "echoes"],
25
+ ["dingo", "dingoes"],
26
+ ["volcano", "volcanoes"],
27
+ ["tornado", "tornadoes"],
28
+ ["torpedo", "torpedoes"],
29
+ ["genus", "genera"],
30
+ ["viscus", "viscera"],
31
+ ["stigma", "stigmata"],
32
+ ["stoma", "stomata"],
33
+ ["dogma", "dogmata"],
34
+ ["lemma", "lemmata"],
35
+ ["schema", "schemata"],
36
+ ["anathema", "anathemata"],
37
+ ["ox", "oxen"],
38
+ ["axe", "axes"],
39
+ ["die", "dice"],
40
+ ["yes", "yeses"],
41
+ ["foot", "feet"],
42
+ ["eave", "eaves"],
43
+ ["goose", "geese"],
44
+ ["tooth", "teeth"],
45
+ ["quiz", "quizzes"],
46
+ ["human", "humans"],
47
+ ["proof", "proofs"],
48
+ ["carve", "carves"],
49
+ ["valve", "valves"],
50
+ ["looey", "looies"],
51
+ ["thief", "thieves"],
52
+ ["groove", "grooves"],
53
+ ["pickaxe", "pickaxes"],
54
+ ["passerby", "passersby"],
55
+ ["canvas", "canvases"]
61
56
  ];
57
+ //#endregion
62
58
  exports.IRREGULAR_WORDS = IRREGULAR_WORDS;
@@ -1,62 +1,57 @@
1
- const IRREGULAR_WORDS = [
2
- // Pronouns.
3
- ["I", "we"],
4
- ["me", "us"],
5
- ["he", "they"],
6
- ["she", "they"],
7
- ["them", "them"],
8
- ["myself", "ourselves"],
9
- ["yourself", "yourselves"],
10
- ["itself", "themselves"],
11
- ["herself", "themselves"],
12
- ["himself", "themselves"],
13
- ["themself", "themselves"],
14
- ["is", "are"],
15
- ["was", "were"],
16
- ["has", "have"],
17
- ["this", "these"],
18
- ["that", "those"],
19
- ["my", "our"],
20
- ["its", "their"],
21
- ["his", "their"],
22
- ["her", "their"],
23
- // Words ending in with a consonant and `o`.
24
- ["echo", "echoes"],
25
- ["dingo", "dingoes"],
26
- ["volcano", "volcanoes"],
27
- ["tornado", "tornadoes"],
28
- ["torpedo", "torpedoes"],
29
- // Ends with `us`.
30
- ["genus", "genera"],
31
- ["viscus", "viscera"],
32
- // Ends with `ma`.
33
- ["stigma", "stigmata"],
34
- ["stoma", "stomata"],
35
- ["dogma", "dogmata"],
36
- ["lemma", "lemmata"],
37
- ["schema", "schemata"],
38
- ["anathema", "anathemata"],
39
- // Other irregular rules.
40
- ["ox", "oxen"],
41
- ["axe", "axes"],
42
- ["die", "dice"],
43
- ["yes", "yeses"],
44
- ["foot", "feet"],
45
- ["eave", "eaves"],
46
- ["goose", "geese"],
47
- ["tooth", "teeth"],
48
- ["quiz", "quizzes"],
49
- ["human", "humans"],
50
- ["proof", "proofs"],
51
- ["carve", "carves"],
52
- ["valve", "valves"],
53
- ["looey", "looies"],
54
- ["thief", "thieves"],
55
- ["groove", "grooves"],
56
- ["pickaxe", "pickaxes"],
57
- ["passerby", "passersby"],
58
- ["canvas", "canvases"]
1
+ //#region src/string/pluralize/rules/irregular.ts
2
+ var IRREGULAR_WORDS = [
3
+ ["I", "we"],
4
+ ["me", "us"],
5
+ ["he", "they"],
6
+ ["she", "they"],
7
+ ["them", "them"],
8
+ ["myself", "ourselves"],
9
+ ["yourself", "yourselves"],
10
+ ["itself", "themselves"],
11
+ ["herself", "themselves"],
12
+ ["himself", "themselves"],
13
+ ["themself", "themselves"],
14
+ ["is", "are"],
15
+ ["was", "were"],
16
+ ["has", "have"],
17
+ ["this", "these"],
18
+ ["that", "those"],
19
+ ["my", "our"],
20
+ ["its", "their"],
21
+ ["his", "their"],
22
+ ["her", "their"],
23
+ ["echo", "echoes"],
24
+ ["dingo", "dingoes"],
25
+ ["volcano", "volcanoes"],
26
+ ["tornado", "tornadoes"],
27
+ ["torpedo", "torpedoes"],
28
+ ["genus", "genera"],
29
+ ["viscus", "viscera"],
30
+ ["stigma", "stigmata"],
31
+ ["stoma", "stomata"],
32
+ ["dogma", "dogmata"],
33
+ ["lemma", "lemmata"],
34
+ ["schema", "schemata"],
35
+ ["anathema", "anathemata"],
36
+ ["ox", "oxen"],
37
+ ["axe", "axes"],
38
+ ["die", "dice"],
39
+ ["yes", "yeses"],
40
+ ["foot", "feet"],
41
+ ["eave", "eaves"],
42
+ ["goose", "geese"],
43
+ ["tooth", "teeth"],
44
+ ["quiz", "quizzes"],
45
+ ["human", "humans"],
46
+ ["proof", "proofs"],
47
+ ["carve", "carves"],
48
+ ["valve", "valves"],
49
+ ["looey", "looies"],
50
+ ["thief", "thieves"],
51
+ ["groove", "grooves"],
52
+ ["pickaxe", "pickaxes"],
53
+ ["passerby", "passersby"],
54
+ ["canvas", "canvases"]
59
55
  ];
60
- export {
61
- IRREGULAR_WORDS
62
- };
56
+ //#endregion
57
+ export { IRREGULAR_WORDS };