@hichchi/utils 0.0.1-beta.2 → 0.0.2

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 (90) hide show
  1. package/index.cjs.default.js +1 -0
  2. package/index.cjs.js +3645 -0
  3. package/index.cjs.mjs +2 -0
  4. package/index.d.ts +1 -5
  5. package/index.esm.js +3575 -0
  6. package/package.json +13 -8
  7. package/src/index.d.ts +5 -0
  8. package/{interfaces → src/interfaces}/infinite-object.interface.d.ts +3 -3
  9. package/{interfaces → src/interfaces}/path-value-set.interface.d.ts +12 -12
  10. package/{types → src/types}/deep-partial.type.d.ts +6 -0
  11. package/{types → src/types}/literal-object.type.d.ts +2 -2
  12. package/{utils → src/utils}/index.d.ts +1 -0
  13. package/{utils → src/utils}/object.utils.d.ts +23 -19
  14. package/CHANGELOG.md +0 -19
  15. package/README.md +0 -7944
  16. package/constants/constants.js +0 -227
  17. package/constants/constants.js.map +0 -1
  18. package/constants/english-inflection-rules.js +0 -360
  19. package/constants/english-inflection-rules.js.map +0 -1
  20. package/constants/index.js +0 -6
  21. package/constants/index.js.map +0 -1
  22. package/enums/index.js +0 -5
  23. package/enums/index.js.map +0 -1
  24. package/enums/template-tag.enum.js +0 -39
  25. package/enums/template-tag.enum.js.map +0 -1
  26. package/index.js +0 -9
  27. package/index.js.map +0 -1
  28. package/interfaces/index.js +0 -7
  29. package/interfaces/index.js.map +0 -1
  30. package/interfaces/infinite-object.interface.js +0 -3
  31. package/interfaces/infinite-object.interface.js.map +0 -1
  32. package/interfaces/inflection-rule.interfaces.js +0 -3
  33. package/interfaces/inflection-rule.interfaces.js.map +0 -1
  34. package/interfaces/path-value-set.interface.js +0 -3
  35. package/interfaces/path-value-set.interface.js.map +0 -1
  36. package/readme-top.md +0 -187
  37. package/types/deep-partial.type.js +0 -3
  38. package/types/deep-partial.type.js.map +0 -1
  39. package/types/index.js +0 -38
  40. package/types/index.js.map +0 -1
  41. package/types/is-already-in-path.type.js +0 -3
  42. package/types/is-already-in-path.type.js.map +0 -1
  43. package/types/is-empty.type.js +0 -3
  44. package/types/is-empty.type.js.map +0 -1
  45. package/types/is-primitive.type.js +0 -4
  46. package/types/is-primitive.type.js.map +0 -1
  47. package/types/literal-object.type.js +0 -3
  48. package/types/literal-object.type.js.map +0 -1
  49. package/types/loose-autocomplete.type.js +0 -3
  50. package/types/loose-autocomplete.type.js.map +0 -1
  51. package/types/partial-with-null.type.js +0 -3
  52. package/types/partial-with-null.type.js.map +0 -1
  53. package/types/prettify.type.js +0 -3
  54. package/types/prettify.type.js.map +0 -1
  55. package/types/type.type.js +0 -3
  56. package/types/type.type.js.map +0 -1
  57. package/utils/assertions.utils.js +0 -163
  58. package/utils/assertions.utils.js.map +0 -1
  59. package/utils/file.utils.js +0 -1315
  60. package/utils/file.utils.js.map +0 -1
  61. package/utils/index.js +0 -9
  62. package/utils/index.js.map +0 -1
  63. package/utils/object.utils.js +0 -1069
  64. package/utils/object.utils.js.map +0 -1
  65. package/utils/string-template.utils.js +0 -269
  66. package/utils/string-template.utils.js.map +0 -1
  67. package/utils/string.utils.js +0 -1255
  68. package/utils/string.utils.js.map +0 -1
  69. package/utils/url.utils.js +0 -112
  70. package/utils/url.utils.js.map +0 -1
  71. /package/{constants → src/constants}/constants.d.ts +0 -0
  72. /package/{constants → src/constants}/english-inflection-rules.d.ts +0 -0
  73. /package/{constants → src/constants}/index.d.ts +0 -0
  74. /package/{enums → src/enums}/index.d.ts +0 -0
  75. /package/{enums → src/enums}/template-tag.enum.d.ts +0 -0
  76. /package/{interfaces → src/interfaces}/index.d.ts +0 -0
  77. /package/{interfaces → src/interfaces}/inflection-rule.interfaces.d.ts +0 -0
  78. /package/{types → src/types}/index.d.ts +0 -0
  79. /package/{types → src/types}/is-already-in-path.type.d.ts +0 -0
  80. /package/{types → src/types}/is-empty.type.d.ts +0 -0
  81. /package/{types → src/types}/is-primitive.type.d.ts +0 -0
  82. /package/{types → src/types}/loose-autocomplete.type.d.ts +0 -0
  83. /package/{types → src/types}/partial-with-null.type.d.ts +0 -0
  84. /package/{types → src/types}/prettify.type.d.ts +0 -0
  85. /package/{types → src/types}/type.type.d.ts +0 -0
  86. /package/{utils → src/utils}/assertions.utils.d.ts +0 -0
  87. /package/{utils → src/utils}/file.utils.d.ts +0 -0
  88. /package/{utils → src/utils}/string-template.utils.d.ts +0 -0
  89. /package/{utils → src/utils}/string.utils.d.ts +0 -0
  90. /package/{utils → src/utils}/url.utils.d.ts +0 -0
@@ -1,227 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONTEXT_MULTIPLIER = exports.DEFAULT_ELLIPSIS = exports.DEFAULT_CONTEXT_LENGTH = exports.DEFAULT_BREAK_CHAR = exports.DEFAULT_LINE_LENGTH = exports.CHARACTERS_TO_REMOVE = exports.HEX_PADDING_CHAR = exports.HEX_PADDING_LENGTH = exports.HEX_RADIX = void 0;
4
- /**
5
- * Base for hexadecimal number conversion
6
- *
7
- * This constant defines the radix (base) used for hexadecimal number conversion.
8
- * The value 16 represents the standard hexadecimal numbering system (0-9, A-F).
9
- * It's used in toString() and parseInt() operations involving hex values.
10
- *
11
- * @example
12
- * ```typescript
13
- * // Converting a number to hexadecimal string
14
- * const hexString = number.toString(HEX_RADIX);
15
- *
16
- * // Converting a hexadecimal string to a number
17
- * const number = parseInt(hexString, HEX_RADIX);
18
- * ```
19
- *
20
- * @see {@link HEX_PADDING_LENGTH} Related constant for hex string formatting
21
- * @see {@link HEX_PADDING_CHAR} Related constant for hex string padding
22
- */
23
- exports.HEX_RADIX = 16;
24
- /**
25
- * Minimum length for padded hexadecimal strings
26
- *
27
- * This constant defines the minimum length for hexadecimal strings after padding.
28
- * It ensures that hex values have a consistent length (e.g., "0A" instead of "A").
29
- * The value 2 ensures that single-digit hex values are padded with a leading zero.
30
- *
31
- * @example
32
- * ```typescript
33
- * // Padding a hex string to ensure consistent length
34
- * const paddedHex = hexString.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
35
- *
36
- * // Full example with conversion and padding
37
- * const byteValue = 10;
38
- * const hexByte = byteValue.toString(HEX_RADIX).padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
39
- * // hexByte = "0A"
40
- * ```
41
- *
42
- * @see {@link HEX_RADIX} Related constant for hex conversion
43
- * @see {@link HEX_PADDING_CHAR} Related constant for the padding character
44
- */
45
- exports.HEX_PADDING_LENGTH = 2;
46
- /**
47
- * Character used for padding hexadecimal strings
48
- *
49
- * This constant defines the character used to pad hexadecimal strings to reach
50
- * the minimum length defined by HEX_PADDING_LENGTH. The value "0" is the standard
51
- * padding character for hexadecimal values.
52
- *
53
- * @example
54
- * ```typescript
55
- * // Padding a hex string with zeros
56
- * const paddedHex = hexString.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
57
- *
58
- * // Example with a single-digit hex value
59
- * const hexValue = "F";
60
- * const paddedHex = hexValue.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
61
- * // paddedHex = "0F"
62
- * ```
63
- *
64
- * @see {@link HEX_RADIX} Related constant for hex conversion
65
- * @see {@link HEX_PADDING_LENGTH} Related constant for the minimum length
66
- */
67
- exports.HEX_PADDING_CHAR = "0";
68
- /**
69
- * Number of characters to remove in string truncation operations
70
- *
71
- * This constant defines the default number of characters to remove when
72
- * truncating strings in various utility functions. The value 2 is commonly
73
- * used when removing the last two characters of a string (e.g., removing
74
- * a trailing comma and space).
75
- *
76
- * @example
77
- * ```typescript
78
- * // Removing trailing characters from a string
79
- * const items = ["apple", "banana", "cherry"];
80
- * let result = "";
81
- *
82
- * for (const item of items) {
83
- * result += item + ", ";
84
- * }
85
- *
86
- * // Remove trailing comma and space
87
- * if (result.length > 0) {
88
- * result = result.slice(0, -CHARACTERS_TO_REMOVE);
89
- * }
90
- * // result = "apple, banana, cherry"
91
- * ```
92
- */
93
- exports.CHARACTERS_TO_REMOVE = 2;
94
- /**
95
- * Default maximum line length for word wrapping
96
- *
97
- * This constant defines the default maximum length of a line when performing
98
- * word wrapping operations. The value 80 is a common standard for line length
99
- * in many text formats and terminal displays.
100
- *
101
- * @example
102
- * ```typescript
103
- * // Wrapping a long text to the default line length
104
- * function wrapText(text: string, maxLength = DEFAULT_LINE_LENGTH, breakChar = DEFAULT_BREAK_CHAR): string {
105
- * // Word wrapping implementation
106
- * const result = [];
107
- * let line = "";
108
- *
109
- * for (const word of text.split(" ")) {
110
- * if ((line + word).length > maxLength) {
111
- * result.push(line);
112
- * line = word;
113
- * } else {
114
- * line += (line ? " " : "") + word;
115
- * }
116
- * }
117
- *
118
- * if (line) {
119
- * result.push(line);
120
- * }
121
- *
122
- * return result.join(breakChar);
123
- * }
124
- * ```
125
- *
126
- * @see {@link DEFAULT_BREAK_CHAR} Related constant for line break character
127
- */
128
- exports.DEFAULT_LINE_LENGTH = 80;
129
- /**
130
- * Default line break character for word wrapping
131
- *
132
- * This constant defines the default character or string used to separate lines
133
- * when performing word wrapping operations. The value "\n" represents a standard
134
- * line feed character used for line breaks in most text formats.
135
- *
136
- * @example
137
- * ```typescript
138
- * // Using the default break character in word wrapping
139
- * const wrappedText = longText.match(new RegExp(`.{1,${DEFAULT_LINE_LENGTH}}(\\s|$)`, 'g'))
140
- * ?.join(DEFAULT_BREAK_CHAR) || longText;
141
- * ```
142
- *
143
- * @see {@link DEFAULT_LINE_LENGTH} Related constant for maximum line length
144
- */
145
- exports.DEFAULT_BREAK_CHAR = "\n";
146
- /**
147
- * Default context length for text excerpts
148
- *
149
- * This constant defines the default number of characters to include before and after
150
- * a search term when generating text excerpts or snippets. The value 40 provides
151
- * enough context to understand the meaning while keeping the excerpt concise.
152
- *
153
- * @example
154
- * ```typescript
155
- * // Generating an excerpt around a search term
156
- * function generateExcerpt(text: string, searchTerm: string): string {
157
- * const index = text.toLowerCase().indexOf(searchTerm.toLowerCase());
158
- * if (index === -1) return text.substring(0, DEFAULT_CONTEXT_LENGTH * 2) + DEFAULT_ELLIPSIS;
159
- *
160
- * const start = Math.max(0, index - DEFAULT_CONTEXT_LENGTH);
161
- * const end = Math.min(text.length, index + searchTerm.length + DEFAULT_CONTEXT_LENGTH);
162
- *
163
- * let excerpt = text.substring(start, end);
164
- * if (start > 0) excerpt = DEFAULT_ELLIPSIS + excerpt;
165
- * if (end < text.length) excerpt = excerpt + DEFAULT_ELLIPSIS;
166
- *
167
- * return excerpt;
168
- * }
169
- * ```
170
- *
171
- * @see {@link DEFAULT_ELLIPSIS} Related constant for indicating truncated text
172
- * @see {@link CONTEXT_MULTIPLIER} Related constant for adjusting context length
173
- */
174
- exports.DEFAULT_CONTEXT_LENGTH = 40;
175
- /**
176
- * Default ellipsis string for indicating truncated text
177
- *
178
- * This constant defines the default string used to indicate that text has been
179
- * truncated or omitted in excerpts and summaries. The value "..." is the standard
180
- * ellipsis used to represent omitted content.
181
- *
182
- * @example
183
- * ```typescript
184
- * // Truncating a long string with ellipsis
185
- * function truncate(text: string, maxLength: number): string {
186
- * if (text.length <= maxLength) return text;
187
- * return text.substring(0, maxLength - DEFAULT_ELLIPSIS.length) + DEFAULT_ELLIPSIS;
188
- * }
189
- *
190
- * const longText = "This is a very long text that needs to be truncated";
191
- * const truncated = truncate(longText, 20);
192
- * // truncated = "This is a very lo..."
193
- * ```
194
- *
195
- * @see {@link DEFAULT_CONTEXT_LENGTH} Related constant for excerpt generation
196
- */
197
- exports.DEFAULT_ELLIPSIS = "...";
198
- /**
199
- * Multiplier for adjusting context length in excerpts
200
- *
201
- * This constant defines a multiplier used to adjust the context length when
202
- * generating excerpts under different conditions. The value 2 is typically
203
- * used to double the context length for certain scenarios, such as when no
204
- * search term is found.
205
- *
206
- * @example
207
- * ```typescript
208
- * // Using the multiplier to adjust context length
209
- * function getContextLength(hasSearchTerm: boolean): number {
210
- * return hasSearchTerm
211
- * ? DEFAULT_CONTEXT_LENGTH
212
- * : DEFAULT_CONTEXT_LENGTH * CONTEXT_MULTIPLIER;
213
- * }
214
- *
215
- * // Getting the first part of a text when no search term is found
216
- * function getFirstPart(text: string): string {
217
- * const length = DEFAULT_CONTEXT_LENGTH * CONTEXT_MULTIPLIER;
218
- * return text.length > length
219
- * ? text.substring(0, length) + DEFAULT_ELLIPSIS
220
- * : text;
221
- * }
222
- * ```
223
- *
224
- * @see {@link DEFAULT_CONTEXT_LENGTH} Related constant for base context length
225
- */
226
- exports.CONTEXT_MULTIPLIER = 2;
227
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../libs/utils/src/constants/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,SAAS,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,kBAAkB,GAAG,CAAC,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,gBAAgB,GAAG,GAAG,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACU,QAAA,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACU,QAAA,mBAAmB,GAAG,EAAE,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACU,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACU,QAAA,sBAAsB,GAAG,EAAE,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACU,QAAA,gBAAgB,GAAG,KAAK,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACU,QAAA,kBAAkB,GAAG,CAAC,CAAC"}
@@ -1,360 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EnglishInflectionRules = void 0;
4
- const constants_1 = require("./constants");
5
- /**
6
- * Comprehensive rules for English word inflection (singular/plural transformations)
7
- *
8
- * This module provides a structured collection of rules for transforming English words
9
- * between singular and plural forms. The rules are organized into categories based on
10
- * linguistic patterns and exceptions, ensuring accurate transformations for various
11
- * word types.
12
- *
13
- * Key features:
14
- * - Invariant words that are identical in singular and plural forms
15
- * - Irregular plural forms that don't follow standard patterns
16
- * - Latin and Greek origin words with their specific plural formations
17
- * - Pattern-based rules for common English word endings
18
- * - Default fallback rules for standard English pluralization
19
- *
20
- * The rules are applied in a specific priority order, from most specific to most general,
21
- * to ensure correct handling of special cases. Each rule consists of a regular expression
22
- * pattern and a replacement string or function.
23
- *
24
- * @example
25
- * ```typescript
26
- * // Using the rules with the plural() function
27
- * import { EnglishInflectionRules } from '@hichchi/utils/constants';
28
- * import { InflectionRule } from '@hichchi/utils/interfaces';
29
- *
30
- * function plural(word: string): string {
31
- * // Combine all rules in priority order
32
- * const rules: InflectionRule[] = [
33
- * ...EnglishInflectionRules.INVARIANT,
34
- * ...EnglishInflectionRules.IRREGULAR.toPlural,
35
- * ...EnglishInflectionRules.LATIN_GREEK.toPlural,
36
- * ...EnglishInflectionRules.PATTERN_RULES.toPlural,
37
- * ...EnglishInflectionRules.DEFAULT.toPlural,
38
- * ];
39
- *
40
- * // Apply the first matching rule
41
- * for (const rule of rules) {
42
- * if (rule.regex.test(word)) {
43
- * return word.replace(rule.regex, rule.replacement as string);
44
- * }
45
- * }
46
- *
47
- * return word;
48
- * }
49
- * ```
50
- *
51
- * @see {@link plural} Function that uses these rules to convert words to plural form
52
- * @see {@link singular} Function that uses these rules to convert words to singular form
53
- * @see {@link InflectionRuleCategories} Interface defining the structure of the rules
54
- * @see {@link InflectionRule} Interface for individual transformation rules
55
- */
56
- exports.EnglishInflectionRules = {
57
- /**
58
- * Words that are the same in singular and plural form
59
- *
60
- * This category contains rules for words that don't change between singular and plural forms.
61
- * These invariant words (also called "zero plurals") have identical singular and plural forms
62
- * in English. The rule simply returns the word unchanged.
63
- *
64
- * Common examples include:
65
- * - Animal names: "fish", "deer", "sheep"
66
- * - Scientific terms: "species", "series"
67
- * - Uncountable nouns: "equipment"
68
- *
69
- * @example
70
- * ```typescript
71
- * // These words remain unchanged in plural form
72
- * plural("fish"); // "fish"
73
- * plural("deer"); // "deer"
74
- * plural("sheep"); // "sheep"
75
- * plural("species"); // "species"
76
- * plural("equipment"); // "equipment"
77
- * ```
78
- *
79
- * @see {@link plural} Function that applies these rules
80
- * @see {@link singular} Function that applies these rules
81
- */
82
- INVARIANT: [{ regex: /^(fish|deer|sheep|species|series|equipment)$/i, replacement: "$1" }],
83
- /**
84
- * Irregular plural forms
85
- *
86
- * This category contains rules for words with irregular plural forms that don't
87
- * follow standard English pluralization patterns. These words have unique
88
- * transformations between singular and plural forms that must be handled as
89
- * special cases.
90
- *
91
- * The category is divided into two rule sets:
92
- * - toPlural: Rules for converting singular forms to their irregular plural forms
93
- * - toSingular: Rules for converting irregular plural forms back to singular
94
- *
95
- * These rules handle common irregular English plurals like "child/children",
96
- * "man/men", "tooth/teeth", etc. Many of these irregular forms have historical
97
- * origins in Old English and other Germanic languages.
98
- *
99
- * @example
100
- * ```typescript
101
- * // Singular to plural transformations
102
- * plural("child"); // "children"
103
- * plural("man"); // "men"
104
- * plural("tooth"); // "teeth"
105
- * plural("person"); // "people"
106
- *
107
- * // Plural to singular transformations
108
- * singular("children"); // "child"
109
- * singular("men"); // "man"
110
- * singular("teeth"); // "tooth"
111
- * singular("people"); // "person"
112
- * ```
113
- *
114
- * @see {@link plural} Function that applies these rules for pluralization
115
- * @see {@link singular} Function that applies these rules for singularization
116
- */
117
- IRREGULAR: {
118
- // Singular to plural transformations
119
- toPlural: [
120
- { regex: /^child$/i, replacement: "children" },
121
- { regex: /^man$/i, replacement: "men" },
122
- { regex: /^woman$/i, replacement: "women" },
123
- { regex: /^tooth$/i, replacement: "teeth" },
124
- { regex: /^foot$/i, replacement: "feet" },
125
- { regex: /^goose$/i, replacement: "geese" },
126
- { regex: /^mouse$/i, replacement: "mice" },
127
- { regex: /^person$/i, replacement: "people" },
128
- { regex: /^ox$/i, replacement: "oxen" },
129
- ],
130
- // Plural to singular transformations
131
- toSingular: [
132
- { regex: /children$/i, replacement: "child" },
133
- { regex: /men$/i, replacement: "man" },
134
- { regex: /women$/i, replacement: "woman" },
135
- { regex: /teeth$/i, replacement: "tooth" },
136
- { regex: /feet$/i, replacement: "foot" },
137
- { regex: /geese$/i, replacement: "goose" },
138
- { regex: /mice$/i, replacement: "mouse" },
139
- { regex: /people$/i, replacement: "person" },
140
- { regex: /oxen$/i, replacement: "ox" },
141
- ],
142
- },
143
- /**
144
- * Latin/Greek origin words
145
- *
146
- * This category contains rules for words borrowed from Latin and Greek that
147
- * retain their original pluralization patterns. These words follow different
148
- * rules than native English words and often have distinctive ending changes.
149
- *
150
- * The category is divided into two rule sets:
151
- * - toPlural: Rules for converting Latin/Greek singular forms to their plural forms
152
- * - toSingular: Rules for converting Latin/Greek plural forms back to singular
153
- *
154
- * Common patterns include:
155
- * - "-us" → "-i" (cactus/cacti, fungus/fungi)
156
- * - "-is" → "-es" (analysis/analyses, thesis/theses)
157
- * - "-on"/"-um" → "-a" (criterion/criteria, datum/data)
158
- * - "-ex"/"-ix" → "-ices" (index/indices, matrix/matrices)
159
- *
160
- * These words are often found in academic, scientific, and technical contexts.
161
- * Note that some of these words have alternative anglicized plural forms that
162
- * are also acceptable in modern English (e.g., "cactuses" alongside "cacti").
163
- *
164
- * @example
165
- * ```typescript
166
- * // Singular to plural transformations
167
- * plural("cactus"); // "cacti"
168
- * plural("analysis"); // "analyses"
169
- * plural("criterion"); // "criteria"
170
- * plural("index"); // "indices"
171
- * plural("matrix"); // "matrices"
172
- *
173
- * // Plural to singular transformations
174
- * singular("cacti"); // "cactus"
175
- * singular("analyses"); // "analysis"
176
- * singular("criteria"); // "criterion"
177
- * singular("indices"); // "index"
178
- * singular("matrices"); // "matrix"
179
- * ```
180
- *
181
- * @see {@link plural} Function that applies these rules for pluralization
182
- * @see {@link singular} Function that applies these rules for singularization
183
- */
184
- LATIN_GREEK: {
185
- // Singular to plural transformations
186
- toPlural: [
187
- { regex: /^cactus$/i, replacement: "cacti" },
188
- { regex: /^focus$/i, replacement: "foci" },
189
- { regex: /^fungus$/i, replacement: "fungi" },
190
- { regex: /^nucleus$/i, replacement: "nuclei" },
191
- { regex: /^syllabus$/i, replacement: "syllabi" },
192
- { regex: /^analysis$/i, replacement: "analyses" },
193
- { regex: /^diagnosis$/i, replacement: "diagnoses" },
194
- { regex: /^thesis$/i, replacement: "theses" },
195
- { regex: /^criterion$/i, replacement: "criteria" },
196
- { regex: /^datum$/i, replacement: "data" },
197
- { regex: /^phenomenon$/i, replacement: "phenomena" },
198
- { regex: /^index$/i, replacement: "indices" },
199
- { regex: /^matrix$/i, replacement: "matrices" },
200
- { regex: /^vertex$/i, replacement: "vertices" },
201
- { regex: /^appendix$/i, replacement: "appendices" },
202
- ],
203
- // Plural to singular transformations
204
- toSingular: [
205
- { regex: /matrices$/i, replacement: "matrix" },
206
- { regex: /indices$/i, replacement: "index" },
207
- { regex: /vertices$/i, replacement: "vertex" },
208
- { regex: /appendices$/i, replacement: "appendix" },
209
- { regex: /cacti$/i, replacement: "cactus" },
210
- { regex: /foci$/i, replacement: "focus" },
211
- { regex: /fungi$/i, replacement: "fungus" },
212
- { regex: /nuclei$/i, replacement: "nucleus" },
213
- { regex: /syllabi$/i, replacement: "syllabus" },
214
- { regex: /analyses$/i, replacement: "analysis" },
215
- { regex: /diagnoses$/i, replacement: "diagnosis" },
216
- { regex: /theses$/i, replacement: "thesis" },
217
- { regex: /criteria$/i, replacement: "criterion" },
218
- { regex: /data$/i, replacement: "datum" },
219
- { regex: /phenomena$/i, replacement: "phenomenon" },
220
- ],
221
- },
222
- /**
223
- * Words with specific ending patterns
224
- *
225
- * This category contains rules for words that follow regular patterns based on
226
- * their endings. These patterns represent the most common rules for English
227
- * pluralization and singularization, covering a wide range of everyday words.
228
- *
229
- * The category is divided into two rule sets:
230
- * - toPlural: Rules for converting singular forms to plural based on word endings
231
- * - toSingular: Rules for converting plural forms back to singular
232
- *
233
- * Key pattern groups include:
234
- *
235
- * 1. Words ending in -f or -fe:
236
- * - "knife" → "knives", "life" → "lives", "wolf" → "wolves"
237
- *
238
- * 2. Words ending in -y:
239
- * - After consonant: "city" → "cities", "baby" → "babies"
240
- * - After vowel: "boy" → "boys", "key" → "keys"
241
- *
242
- * 3. Words ending in -o:
243
- * - Some specific words: "hero" → "heroes", "potato" → "potatoes"
244
- * - After consonant: "echo" → "echoes", "tomato" → "tomatoes"
245
- *
246
- * 4. Words ending in -s, -ss, -sh, -ch, -x, -z:
247
- * - "bus" → "buses", "box" → "boxes", "dish" → "dishes"
248
- *
249
- * These patterns cover the majority of regular English pluralization rules
250
- * and are applied after checking for invariant words, irregular forms, and
251
- * Latin/Greek words.
252
- *
253
- * @example
254
- * ```typescript
255
- * // Words ending in -f or -fe
256
- * plural("knife"); // "knives"
257
- * plural("life"); // "lives"
258
- * plural("wolf"); // "wolves"
259
- *
260
- * // Words ending in -y
261
- * plural("city"); // "cities"
262
- * plural("boy"); // "boys"
263
- *
264
- * // Words ending in -o
265
- * plural("hero"); // "heroes"
266
- * plural("photo"); // "photos"
267
- *
268
- * // Words ending in -s, -ss, -sh, -ch, -x, -z
269
- * plural("bus"); // "buses"
270
- * plural("box"); // "boxes"
271
- * plural("dish"); // "dishes"
272
- *
273
- * // Plural to singular
274
- * singular("knives"); // "knife"
275
- * singular("cities"); // "city"
276
- * singular("boxes"); // "box"
277
- * ```
278
- *
279
- * @see {@link plural} Function that applies these rules for pluralization
280
- * @see {@link singular} Function that applies these rules for singularization
281
- * @see {@link CHARACTERS_TO_REMOVE} Constant used in some replacement functions
282
- */
283
- PATTERN_RULES: {
284
- // Singular to plural transformations
285
- toPlural: [
286
- // Words ending in -f or -fe
287
- { regex: /^((?:wi|li)fe)$/i, replacement: "$1ves" },
288
- { regex: /(fe)$/i, replacement: "ves" },
289
- { regex: /([^f])f$/i, replacement: "$1ves" },
290
- // Words ending in -y
291
- { regex: /([^aeiou])y$/i, replacement: "$1ies" },
292
- { regex: /([aeiou]y)$/i, replacement: "$1s" },
293
- // Words ending in -o
294
- { regex: /(hero|potato|tomato|torpedo|veto)$/i, replacement: "$1es" },
295
- { regex: /([^aeiou])o$/i, replacement: "$1oes" },
296
- // Words ending in -is
297
- { regex: /(is)$/i, replacement: "es" },
298
- // Words ending in -us
299
- { regex: /(us)$/i, replacement: "uses" },
300
- // Words ending in -s, -ss, -sh, -ch, -x, -z
301
- { regex: /(s|ss|sh|ch|x|z)$/i, replacement: "$1es" },
302
- ],
303
- // Plural to singular transformations
304
- toSingular: [
305
- // Special spelling changes
306
- { regex: /knives$/i, replacement: "knife" },
307
- { regex: /lives$/i, replacement: "life" },
308
- { regex: /shelves$/i, replacement: "shelf" },
309
- // Common word patterns
310
- {
311
- regex: /(buses|dishes|matches)$/i,
312
- replacement: (match) => match.slice(0, -constants_1.CHARACTERS_TO_REMOVE),
313
- },
314
- { regex: /([^aeiouy]|qu)ies$/i, replacement: "$1y" },
315
- { regex: /(x|ch|ss|sh)es$/i, replacement: "$1" },
316
- { regex: /oes$/i, replacement: "o" },
317
- { regex: /ves$/i, replacement: "f" },
318
- ],
319
- },
320
- /**
321
- * Default rules for standard transformations
322
- *
323
- * This category contains fallback rules that are applied when no other rules match.
324
- * These represent the most basic and common English pluralization pattern: adding
325
- * an "s" to form plurals and removing an "s" to form singulars.
326
- *
327
- * The category is divided into two rule sets:
328
- * - toPlural: Adds "s" to the end of any word to form its plural
329
- * - toSingular: Removes a trailing "s" from any word to form its singular
330
- *
331
- * These rules are applied as a last resort after all other more specific rules
332
- * have been checked. They handle the majority of regular English words that don't
333
- * fall into any of the special categories or patterns.
334
- *
335
- * While simple, these rules can sometimes produce incorrect results for words that
336
- * should follow more specific patterns but weren't included in the other rule sets.
337
- * They're designed as a reasonable fallback rather than a comprehensive solution.
338
- *
339
- * @example
340
- * ```typescript
341
- * // Singular to plural with default rule
342
- * plural("book"); // "books"
343
- * plural("car"); // "cars"
344
- * plural("apple"); // "apples"
345
- *
346
- * // Plural to singular with default rule
347
- * singular("books"); // "book"
348
- * singular("cars"); // "car"
349
- * singular("apples"); // "apple"
350
- * ```
351
- *
352
- * @see {@link plural} Function that applies these rules for pluralization
353
- * @see {@link singular} Function that applies these rules for singularization
354
- */
355
- DEFAULT: {
356
- toPlural: [{ regex: /(.*)$/i, replacement: "$1s" }],
357
- toSingular: [{ regex: /s$/i, replacement: "" }],
358
- },
359
- };
360
- //# sourceMappingURL=english-inflection-rules.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"english-inflection-rules.js","sourceRoot":"","sources":["../../../../libs/utils/src/constants/english-inflection-rules.ts"],"names":[],"mappings":";;;AAAA,2CAAmD;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACU,QAAA,sBAAsB,GAA6B;IAC5D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,EAAE,CAAC,EAAE,KAAK,EAAE,+CAA+C,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;IAE1F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,SAAS,EAAE;QACP,qCAAqC;QACrC,QAAQ,EAAE;YACN,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE;YAC9C,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE;YACvC,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE;YAC3C,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE;YAC3C,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE;YACzC,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE;YAC3C,EAAE,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE;YAC1C,EAAE,KAAK,EAAE,WAAW,EAAE,WA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AE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE;YAE5C,uBAAuB;YACvB;gBACI,KAAK,EAAE,0BAA0B;gBACjC,WAAW,EAAE,CAAC,KAAa,EAAU,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,gCAAoB,CAAC;aAChF;YACD,EAAE,KAAK,EAAE,qBAAqB,EAAE,WAAW,EAAE,KAAK,EAAE;YACpD,EAAE,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,IAAI,EAAE;YAChD,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE;YACpC,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE;SACvC;KACJ;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,OAAO,EAAE;QACL,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QACnD,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;KAClD;CACJ,CAAC"}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./constants"), exports);
5
- tslib_1.__exportStar(require("./english-inflection-rules"), exports);
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/utils/src/constants/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,qEAA2C"}
package/enums/index.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./template-tag.enum"), exports);
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/utils/src/enums/index.ts"],"names":[],"mappings":";;;AAAA,8DAAoC"}
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateTag = void 0;
4
- /**
5
- * Template tags for string transformations
6
- *
7
- * This enum defines all available template tags that can be used with the `applyTemplate`
8
- * and `applyTemplates` functions. Each tag corresponds to a specific string transformation
9
- * function from the string.utils module.
10
- *
11
- * Template tags are represented as strings in the format `#{transformationName}`. When these
12
- * tags appear in template strings, they are replaced with the result of applying the
13
- * corresponding transformation to the provided value.
14
- *
15
- * @see {@link applyTemplate} For applying a single value to a template
16
- * @see {@link applyTemplates} For applying multiple values to a template
17
- */
18
- var TemplateTag;
19
- (function (TemplateTag) {
20
- TemplateTag["UPPER_CASE"] = "#{upperCase}";
21
- TemplateTag["SNAKE_CASE"] = "#{snakeCase}";
22
- TemplateTag["UPPER_SNAKE_CASE"] = "#{upperSnakeCase}";
23
- TemplateTag["LOWER_CASE"] = "#{lowerCase}";
24
- TemplateTag["SENTENCE_CASE"] = "#{sentenceCase}";
25
- TemplateTag["FIRST_CASE"] = "#{firstCase}";
26
- TemplateTag["CAMEL_CASE"] = "#{camelCase}";
27
- TemplateTag["PASCAL_CASE"] = "#{pascalCase}";
28
- TemplateTag["KEBAB_CASE"] = "#{kebabCase}";
29
- TemplateTag["UPPER_KEBAB_CASE"] = "#{upperKebabCase}";
30
- TemplateTag["TITLE_CASE"] = "#{titleCase}";
31
- TemplateTag["LOWER_CASE_BREAK"] = "#{lowerCaseBreak}";
32
- TemplateTag["UPPER_CASE_BREAK"] = "#{upperCaseBreak}";
33
- TemplateTag["FIRST_CASE_BREAK"] = "#{firstCaseBreak}";
34
- TemplateTag["SINGULAR"] = "#{singular}";
35
- TemplateTag["NUMBER"] = "#{number}";
36
- TemplateTag["HTML_TO_TEXT"] = "#{htmlToText}";
37
- // FORMAT = "#{format}",
38
- })(TemplateTag || (exports.TemplateTag = TemplateTag = {}));
39
- //# sourceMappingURL=template-tag.enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"template-tag.enum.js","sourceRoot":"","sources":["../../../../libs/utils/src/enums/template-tag.enum.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;GAaG;AACH,IAAY,WAmBX;AAnBD,WAAY,WAAW;IACnB,0CAA2B,CAAA;IAC3B,0CAA2B,CAAA;IAC3B,qDAAsC,CAAA;IACtC,0CAA2B,CAAA;IAC3B,gDAAiC,CAAA;IACjC,0CAA2B,CAAA;IAC3B,0CAA2B,CAAA;IAC3B,4CAA6B,CAAA;IAC7B,0CAA2B,CAAA;IAC3B,qDAAsC,CAAA;IACtC,0CAA2B,CAAA;IAC3B,qDAAsC,CAAA;IACtC,qDAAsC,CAAA;IACtC,qDAAsC,CAAA;IACtC,uCAAwB,CAAA;IACxB,mCAAoB,CAAA;IACpB,6CAA8B,CAAA;IAC9B,wBAAwB;AAC5B,CAAC,EAnBW,WAAW,2BAAX,WAAW,QAmBtB"}