@bccampus/utils 0.2.3 → 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 (163) 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 -1
  42. package/dist/index.js +0 -1
  43. package/dist/object/get.cjs +5 -5
  44. package/dist/object/get.d.ts +1 -1
  45. package/dist/object/get.js +6 -7
  46. package/dist/object/get.test.d.ts +1 -0
  47. package/dist/object/is-object.cjs +5 -2
  48. package/dist/object/is-object.d.ts +1 -1
  49. package/dist/object/is-object.js +6 -4
  50. package/dist/object/is-object.test.d.ts +1 -0
  51. package/dist/object/omit.cjs +14 -16
  52. package/dist/object/omit.d.ts +1 -1
  53. package/dist/object/omit.js +15 -18
  54. package/dist/object/omit.test.d.ts +1 -0
  55. package/dist/object/pick.cjs +10 -9
  56. package/dist/object/pick.d.ts +1 -1
  57. package/dist/object/pick.js +9 -9
  58. package/dist/object/pick.test.d.ts +1 -0
  59. package/dist/object/set.cjs +13 -12
  60. package/dist/object/set.d.ts +1 -1
  61. package/dist/object/set.js +14 -14
  62. package/dist/object/set.test.d.ts +1 -0
  63. package/dist/path/file-url-to-path.cjs +10 -6
  64. package/dist/path/file-url-to-path.js +11 -8
  65. package/dist/path/file-url-to-path.test.d.ts +1 -0
  66. package/dist/path/normalize.cjs +41 -27
  67. package/dist/path/normalize.d.ts +8 -2
  68. package/dist/path/normalize.js +41 -28
  69. package/dist/path/normalize.test.d.ts +1 -0
  70. package/dist/set/difference.cjs +5 -6
  71. package/dist/set/difference.d.ts +1 -1
  72. package/dist/set/difference.js +6 -8
  73. package/dist/set/intersection.cjs +6 -9
  74. package/dist/set/intersection.d.ts +1 -1
  75. package/dist/set/intersection.js +7 -11
  76. package/dist/set/is-superset.cjs +5 -8
  77. package/dist/set/is-superset.d.ts +1 -1
  78. package/dist/set/is-superset.js +6 -10
  79. package/dist/set/set.test.d.ts +1 -0
  80. package/dist/set/symmetric-difference.cjs +6 -10
  81. package/dist/set/symmetric-difference.d.ts +1 -1
  82. package/dist/set/symmetric-difference.js +7 -12
  83. package/dist/set/union.cjs +5 -6
  84. package/dist/set/union.d.ts +1 -1
  85. package/dist/set/union.js +6 -8
  86. package/dist/string/capitalize.cjs +5 -2
  87. package/dist/string/capitalize.d.ts +1 -1
  88. package/dist/string/capitalize.js +6 -4
  89. package/dist/string/capitalize.test.d.ts +1 -0
  90. package/dist/string/normalize.cjs +7 -2
  91. package/dist/string/normalize.js +8 -4
  92. package/dist/string/normalize.test.d.ts +1 -0
  93. package/dist/string/pluralize/index.cjs +5 -4
  94. package/dist/string/pluralize/index.js +4 -5
  95. package/dist/string/pluralize/pluralize.cjs +162 -208
  96. package/dist/string/pluralize/pluralize.d.ts +4 -8
  97. package/dist/string/pluralize/pluralize.js +158 -205
  98. package/dist/string/pluralize/pluralize.test.d.ts +1 -0
  99. package/dist/string/pluralize/rules/index.cjs +8 -9
  100. package/dist/string/pluralize/rules/index.js +1 -6
  101. package/dist/string/pluralize/rules/irregular.cjs +55 -59
  102. package/dist/string/pluralize/rules/irregular.js +56 -61
  103. package/dist/string/pluralize/rules/pluralization.cjs +28 -36
  104. package/dist/string/pluralize/rules/pluralization.js +29 -38
  105. package/dist/string/pluralize/rules/singularization.cjs +27 -44
  106. package/dist/string/pluralize/rules/singularization.js +28 -46
  107. package/dist/string/pluralize/rules/uncountable.cjs +104 -110
  108. package/dist/string/pluralize/rules/uncountable.js +105 -112
  109. package/dist/string/pluralize/types.cjs +0 -1
  110. package/dist/string/pluralize/types.js +0 -1
  111. package/dist/string/slugify/index.cjs +2129 -2246
  112. package/dist/string/slugify/index.js +2130 -2248
  113. package/dist/string/slugify/slugify.test.d.ts +1 -0
  114. package/dist/string/strip-html-tags.cjs +4 -3
  115. package/dist/string/strip-html-tags.js +5 -5
  116. package/dist/string/strip-html-tags.test.d.ts +1 -0
  117. package/dist/string/to-int.cjs +14 -6
  118. package/dist/string/to-int.js +15 -8
  119. package/dist/string/to-int.test.d.ts +1 -0
  120. package/dist/string/to-sentence-case.cjs +6 -6
  121. package/dist/string/to-sentence-case.d.ts +1 -1
  122. package/dist/string/to-sentence-case.js +7 -8
  123. package/dist/string/to-sentence-case.test.d.ts +1 -0
  124. package/dist/string/trim.cjs +8 -7
  125. package/dist/string/trim.js +9 -9
  126. package/dist/string/trim.test.d.ts +1 -0
  127. package/dist/string/truncate.cjs +16 -15
  128. package/dist/string/truncate.js +17 -17
  129. package/dist/string/truncate.test.d.ts +1 -0
  130. package/dist/value/is-empty.cjs +30 -12
  131. package/dist/value/is-empty.d.ts +1 -1
  132. package/dist/value/is-empty.js +31 -14
  133. package/dist/value/value.test.d.ts +1 -0
  134. package/package.json +180 -69
  135. package/dist/array/index.cjs +0 -4
  136. package/dist/array/index.d.ts +0 -2
  137. package/dist/array/index.js +0 -4
  138. package/dist/date/index.cjs +0 -8
  139. package/dist/date/index.d.ts +0 -3
  140. package/dist/date/index.js +0 -8
  141. package/dist/date/iso-date-time.cjs +0 -256
  142. package/dist/date/iso-date-time.js +0 -256
  143. package/dist/duration/index.cjs +0 -8
  144. package/dist/duration/index.d.ts +0 -4
  145. package/dist/duration/index.js +0 -8
  146. package/dist/format/index.cjs +0 -13
  147. package/dist/format/index.d.ts +0 -5
  148. package/dist/format/index.js +0 -13
  149. package/dist/object/index.cjs +0 -12
  150. package/dist/object/index.d.ts +0 -6
  151. package/dist/object/index.js +0 -12
  152. package/dist/path/index.cjs +0 -6
  153. package/dist/path/index.d.ts +0 -4
  154. package/dist/path/index.js +0 -6
  155. package/dist/set/index.cjs +0 -12
  156. package/dist/set/index.d.ts +0 -6
  157. package/dist/set/index.js +0 -12
  158. package/dist/string/index.cjs +0 -14
  159. package/dist/string/index.d.ts +0 -8
  160. package/dist/string/index.js +0 -14
  161. package/dist/value/index.cjs +0 -4
  162. package/dist/value/index.d.ts +0 -2
  163. package/dist/value/index.js +0 -4
@@ -1,14 +1,10 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/set/symmetric-difference.ts
3
3
  function symmetricDifference(setA, setB) {
4
- const _difference = new Set(setA);
5
- for (const elem of setB) {
6
- if (_difference.has(elem)) {
7
- _difference.delete(elem);
8
- } else {
9
- _difference.add(elem);
10
- }
11
- }
12
- return _difference;
4
+ const _difference = new Set(setA);
5
+ for (const elem of setB) if (_difference.has(elem)) _difference.delete(elem);
6
+ else _difference.add(elem);
7
+ return _difference;
13
8
  }
9
+ //#endregion
14
10
  exports.symmetricDifference = symmetricDifference;
@@ -1 +1 @@
1
- export declare function symmetricDifference(setA: Iterable<any>, setB: Iterable<any>): Set<any>;
1
+ export declare function symmetricDifference(setA: Iterable<unknown>, setB: Iterable<unknown>): Set<unknown>;
@@ -1,14 +1,9 @@
1
+ //#region src/set/symmetric-difference.ts
1
2
  function symmetricDifference(setA, setB) {
2
- const _difference = new Set(setA);
3
- for (const elem of setB) {
4
- if (_difference.has(elem)) {
5
- _difference.delete(elem);
6
- } else {
7
- _difference.add(elem);
8
- }
9
- }
10
- return _difference;
3
+ const _difference = new Set(setA);
4
+ for (const elem of setB) if (_difference.has(elem)) _difference.delete(elem);
5
+ else _difference.add(elem);
6
+ return _difference;
11
7
  }
12
- export {
13
- symmetricDifference
14
- };
8
+ //#endregion
9
+ export { symmetricDifference };
@@ -1,10 +1,9 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/set/union.ts
3
3
  function union(setA, setB) {
4
- const _union = new Set(setA);
5
- for (const elem of setB) {
6
- _union.add(elem);
7
- }
8
- return _union;
4
+ const _union = new Set(setA);
5
+ for (const elem of setB) _union.add(elem);
6
+ return _union;
9
7
  }
8
+ //#endregion
10
9
  exports.union = union;
@@ -1 +1 @@
1
- export declare function union(setA: Iterable<any>, setB: Iterable<any>): Set<any>;
1
+ export declare function union(setA: Iterable<unknown>, setB: Iterable<unknown>): Set<unknown>;
package/dist/set/union.js CHANGED
@@ -1,10 +1,8 @@
1
+ //#region src/set/union.ts
1
2
  function union(setA, setB) {
2
- const _union = new Set(setA);
3
- for (const elem of setB) {
4
- _union.add(elem);
5
- }
6
- return _union;
3
+ const _union = new Set(setA);
4
+ for (const elem of setB) _union.add(elem);
5
+ return _union;
7
6
  }
8
- export {
9
- union
10
- };
7
+ //#endregion
8
+ export { union };
@@ -1,4 +1,7 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const capitalize = (s) => s[0].toUpperCase() + s.slice(1);
2
+ //#region src/string/capitalize.ts
3
+ function capitalize(s) {
4
+ return s[0].toUpperCase() + s.slice(1);
5
+ }
6
+ //#endregion
4
7
  exports.capitalize = capitalize;
@@ -1 +1 @@
1
- export declare const capitalize: <T extends string>(s: T) => Capitalize<typeof s>;
1
+ export declare function capitalize<T extends string>(s: T): string;
@@ -1,4 +1,6 @@
1
- const capitalize = (s) => s[0].toUpperCase() + s.slice(1);
2
- export {
3
- capitalize
4
- };
1
+ //#region src/string/capitalize.ts
2
+ function capitalize(s) {
3
+ return s[0].toUpperCase() + s.slice(1);
4
+ }
5
+ //#endregion
6
+ export { capitalize };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,11 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/string/normalize.ts
3
+ /**
4
+ * Trims white spaces and
5
+ * replaces multiple white space characters with a single space
6
+ */
3
7
  function normalize(text) {
4
- return text.trim().replace(/\s+/g, " ");
8
+ return text.trim().replace(/\s+/g, " ");
5
9
  }
10
+ //#endregion
6
11
  exports.normalize = normalize;
@@ -1,6 +1,10 @@
1
+ //#region src/string/normalize.ts
2
+ /**
3
+ * Trims white spaces and
4
+ * replaces multiple white space characters with a single space
5
+ */
1
6
  function normalize(text) {
2
- return text.trim().replace(/\s+/g, " ");
7
+ return text.trim().replace(/\s+/g, " ");
3
8
  }
4
- export {
5
- normalize
6
- };
9
+ //#endregion
10
+ export { normalize };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const string_pluralize_pluralize = require("./pluralize.cjs");
4
- const pluralize = new string_pluralize_pluralize.Pluralize();
5
- exports.Pluralize = string_pluralize_pluralize.Pluralize;
2
+ const require_string_pluralize_pluralize = require("./pluralize.cjs");
3
+ //#region src/string/pluralize/index.ts
4
+ var pluralize = new require_string_pluralize_pluralize.Pluralize();
5
+ //#endregion
6
+ exports.Pluralize = require_string_pluralize_pluralize.Pluralize;
6
7
  exports.pluralize = pluralize;
@@ -1,6 +1,5 @@
1
1
  import { Pluralize } from "./pluralize.js";
2
- const pluralize = new Pluralize();
3
- export {
4
- Pluralize,
5
- pluralize
6
- };
2
+ //#region src/string/pluralize/index.ts
3
+ var pluralize = new Pluralize();
4
+ //#endregion
5
+ export { Pluralize, pluralize };
@@ -1,210 +1,164 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const string_pluralize_rules_irregular = require("./rules/irregular.cjs");
4
- const string_pluralize_rules_pluralization = require("./rules/pluralization.cjs");
5
- const string_pluralize_rules_singularization = require("./rules/singularization.cjs");
6
- const string_pluralize_rules_uncountable = require("./rules/uncountable.cjs");
7
- const TagIndexRegExp = /\$(\d{1,2})/g;
8
- class Pluralize {
9
- // Rule storage - pluralize and singularize need to be run sequentially,
10
- // while other rules can be optimized using an object for instant lookups.
11
- pluralRules = [];
12
- singularRules = [];
13
- uncountables = {};
14
- irregularPlurals = {};
15
- irregularSingles = {};
16
- constructor() {
17
- for (let index = 0; index < string_pluralize_rules_irregular.IRREGULAR_WORDS.length; index += 1) {
18
- this.addIrregularRule(
19
- string_pluralize_rules_irregular.IRREGULAR_WORDS[index][0],
20
- string_pluralize_rules_irregular.IRREGULAR_WORDS[index][1]
21
- );
22
- }
23
- for (let index = 0; index < string_pluralize_rules_pluralization.PLURALIZATION_RULES.length; index += 1) {
24
- this.addPluralRule(
25
- string_pluralize_rules_pluralization.PLURALIZATION_RULES[index][0],
26
- string_pluralize_rules_pluralization.PLURALIZATION_RULES[index][1]
27
- );
28
- }
29
- for (let index = 0; index < string_pluralize_rules_singularization.SINGULARIZATION_RULES.length; index += 1) {
30
- this.addSingularRule(
31
- string_pluralize_rules_singularization.SINGULARIZATION_RULES[index][0],
32
- string_pluralize_rules_singularization.SINGULARIZATION_RULES[index][1]
33
- );
34
- }
35
- for (let index = 0; index < string_pluralize_rules_uncountable.UNCOUNTABLE_WORDS.length; index += 1) {
36
- this.addUncountableRule(string_pluralize_rules_uncountable.UNCOUNTABLE_WORDS[index]);
37
- }
38
- }
39
- /**
40
- * Add a pluralization rule to the collection.
41
- */
42
- addPluralRule(rule, replacement) {
43
- this.pluralRules.push([this.sanitizeRule(rule), replacement]);
44
- }
45
- /**
46
- * Add a singularization rule to the collection.
47
- */
48
- addSingularRule(rule, replacement) {
49
- this.singularRules.push([this.sanitizeRule(rule), replacement]);
50
- }
51
- /**
52
- * Add an uncountable word rule.
53
- */
54
- addUncountableRule(word) {
55
- if (typeof word === "string") {
56
- this.uncountables[word.toLowerCase()] = true;
57
- return;
58
- }
59
- this.addPluralRule(word, "$0");
60
- this.addSingularRule(word, "$0");
61
- }
62
- /**
63
- * Add an irregular word definition.
64
- *
65
- * @param {string} single
66
- * @param {string} plural
67
- */
68
- addIrregularRule(single, plural) {
69
- plural = plural.toLowerCase();
70
- single = single.toLowerCase();
71
- this.irregularSingles[single] = plural;
72
- this.irregularPlurals[plural] = single;
73
- }
74
- /**
75
- * Sanitize a pluralization rule to a usable regular expression.
76
- */
77
- sanitizeRule(rule) {
78
- if (typeof rule === "string") {
79
- return new RegExp(`^${rule}$`, "i");
80
- }
81
- return rule;
82
- }
83
- /**
84
- * Pass in a word token to produce a function that can replicate the case on
85
- * another word.
86
- */
87
- restoreCase(word, token) {
88
- if (word === token) return token;
89
- if (word === word.toLowerCase()) return token.toLowerCase();
90
- if (word === word.toUpperCase()) return token.toUpperCase();
91
- if (word[0] === word[0].toUpperCase()) {
92
- return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
93
- }
94
- return token.toLowerCase();
95
- }
96
- /**
97
- * Interpolate a regexp string.
98
- *
99
- * @param {string} str
100
- * @param {Array} args
101
- * @return {string}
102
- */
103
- interpolate(str, args) {
104
- return str.replace(TagIndexRegExp, (match, index) => {
105
- return args[index] || "";
106
- });
107
- }
108
- /**
109
- * Replace a word using a rule.
110
- */
111
- replace(word, rule) {
112
- return word.replace(rule[0], (match, index, ...args) => {
113
- const result = this.interpolate(rule[1], args);
114
- if (match === "") {
115
- return this.restoreCase(word[index - 1], result);
116
- }
117
- return this.restoreCase(match, result);
118
- });
119
- }
120
- /**
121
- * Sanitize a word by passing in the word and sanitization rules.
122
- */
123
- sanitizeWord(token, word, rules) {
124
- if (!token.length || this.uncountables[token]) {
125
- return word;
126
- }
127
- let len = rules.length;
128
- while (len--) {
129
- const rule = rules[len];
130
- if (typeof rule[0] === "string" || rule[0].test(word))
131
- return this.replace(word, rule);
132
- }
133
- return word;
134
- }
135
- /**
136
- * Replace a word with the updated word.
137
- */
138
- old_replaceWord(replaceMap, keepMap, rules) {
139
- return (word) => {
140
- const token = word.toLowerCase();
141
- if (keepMap[token]) {
142
- return this.restoreCase(word, token);
143
- }
144
- if (replaceMap[token]) {
145
- return this.restoreCase(word, replaceMap[token]);
146
- }
147
- return this.sanitizeWord(token, word, rules);
148
- };
149
- }
150
- /**
151
- * Replace a word with the updated word.
152
- */
153
- replaceWord(word, direction) {
154
- const replaceMap = direction === "SingularToPlural" ? this.irregularSingles : this.irregularPlurals;
155
- const keepMap = direction === "SingularToPlural" ? this.irregularPlurals : this.irregularSingles;
156
- const rules = direction === "SingularToPlural" ? this.pluralRules : this.singularRules;
157
- const token = word.toLowerCase();
158
- if (keepMap[token]) {
159
- return this.restoreCase(word, token);
160
- }
161
- if (replaceMap[token]) {
162
- return this.restoreCase(word, replaceMap[token]);
163
- }
164
- return this.sanitizeWord(token, word, rules);
165
- }
166
- /**
167
- * Check if a word is part of the map.
168
- */
169
- checkWord(word, reason) {
170
- const replaceMap = reason === "Plurality" ? this.irregularSingles : this.irregularPlurals;
171
- const keepMap = reason === "Plurality" ? this.irregularPlurals : this.irregularSingles;
172
- const rules = reason === "Singularity" ? this.pluralRules : this.singularRules;
173
- const token = word.toLowerCase();
174
- if (keepMap[token]) return true;
175
- if (replaceMap[token]) return false;
176
- return this.sanitizeWord(token, token, rules) === token;
177
- }
178
- /**
179
- * Pluralize or singularize a word based on the passed in count.
180
- */
181
- pluralize(word, count, inclusive) {
182
- const pluralized = count === 1 ? this.singular(word) : this.plural(word);
183
- return (inclusive ? `${count} ` : "") + pluralized;
184
- }
185
- /**
186
- * Pluralize a word.
187
- */
188
- plural(singularWord) {
189
- return this.replaceWord(singularWord, "SingularToPlural");
190
- }
191
- /**
192
- * Check if a word is plural.
193
- */
194
- isPlural(word) {
195
- this.checkWord(word, "Plurality");
196
- }
197
- /**
198
- * Singularize a word.
199
- */
200
- singular(pluralWord) {
201
- return this.replaceWord(pluralWord, "PluralToSingular");
202
- }
203
- /**
204
- * Check if a word is singular.
205
- */
206
- isSingular(word) {
207
- this.checkWord(word, "Singularity");
208
- }
209
- }
2
+ const require_string_pluralize_rules_irregular = require("./rules/irregular.cjs");
3
+ const require_string_pluralize_rules_pluralization = require("./rules/pluralization.cjs");
4
+ const require_string_pluralize_rules_singularization = require("./rules/singularization.cjs");
5
+ const require_string_pluralize_rules_uncountable = require("./rules/uncountable.cjs");
6
+ //#region src/string/pluralize/pluralize.ts
7
+ var TagIndexRegExp = /\$(\d{1,2})/g;
8
+ var Pluralize = class {
9
+ pluralRules = [];
10
+ singularRules = [];
11
+ uncountables = {};
12
+ irregularPlurals = {};
13
+ irregularSingles = {};
14
+ constructor() {
15
+ for (let index = 0; index < require_string_pluralize_rules_irregular.IRREGULAR_WORDS.length; index += 1) this.addIrregularRule(require_string_pluralize_rules_irregular.IRREGULAR_WORDS[index][0], require_string_pluralize_rules_irregular.IRREGULAR_WORDS[index][1]);
16
+ for (let index = 0; index < require_string_pluralize_rules_pluralization.PLURALIZATION_RULES.length; index += 1) this.addPluralRule(require_string_pluralize_rules_pluralization.PLURALIZATION_RULES[index][0], require_string_pluralize_rules_pluralization.PLURALIZATION_RULES[index][1]);
17
+ for (let index = 0; index < require_string_pluralize_rules_singularization.SINGULARIZATION_RULES.length; index += 1) this.addSingularRule(require_string_pluralize_rules_singularization.SINGULARIZATION_RULES[index][0], require_string_pluralize_rules_singularization.SINGULARIZATION_RULES[index][1]);
18
+ for (let index = 0; index < require_string_pluralize_rules_uncountable.UNCOUNTABLE_WORDS.length; index += 1) this.addUncountableRule(require_string_pluralize_rules_uncountable.UNCOUNTABLE_WORDS[index]);
19
+ }
20
+ /**
21
+ * Add a pluralization rule to the collection.
22
+ */
23
+ addPluralRule(rule, replacement) {
24
+ this.pluralRules.push([this.sanitizeRule(rule), replacement]);
25
+ }
26
+ /**
27
+ * Add a singularization rule to the collection.
28
+ */
29
+ addSingularRule(rule, replacement) {
30
+ this.singularRules.push([this.sanitizeRule(rule), replacement]);
31
+ }
32
+ /**
33
+ * Add an uncountable word rule.
34
+ */
35
+ addUncountableRule(word) {
36
+ if (typeof word === "string") {
37
+ this.uncountables[word.toLowerCase()] = true;
38
+ return;
39
+ }
40
+ this.addPluralRule(word, "$0");
41
+ this.addSingularRule(word, "$0");
42
+ }
43
+ /**
44
+ * Add an irregular word definition.
45
+ *
46
+ * @param {string} single
47
+ * @param {string} plural
48
+ */
49
+ addIrregularRule(single, plural) {
50
+ plural = plural.toLowerCase();
51
+ single = single.toLowerCase();
52
+ this.irregularSingles[single] = plural;
53
+ this.irregularPlurals[plural] = single;
54
+ }
55
+ /**
56
+ * Sanitize a pluralization rule to a usable regular expression.
57
+ */
58
+ sanitizeRule(rule) {
59
+ if (typeof rule === "string") return new RegExp(`^${rule}$`, "i");
60
+ return rule;
61
+ }
62
+ /**
63
+ * Pass in a word token to produce a function that can replicate the case on
64
+ * another word.
65
+ */
66
+ restoreCase(word, token) {
67
+ if (word === token) return token;
68
+ if (word === word.toUpperCase()) return token.toUpperCase();
69
+ if (word[0] === word[0].toUpperCase()) return token.charAt(0).toUpperCase() + token.substring(1).toLowerCase();
70
+ return token.toLowerCase();
71
+ }
72
+ /**
73
+ * Interpolate a regexp string.
74
+ *
75
+ * @param {string} str
76
+ * @param {Array} args
77
+ * @return {string}
78
+ */
79
+ interpolate(str, args) {
80
+ return str.replace(TagIndexRegExp, (match, index) => {
81
+ return args[index] || "";
82
+ });
83
+ }
84
+ /**
85
+ * Replace a word using a rule.
86
+ */
87
+ replace(word, rule) {
88
+ return word.replace(rule[0], (...args) => {
89
+ const [match, index] = args;
90
+ const result = this.interpolate(rule[1], args);
91
+ if (match === "") return this.restoreCase(word[index - 1], result);
92
+ return this.restoreCase(match, result);
93
+ });
94
+ }
95
+ /**
96
+ * Sanitize a word by passing in the word and sanitization rules.
97
+ */
98
+ sanitizeWord(token, word, rules) {
99
+ if (!token.length || this.uncountables[token]) return word;
100
+ let len = rules.length;
101
+ while (len--) {
102
+ const rule = rules[len];
103
+ if (typeof rule[0] === "string" || rule[0].test(word)) return this.replace(word, rule);
104
+ }
105
+ return word;
106
+ }
107
+ /**
108
+ * Replace a word with the updated word.
109
+ */
110
+ replaceWord(word, direction) {
111
+ const replaceMap = direction === "SingularToPlural" ? this.irregularSingles : this.irregularPlurals;
112
+ const keepMap = direction === "SingularToPlural" ? this.irregularPlurals : this.irregularSingles;
113
+ const rules = direction === "SingularToPlural" ? this.pluralRules : this.singularRules;
114
+ const token = word.toLowerCase();
115
+ if (keepMap[token]) return this.restoreCase(word, token);
116
+ if (replaceMap[token]) return this.restoreCase(word, replaceMap[token]);
117
+ return this.sanitizeWord(token, word, rules);
118
+ }
119
+ /**
120
+ * Check if a word is part of the map.
121
+ */
122
+ checkWord(word, reason) {
123
+ const replaceMap = reason === "Plurality" ? this.irregularSingles : this.irregularPlurals;
124
+ const keepMap = reason === "Plurality" ? this.irregularPlurals : this.irregularSingles;
125
+ const rules = reason === "Plurality" ? this.pluralRules : this.singularRules;
126
+ const token = word.toLowerCase();
127
+ if (keepMap[token]) return true;
128
+ if (replaceMap[token]) return false;
129
+ return this.sanitizeWord(token, token, rules) === token;
130
+ }
131
+ /**
132
+ * Pluralize or singularize a word based on the passed in count.
133
+ */
134
+ pluralize(word, count, inclusive = false) {
135
+ const pluralized = count === 1 ? this.singular(word) : this.plural(word);
136
+ return (inclusive ? `${count} ` : "") + pluralized;
137
+ }
138
+ /**
139
+ * Pluralize a word.
140
+ */
141
+ plural(singularWord) {
142
+ return this.replaceWord(singularWord, "SingularToPlural");
143
+ }
144
+ /**
145
+ * Check if a word is plural.
146
+ */
147
+ isPlural(word) {
148
+ return this.checkWord(word, "Plurality");
149
+ }
150
+ /**
151
+ * Singularize a word.
152
+ */
153
+ singular(pluralWord) {
154
+ return this.replaceWord(pluralWord, "PluralToSingular");
155
+ }
156
+ /**
157
+ * Check if a word is singular.
158
+ */
159
+ isSingular(word) {
160
+ return this.checkWord(word, "Singularity");
161
+ }
162
+ };
163
+ //#endregion
210
164
  exports.Pluralize = Pluralize;
@@ -41,7 +41,7 @@ export declare class Pluralize {
41
41
  * @param {Array} args
42
42
  * @return {string}
43
43
  */
44
- interpolate(str: string, args: string[]): string;
44
+ private interpolate;
45
45
  /**
46
46
  * Replace a word using a rule.
47
47
  */
@@ -50,10 +50,6 @@ export declare class Pluralize {
50
50
  * Sanitize a word by passing in the word and sanitization rules.
51
51
  */
52
52
  sanitizeWord(token: string, word: string, rules: Rule[]): string;
53
- /**
54
- * Replace a word with the updated word.
55
- */
56
- old_replaceWord(replaceMap: Record<string, string>, keepMap: Record<string, string>, rules: Rule[]): (word: string) => string;
57
53
  /**
58
54
  * Replace a word with the updated word.
59
55
  */
@@ -65,7 +61,7 @@ export declare class Pluralize {
65
61
  /**
66
62
  * Pluralize or singularize a word based on the passed in count.
67
63
  */
68
- pluralize(word: string, count: number, inclusive: boolean): string;
64
+ pluralize(word: string, count: number, inclusive?: boolean): string;
69
65
  /**
70
66
  * Pluralize a word.
71
67
  */
@@ -73,7 +69,7 @@ export declare class Pluralize {
73
69
  /**
74
70
  * Check if a word is plural.
75
71
  */
76
- isPlural(word: string): void;
72
+ isPlural(word: string): boolean;
77
73
  /**
78
74
  * Singularize a word.
79
75
  */
@@ -81,5 +77,5 @@ export declare class Pluralize {
81
77
  /**
82
78
  * Check if a word is singular.
83
79
  */
84
- isSingular(word: string): void;
80
+ isSingular(word: string): boolean;
85
81
  }