legal-markdown-js 0.1.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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +168 -0
  3. package/dist/browser.d.ts +87 -0
  4. package/dist/browser.d.ts.map +1 -0
  5. package/dist/browser.js +157 -0
  6. package/dist/browser.js.map +1 -0
  7. package/dist/cli/index.d.ts +34 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +221 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/service.d.ts +128 -0
  12. package/dist/cli/service.d.ts.map +1 -0
  13. package/dist/cli/service.js +284 -0
  14. package/dist/cli/service.js.map +1 -0
  15. package/dist/constants/index.d.ts +229 -0
  16. package/dist/constants/index.d.ts.map +1 -0
  17. package/dist/constants/index.js +232 -0
  18. package/dist/constants/index.js.map +1 -0
  19. package/dist/core/exporters/metadata-exporter.d.ts +104 -0
  20. package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
  21. package/dist/core/exporters/metadata-exporter.js +201 -0
  22. package/dist/core/exporters/metadata-exporter.js.map +1 -0
  23. package/dist/core/index.d.ts +40 -0
  24. package/dist/core/index.d.ts.map +1 -0
  25. package/dist/core/index.js +56 -0
  26. package/dist/core/index.js.map +1 -0
  27. package/dist/core/parsers/yaml-parser.d.ts +149 -0
  28. package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
  29. package/dist/core/parsers/yaml-parser.js +321 -0
  30. package/dist/core/parsers/yaml-parser.js.map +1 -0
  31. package/dist/core/processors/clause-processor.d.ts +74 -0
  32. package/dist/core/processors/clause-processor.d.ts.map +1 -0
  33. package/dist/core/processors/clause-processor.js +213 -0
  34. package/dist/core/processors/clause-processor.js.map +1 -0
  35. package/dist/core/processors/date-processor.d.ts +90 -0
  36. package/dist/core/processors/date-processor.d.ts.map +1 -0
  37. package/dist/core/processors/date-processor.js +336 -0
  38. package/dist/core/processors/date-processor.js.map +1 -0
  39. package/dist/core/processors/header-processor.d.ts +104 -0
  40. package/dist/core/processors/header-processor.d.ts.map +1 -0
  41. package/dist/core/processors/header-processor.js +585 -0
  42. package/dist/core/processors/header-processor.js.map +1 -0
  43. package/dist/core/processors/import-processor.d.ts +116 -0
  44. package/dist/core/processors/import-processor.d.ts.map +1 -0
  45. package/dist/core/processors/import-processor.js +236 -0
  46. package/dist/core/processors/import-processor.js.map +1 -0
  47. package/dist/core/processors/mixin-processor.d.ts +93 -0
  48. package/dist/core/processors/mixin-processor.d.ts.map +1 -0
  49. package/dist/core/processors/mixin-processor.js +378 -0
  50. package/dist/core/processors/mixin-processor.js.map +1 -0
  51. package/dist/core/processors/reference-processor.d.ts +115 -0
  52. package/dist/core/processors/reference-processor.d.ts.map +1 -0
  53. package/dist/core/processors/reference-processor.js +273 -0
  54. package/dist/core/processors/reference-processor.js.map +1 -0
  55. package/dist/errors/index.d.ts +234 -0
  56. package/dist/errors/index.d.ts.map +1 -0
  57. package/dist/errors/index.js +267 -0
  58. package/dist/errors/index.js.map +1 -0
  59. package/dist/extensions/batch-processor.d.ts +197 -0
  60. package/dist/extensions/batch-processor.d.ts.map +1 -0
  61. package/dist/extensions/batch-processor.js +392 -0
  62. package/dist/extensions/batch-processor.js.map +1 -0
  63. package/dist/extensions/formatters/index.d.ts +99 -0
  64. package/dist/extensions/formatters/index.d.ts.map +1 -0
  65. package/dist/extensions/formatters/index.js +128 -0
  66. package/dist/extensions/formatters/index.js.map +1 -0
  67. package/dist/extensions/index.d.ts +53 -0
  68. package/dist/extensions/index.d.ts.map +1 -0
  69. package/dist/extensions/index.js +71 -0
  70. package/dist/extensions/index.js.map +1 -0
  71. package/dist/extensions/latex-parser.d.ts +111 -0
  72. package/dist/extensions/latex-parser.d.ts.map +1 -0
  73. package/dist/extensions/latex-parser.js +563 -0
  74. package/dist/extensions/latex-parser.js.map +1 -0
  75. package/dist/extensions/rst-parser.d.ts +112 -0
  76. package/dist/extensions/rst-parser.d.ts.map +1 -0
  77. package/dist/extensions/rst-parser.js +268 -0
  78. package/dist/extensions/rst-parser.js.map +1 -0
  79. package/dist/extensions/template-loops.d.ts +61 -0
  80. package/dist/extensions/template-loops.d.ts.map +1 -0
  81. package/dist/extensions/template-loops.js +418 -0
  82. package/dist/extensions/template-loops.js.map +1 -0
  83. package/dist/extensions/utilities/index.d.ts +114 -0
  84. package/dist/extensions/utilities/index.d.ts.map +1 -0
  85. package/dist/extensions/utilities/index.js +137 -0
  86. package/dist/extensions/utilities/index.js.map +1 -0
  87. package/dist/extensions/validators/index.d.ts +65 -0
  88. package/dist/extensions/validators/index.d.ts.map +1 -0
  89. package/dist/extensions/validators/index.js +88 -0
  90. package/dist/extensions/validators/index.js.map +1 -0
  91. package/dist/generators/html-generator.d.ts +184 -0
  92. package/dist/generators/html-generator.d.ts.map +1 -0
  93. package/dist/generators/html-generator.js +361 -0
  94. package/dist/generators/html-generator.js.map +1 -0
  95. package/dist/generators/pdf-generator.d.ts +165 -0
  96. package/dist/generators/pdf-generator.d.ts.map +1 -0
  97. package/dist/generators/pdf-generator.js +275 -0
  98. package/dist/generators/pdf-generator.js.map +1 -0
  99. package/dist/helpers/date-helpers.d.ts +216 -0
  100. package/dist/helpers/date-helpers.d.ts.map +1 -0
  101. package/dist/helpers/date-helpers.js +402 -0
  102. package/dist/helpers/date-helpers.js.map +1 -0
  103. package/dist/helpers/index.d.ts +87 -0
  104. package/dist/helpers/index.d.ts.map +1 -0
  105. package/dist/helpers/index.js +149 -0
  106. package/dist/helpers/index.js.map +1 -0
  107. package/dist/helpers/number-helpers.d.ts +269 -0
  108. package/dist/helpers/number-helpers.d.ts.map +1 -0
  109. package/dist/helpers/number-helpers.js +406 -0
  110. package/dist/helpers/number-helpers.js.map +1 -0
  111. package/dist/helpers/string-helpers.d.ts +391 -0
  112. package/dist/helpers/string-helpers.d.ts.map +1 -0
  113. package/dist/helpers/string-helpers.js +549 -0
  114. package/dist/helpers/string-helpers.js.map +1 -0
  115. package/dist/index.d.ts +229 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +384 -0
  118. package/dist/index.js.map +1 -0
  119. package/dist/legal-markdown.umd.min.js +2 -0
  120. package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
  121. package/dist/legal-markdown.umd.min.js.map +1 -0
  122. package/dist/lib/index.d.ts +150 -0
  123. package/dist/lib/index.d.ts.map +1 -0
  124. package/dist/lib/index.js +265 -0
  125. package/dist/lib/index.js.map +1 -0
  126. package/dist/parsers/content-detector.d.ts +131 -0
  127. package/dist/parsers/content-detector.d.ts.map +1 -0
  128. package/dist/parsers/content-detector.js +220 -0
  129. package/dist/parsers/content-detector.js.map +1 -0
  130. package/dist/parsers/fallback-parsers.d.ts +14 -0
  131. package/dist/parsers/fallback-parsers.d.ts.map +1 -0
  132. package/dist/parsers/fallback-parsers.js +188 -0
  133. package/dist/parsers/fallback-parsers.js.map +1 -0
  134. package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
  135. package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
  136. package/dist/parsers/implementations/pandoc-native.js +63 -0
  137. package/dist/parsers/implementations/pandoc-native.js.map +1 -0
  138. package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
  139. package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
  140. package/dist/parsers/implementations/pandoc-wasm.js +64 -0
  141. package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
  142. package/dist/parsers/pandoc-factory.d.ts +97 -0
  143. package/dist/parsers/pandoc-factory.d.ts.map +1 -0
  144. package/dist/parsers/pandoc-factory.js +146 -0
  145. package/dist/parsers/pandoc-factory.js.map +1 -0
  146. package/dist/parsers/pandoc-loader.d.ts +24 -0
  147. package/dist/parsers/pandoc-loader.d.ts.map +1 -0
  148. package/dist/parsers/pandoc-loader.js +124 -0
  149. package/dist/parsers/pandoc-loader.js.map +1 -0
  150. package/dist/parsers/pandoc-parser.d.ts +27 -0
  151. package/dist/parsers/pandoc-parser.d.ts.map +1 -0
  152. package/dist/parsers/pandoc-parser.js +3 -0
  153. package/dist/parsers/pandoc-parser.js.map +1 -0
  154. package/dist/styles/default.css +125 -0
  155. package/dist/styles/headers.css +146 -0
  156. package/dist/styles/highlight.css +171 -0
  157. package/dist/tracking/field-tracker.d.ts +206 -0
  158. package/dist/tracking/field-tracker.d.ts.map +1 -0
  159. package/dist/tracking/field-tracker.js +247 -0
  160. package/dist/tracking/field-tracker.js.map +1 -0
  161. package/dist/types.d.ts +186 -0
  162. package/dist/types.d.ts.map +1 -0
  163. package/dist/types.js +33 -0
  164. package/dist/types.js.map +1 -0
  165. package/dist/utils/logger.d.ts +107 -0
  166. package/dist/utils/logger.d.ts.map +1 -0
  167. package/dist/utils/logger.js +122 -0
  168. package/dist/utils/logger.js.map +1 -0
  169. package/dist/web/bundle-standalone.js +28 -0
  170. package/dist/web/bundle.js +17 -0
  171. package/dist/web/index.html +1465 -0
  172. package/dist/web/legal-markdown.umd.min.js +2 -0
  173. package/dist/web/standalone.html +390 -0
  174. package/dist/web/styles.css +874 -0
  175. package/package.json +118 -0
@@ -0,0 +1,549 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview String Manipulation and Formatting Helpers
4
+ *
5
+ * This module provides comprehensive string manipulation utilities designed
6
+ * for legal document processing. It includes functions for case conversion,
7
+ * text formatting, string validation, and various text processing operations
8
+ * commonly needed in legal document generation and formatting.
9
+ *
10
+ * Features:
11
+ * - Case conversion (capitalize, title case, upper, lower)
12
+ * - String formatting (camelCase, kebab-case, snake_case, PascalCase)
13
+ * - Text manipulation (truncate, clean, pad, pluralize)
14
+ * - String validation and search (contains, replace)
15
+ * - Name processing (initials extraction)
16
+ * - Safe handling of null/undefined values
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * import { capitalize, titleCase, pluralize } from './string-helpers';
21
+ *
22
+ * // Case conversion
23
+ * const title = titleCase('legal document processing'); // \"Legal Document Processing\"\n *\n * // Text formatting\n * const name = capitalize('john doe'); // \"John doe\"\n *\n * // Pluralization\n * const items = pluralize('contract', 5); // \"contracts\"\n * ```\n */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.capitalize = capitalize;
26
+ exports.capitalizeWords = capitalizeWords;
27
+ exports.upper = upper;
28
+ exports.lower = lower;
29
+ exports.titleCase = titleCase;
30
+ exports.kebabCase = kebabCase;
31
+ exports.snakeCase = snakeCase;
32
+ exports.camelCase = camelCase;
33
+ exports.pascalCase = pascalCase;
34
+ exports.truncate = truncate;
35
+ exports.clean = clean;
36
+ exports.pluralize = pluralize;
37
+ exports.padStart = padStart;
38
+ exports.padEnd = padEnd;
39
+ exports.contains = contains;
40
+ exports.replaceAll = replaceAll;
41
+ exports.initials = initials;
42
+ /**
43
+ * Capitalizes the first letter of a string
44
+ *
45
+ * Converts the first character to uppercase and the rest to lowercase.
46
+ * Safely handles null and undefined values by returning an empty string.
47
+ *
48
+ * @param {string | undefined | null} str - The string to capitalize
49
+ * @returns {string} The capitalized string, or empty string if input is null/undefined
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * capitalize('hello world'); // "Hello world"
54
+ * capitalize('HELLO WORLD'); // "Hello world"
55
+ * capitalize('hELLO wORLD'); // "Hello world"
56
+ * capitalize(''); // ""
57
+ * capitalize(null); // ""
58
+ * capitalize(undefined); // ""
59
+ * ```
60
+ */
61
+ function capitalize(str) {
62
+ if (!str)
63
+ return '';
64
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
65
+ }
66
+ /**
67
+ * Capitalizes the first letter of each word in a string
68
+ *
69
+ * Applies the capitalize function to each word separated by spaces,
70
+ * useful for formatting names, titles, and other multi-word strings.
71
+ *
72
+ * @param {string | undefined | null} str - The string to capitalize
73
+ * @returns {string} The string with each word capitalized
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * capitalizeWords('john doe'); // "John Doe"
78
+ * capitalizeWords('legal document'); // "Legal Document"
79
+ * capitalizeWords('HELLO WORLD'); // "Hello World"
80
+ * capitalizeWords('mixed CaSe WoRdS'); // "Mixed Case Words"
81
+ * capitalizeWords(''); // ""
82
+ * capitalizeWords(null); // ""
83
+ * ```
84
+ */
85
+ function capitalizeWords(str) {
86
+ if (!str)
87
+ return '';
88
+ return str
89
+ .split(' ')
90
+ .map(word => capitalize(word))
91
+ .join(' ');
92
+ }
93
+ /**
94
+ * Converts a string to uppercase
95
+ *
96
+ * Safely converts all characters in the string to uppercase,
97
+ * handling null and undefined values gracefully.
98
+ *
99
+ * @param {string | undefined | null} str - The string to convert
100
+ * @returns {string} The uppercase string, or empty string if input is null/undefined
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * upper('hello world'); // "HELLO WORLD"
105
+ * upper('Mixed Case'); // "MIXED CASE"
106
+ * upper(''); // ""
107
+ * upper(null); // ""
108
+ * upper(undefined); // ""
109
+ * ```
110
+ */
111
+ function upper(str) {
112
+ return str ? str.toUpperCase() : '';
113
+ }
114
+ /**
115
+ * Converts a string to lowercase
116
+ *
117
+ * Safely converts all characters in the string to lowercase,
118
+ * handling null and undefined values gracefully.
119
+ *
120
+ * @param {string | undefined | null} str - The string to convert
121
+ * @returns {string} The lowercase string, or empty string if input is null/undefined
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * lower('HELLO WORLD'); // "hello world"
126
+ * lower('Mixed Case'); // "mixed case"
127
+ * lower(''); // ""
128
+ * lower(null); // ""
129
+ * lower(undefined); // ""
130
+ * ```
131
+ */
132
+ function lower(str) {
133
+ return str ? str.toLowerCase() : '';
134
+ }
135
+ /**
136
+ * Converts a string to title case with proper handling of articles and prepositions
137
+ *
138
+ * Applies title case rules where the first and last words are always capitalized,
139
+ * and small words (articles, prepositions, conjunctions) are kept lowercase
140
+ * unless they appear at the beginning or end of the string.
141
+ *
142
+ * @param {string | undefined | null} str - The string to convert to title case
143
+ * @returns {string} The title-cased string
144
+ *
145
+ * Small words that remain lowercase: a, an, and, as, at, but, by, for, if, in,
146
+ * nor, of, on, or, so, the, to, up, yet
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * titleCase('the quick brown fox'); // "The Quick Brown Fox"
151
+ * titleCase('a tale of two cities'); // "A Tale of Two Cities"
152
+ * titleCase('for whom the bell tolls'); // "For Whom the Bell Tolls"
153
+ * titleCase('HELLO WORLD'); // "Hello World"
154
+ * titleCase(''); // ""
155
+ * titleCase(null); // ""
156
+ * ```
157
+ */
158
+ function titleCase(str) {
159
+ if (!str)
160
+ return '';
161
+ const smallWords = new Set([
162
+ 'a',
163
+ 'an',
164
+ 'and',
165
+ 'as',
166
+ 'at',
167
+ 'but',
168
+ 'by',
169
+ 'for',
170
+ 'if',
171
+ 'in',
172
+ 'nor',
173
+ 'of',
174
+ 'on',
175
+ 'or',
176
+ 'so',
177
+ 'the',
178
+ 'to',
179
+ 'up',
180
+ 'yet',
181
+ ]);
182
+ return str
183
+ .split(' ')
184
+ .map((word, index) => {
185
+ const lowerWord = word.toLowerCase();
186
+ // Always capitalize first and last word
187
+ if (index === 0 || index === str.split(' ').length - 1) {
188
+ return capitalize(word);
189
+ }
190
+ // Don't capitalize small words unless they start the string
191
+ if (smallWords.has(lowerWord)) {
192
+ return lowerWord;
193
+ }
194
+ return capitalize(word);
195
+ })
196
+ .join(' ');
197
+ }
198
+ /**
199
+ * Converts a string to kebab-case format
200
+ *
201
+ * Transforms camelCase, PascalCase, or space-separated strings into
202
+ * kebab-case (lowercase with hyphens). Useful for URL slugs, CSS classes,
203
+ * and file names.
204
+ *
205
+ * @param {string | undefined | null} str - The string to convert
206
+ * @returns {string} The kebab-cased string
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * kebabCase('camelCaseString'); // "camel-case-string"
211
+ * kebabCase('PascalCaseString'); // "pascal-case-string"
212
+ * kebabCase('normal string'); // "normal-string"
213
+ * kebabCase('mixed_case string'); // "mixed-case-string"
214
+ * kebabCase(''); // ""
215
+ * kebabCase(null); // ""
216
+ * ```
217
+ */
218
+ function kebabCase(str) {
219
+ if (!str)
220
+ return '';
221
+ return str
222
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
223
+ .replace(/[\s_]+/g, '-')
224
+ .toLowerCase();
225
+ }
226
+ /**
227
+ * Converts a string to snake_case format
228
+ *
229
+ * Transforms camelCase, PascalCase, or space-separated strings into
230
+ * snake_case (lowercase with underscores). Commonly used for variable
231
+ * names, database fields, and API parameters.
232
+ *
233
+ * @param {string | undefined | null} str - The string to convert
234
+ * @returns {string} The snake_cased string
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * snakeCase('camelCaseString'); // "camel_case_string"
239
+ * snakeCase('PascalCaseString'); // "pascal_case_string"
240
+ * snakeCase('normal string'); // "normal_string"
241
+ * snakeCase('kebab-case-string'); // "kebab_case_string"
242
+ * snakeCase(''); // ""
243
+ * snakeCase(null); // ""
244
+ * ```
245
+ */
246
+ function snakeCase(str) {
247
+ if (!str)
248
+ return '';
249
+ return str
250
+ .replace(/([a-z])([A-Z])/g, '$1_$2')
251
+ .replace(/[\s-]+/g, '_')
252
+ .toLowerCase();
253
+ }
254
+ /**
255
+ * Converts a string to camelCase format
256
+ *
257
+ * Transforms space-separated, hyphenated, or snake_case strings into
258
+ * camelCase where the first word is lowercase and subsequent words
259
+ * are capitalized. Commonly used for JavaScript variable names.
260
+ *
261
+ * @param {string | undefined | null} str - The string to convert
262
+ * @returns {string} The camelCased string
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * camelCase('normal string'); // "normalString"
267
+ * camelCase('kebab-case-string'); // "kebabCaseString"
268
+ * camelCase('snake_case_string'); // "snakeCaseString"
269
+ * camelCase('PascalCaseString'); // "pascalCaseString"
270
+ * camelCase(''); // ""
271
+ * camelCase(null); // ""
272
+ * ```
273
+ */
274
+ function camelCase(str) {
275
+ if (!str)
276
+ return '';
277
+ return str
278
+ .split(/[\s-_]+/)
279
+ .map((word, index) => {
280
+ if (index === 0) {
281
+ return word.toLowerCase();
282
+ }
283
+ return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
284
+ })
285
+ .join('');
286
+ }
287
+ /**
288
+ * Converts a string to PascalCase format
289
+ *
290
+ * Transforms strings into PascalCase where the first letter of each word
291
+ * is capitalized and there are no spaces or separators. Commonly used
292
+ * for class names, constructor functions, and type names.
293
+ *
294
+ * @param {string | undefined | null} str - The string to convert
295
+ * @returns {string} The PascalCased string
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * pascalCase('normal string'); // "NormalString"
300
+ * pascalCase('kebab-case-string'); // "KebabCaseString"
301
+ * pascalCase('snake_case_string'); // "SnakeCaseString"
302
+ * pascalCase('camelCaseString'); // "CamelCaseString"
303
+ * pascalCase(''); // ""
304
+ * pascalCase(null); // ""
305
+ * ```
306
+ */
307
+ function pascalCase(str) {
308
+ if (!str)
309
+ return '';
310
+ const camel = camelCase(str);
311
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
312
+ }
313
+ /**
314
+ * Truncates a string to a specified length with optional suffix
315
+ *
316
+ * Shortens a string to the specified maximum length and appends a suffix
317
+ * (default: '...') if the string exceeds the limit. Useful for creating
318
+ * previews, summaries, or fitting text into constrained spaces.
319
+ *
320
+ * @param {string | undefined | null} str - The string to truncate
321
+ * @param {number} length - The maximum length of the result
322
+ * @param {string} suffix - The suffix to append when truncating (default: '...')
323
+ * @returns {string} The truncated string with suffix if needed
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * truncate('This is a long string', 10); // "This is a..."
328
+ * truncate('Short', 10); // "Short"
329
+ * truncate('This is a long string', 15, '…'); // "This is a long…"
330
+ * truncate('', 10); // ""
331
+ * truncate(null, 10); // ""
332
+ * ```
333
+ */
334
+ function truncate(str, length, suffix = '...') {
335
+ if (!str)
336
+ return '';
337
+ if (str.length <= length)
338
+ return str;
339
+ return str.slice(0, length - suffix.length) + suffix;
340
+ }
341
+ /**
342
+ * Removes extra whitespace and trims a string
343
+ *
344
+ * Collapses multiple consecutive whitespace characters into single spaces
345
+ * and removes leading/trailing whitespace. Useful for cleaning up user
346
+ * input or text from various sources.
347
+ *
348
+ * @param {string | undefined | null} str - The string to clean
349
+ * @returns {string} The cleaned string with normalized whitespace
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * clean(' hello world '); // "hello world"
354
+ * clean('\t\n text \r\n'); // "text"
355
+ * clean('normal spacing'); // "normal spacing"
356
+ * clean(''); // ""
357
+ * clean(null); // ""
358
+ * ```
359
+ */
360
+ function clean(str) {
361
+ if (!str)
362
+ return '';
363
+ return str.replace(/\s+/g, ' ').trim();
364
+ }
365
+ /**
366
+ * Pluralizes a word based on count with optional custom plural form
367
+ *
368
+ * Returns the singular form if count is 1, otherwise returns the plural form.
369
+ * Can accept a custom plural form or will apply basic English pluralization
370
+ * rules automatically.
371
+ *
372
+ * @param {string} word - The singular form of the word
373
+ * @param {number} count - The count to determine singular/plural
374
+ * @param {string} [plural] - Optional custom plural form
375
+ * @returns {string} The appropriate singular or plural form
376
+ *
377
+ * Basic pluralization rules applied:
378
+ * - Words ending in 's', 'x', 'z', 'sh', 'ch' → add 'es'
379
+ * - Words ending in consonant + 'y' → change 'y' to 'ies'
380
+ * - All other words → add 's'
381
+ *
382
+ * @example
383
+ * ```typescript
384
+ * pluralize('cat', 1); // "cat"
385
+ * pluralize('cat', 2); // "cats"
386
+ * pluralize('box', 5); // "boxes"
387
+ * pluralize('city', 3); // "cities"
388
+ * pluralize('child', 2, 'children'); // "children"
389
+ * pluralize('person', 1, 'people'); // "person"
390
+ * pluralize('person', 3, 'people'); // "people"
391
+ * ```
392
+ */
393
+ function pluralize(word, count, plural) {
394
+ if (count === 1)
395
+ return word;
396
+ if (plural)
397
+ return plural;
398
+ // Simple pluralization rules
399
+ const rules = [
400
+ [/s$/i, 's'],
401
+ [/([^aeiou])y$/i, '$1ies'],
402
+ [/(x|z|s|sh|ch)$/i, '$1es'],
403
+ [/$/i, 's'],
404
+ ];
405
+ for (const [pattern, replacement] of rules) {
406
+ if (pattern.test(word)) {
407
+ return word.replace(pattern, replacement);
408
+ }
409
+ }
410
+ return word + 's';
411
+ }
412
+ /**
413
+ * Pads a string to a specified length from the start (left side)
414
+ *
415
+ * Adds padding characters to the beginning of a string until it reaches
416
+ * the specified length. Useful for formatting numbers, creating aligned
417
+ * text, or ensuring consistent string lengths.
418
+ *
419
+ * @param {string | undefined | null} str - The string to pad
420
+ * @param {number} length - The target length of the result
421
+ * @param {string} char - The character to use for padding (default: ' ')
422
+ * @returns {string} The padded string
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * padStart('42', 5); // " 42"
427
+ * padStart('42', 5, '0'); // "00042"
428
+ * padStart('hello', 8, '-'); // "---hello"
429
+ * padStart('toolong', 4); // "toolong" (no padding if already longer)
430
+ * padStart('', 3); // " "
431
+ * padStart(null, 5); // " "
432
+ * ```
433
+ */
434
+ function padStart(str, length, char = ' ') {
435
+ if (!str)
436
+ return char.repeat(length);
437
+ return str.padStart(length, char);
438
+ }
439
+ /**
440
+ * Pads a string to a specified length from the end (right side)
441
+ *
442
+ * Adds padding characters to the end of a string until it reaches
443
+ * the specified length. Useful for creating aligned columns,
444
+ * formatting output, or ensuring consistent string lengths.
445
+ *
446
+ * @param {string | undefined | null} str - The string to pad
447
+ * @param {number} length - The target length of the result
448
+ * @param {string} char - The character to use for padding (default: ' ')
449
+ * @returns {string} The padded string
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * padEnd('42', 5); // "42 "
454
+ * padEnd('42', 5, '0'); // "42000"
455
+ * padEnd('hello', 8, '-'); // "hello---"
456
+ * padEnd('toolong', 4); // "toolong" (no padding if already longer)
457
+ * padEnd('', 3); // " "
458
+ * padEnd(null, 5); // " "
459
+ * ```
460
+ */
461
+ function padEnd(str, length, char = ' ') {
462
+ if (!str)
463
+ return char.repeat(length);
464
+ return str.padEnd(length, char);
465
+ }
466
+ /**
467
+ * Checks if a string contains a substring with optional case sensitivity
468
+ *
469
+ * Performs substring search with configurable case sensitivity.
470
+ * Useful for filtering, validation, and text analysis.
471
+ *
472
+ * @param {string | undefined | null} str - The string to search in
473
+ * @param {string} substring - The substring to search for
474
+ * @param {boolean} caseSensitive - Whether the search is case sensitive (default: false)
475
+ * @returns {boolean} True if the substring is found, false otherwise
476
+ *
477
+ * @example
478
+ * ```typescript
479
+ * contains('Hello World', 'hello'); // true (case insensitive)
480
+ * contains('Hello World', 'hello', true); // false (case sensitive)
481
+ * contains('Hello World', 'World'); // true
482
+ * contains('Hello World', 'xyz'); // false
483
+ * contains('', 'test'); // false
484
+ * contains(null, 'test'); // false
485
+ * contains('test', ''); // false
486
+ * ```
487
+ */
488
+ function contains(str, substring, caseSensitive = false) {
489
+ if (!str || !substring)
490
+ return false;
491
+ if (caseSensitive) {
492
+ return str.includes(substring);
493
+ }
494
+ return str.toLowerCase().includes(substring.toLowerCase());
495
+ }
496
+ /**
497
+ * Replaces all occurrences of a substring with a replacement string
498
+ *
499
+ * Performs global string replacement without using regular expressions.
500
+ * Useful for text processing, template substitution, and content cleanup.
501
+ *
502
+ * @param {string | undefined | null} str - The string to perform replacements on
503
+ * @param {string} search - The substring to search for
504
+ * @param {string} replace - The replacement string
505
+ * @returns {string} The string with all occurrences replaced
506
+ *
507
+ * @example
508
+ * ```typescript
509
+ * replaceAll('hello world hello', 'hello', 'hi'); // "hi world hi"
510
+ * replaceAll('a,b,c', ',', ' | '); // "a | b | c"
511
+ * replaceAll('test', 'x', 'y'); // "test" (no change)
512
+ * replaceAll('', 'x', 'y'); // ""
513
+ * replaceAll(null, 'x', 'y'); // ""
514
+ * ```
515
+ */
516
+ function replaceAll(str, search, replace) {
517
+ if (!str)
518
+ return '';
519
+ return str.split(search).join(replace);
520
+ }
521
+ /**
522
+ * Extracts initials from a name or multi-word string
523
+ *
524
+ * Takes the first character of each word (separated by spaces) and
525
+ * combines them into uppercase initials. Useful for creating
526
+ * abbreviated representations of names or titles.
527
+ *
528
+ * @param {string | undefined | null} name - The name or string to extract initials from
529
+ * @returns {string} The initials in uppercase
530
+ *
531
+ * @example
532
+ * ```typescript
533
+ * initials('John Doe'); // "JD"
534
+ * initials('Mary Jane Watson'); // "MJW"
535
+ * initials('single'); // "S"
536
+ * initials('jean-claude van damme'); // "JVD" (hyphens treated as separators)
537
+ * initials(''); // ""
538
+ * initials(null); // ""
539
+ * ```
540
+ */
541
+ function initials(name) {
542
+ if (!name)
543
+ return '';
544
+ return name
545
+ .split(' ')
546
+ .map(word => word.charAt(0).toUpperCase())
547
+ .join('');
548
+ }
549
+ //# sourceMappingURL=string-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-helpers.js","sourceRoot":"","sources":["../../src/helpers/string-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;iTAqBiT;;AAqBjT,gCAGC;AAqBD,0CAMC;AAoBD,sBAEC;AAoBD,sBAEC;AAyBD,8BAwCC;AAsBD,8BAMC;AAsBD,8BAMC;AAsBD,8BAWC;AAsBD,gCAIC;AAuBD,4BAQC;AAqBD,sBAGC;AA8BD,8BAoBC;AAwBD,4BAOC;AAwBD,wBAGC;AAwBD,4BAYC;AAsBD,gCAOC;AAsBD,4BAMC;AAjhBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,UAAU,CAAC,GAA8B;IACvD,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,eAAe,CAAC,GAA8B;IAC5D,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,OAAO,GAAG;SACP,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;SAC7B,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,KAAK,CAA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