@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
@@ -1,12 +1,8 @@
1
+ //#region src/set/is-superset.ts
1
2
  function isSuperset(set, subset) {
2
- const _set = set instanceof Set ? set : new Set(set);
3
- for (const elem of subset) {
4
- if (!_set.has(elem)) {
5
- return false;
6
- }
7
- }
8
- return true;
3
+ const _set = set instanceof Set ? set : new Set(set);
4
+ for (const elem of subset) if (!_set.has(elem)) return false;
5
+ return true;
9
6
  }
10
- export {
11
- isSuperset
12
- };
7
+ //#endregion
8
+ export { isSuperset };
@@ -0,0 +1 @@
1
+ export {};
@@ -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
  }