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.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/browser.d.ts +87 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +157 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli/index.d.ts +34 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +221 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/service.d.ts +128 -0
- package/dist/cli/service.d.ts.map +1 -0
- package/dist/cli/service.js +284 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/constants/index.d.ts +229 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +232 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/exporters/metadata-exporter.d.ts +104 -0
- package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
- package/dist/core/exporters/metadata-exporter.js +201 -0
- package/dist/core/exporters/metadata-exporter.js.map +1 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +56 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parsers/yaml-parser.d.ts +149 -0
- package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
- package/dist/core/parsers/yaml-parser.js +321 -0
- package/dist/core/parsers/yaml-parser.js.map +1 -0
- package/dist/core/processors/clause-processor.d.ts +74 -0
- package/dist/core/processors/clause-processor.d.ts.map +1 -0
- package/dist/core/processors/clause-processor.js +213 -0
- package/dist/core/processors/clause-processor.js.map +1 -0
- package/dist/core/processors/date-processor.d.ts +90 -0
- package/dist/core/processors/date-processor.d.ts.map +1 -0
- package/dist/core/processors/date-processor.js +336 -0
- package/dist/core/processors/date-processor.js.map +1 -0
- package/dist/core/processors/header-processor.d.ts +104 -0
- package/dist/core/processors/header-processor.d.ts.map +1 -0
- package/dist/core/processors/header-processor.js +585 -0
- package/dist/core/processors/header-processor.js.map +1 -0
- package/dist/core/processors/import-processor.d.ts +116 -0
- package/dist/core/processors/import-processor.d.ts.map +1 -0
- package/dist/core/processors/import-processor.js +236 -0
- package/dist/core/processors/import-processor.js.map +1 -0
- package/dist/core/processors/mixin-processor.d.ts +93 -0
- package/dist/core/processors/mixin-processor.d.ts.map +1 -0
- package/dist/core/processors/mixin-processor.js +378 -0
- package/dist/core/processors/mixin-processor.js.map +1 -0
- package/dist/core/processors/reference-processor.d.ts +115 -0
- package/dist/core/processors/reference-processor.d.ts.map +1 -0
- package/dist/core/processors/reference-processor.js +273 -0
- package/dist/core/processors/reference-processor.js.map +1 -0
- package/dist/errors/index.d.ts +234 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +267 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/extensions/batch-processor.d.ts +197 -0
- package/dist/extensions/batch-processor.d.ts.map +1 -0
- package/dist/extensions/batch-processor.js +392 -0
- package/dist/extensions/batch-processor.js.map +1 -0
- package/dist/extensions/formatters/index.d.ts +99 -0
- package/dist/extensions/formatters/index.d.ts.map +1 -0
- package/dist/extensions/formatters/index.js +128 -0
- package/dist/extensions/formatters/index.js.map +1 -0
- package/dist/extensions/index.d.ts +53 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/latex-parser.d.ts +111 -0
- package/dist/extensions/latex-parser.d.ts.map +1 -0
- package/dist/extensions/latex-parser.js +563 -0
- package/dist/extensions/latex-parser.js.map +1 -0
- package/dist/extensions/rst-parser.d.ts +112 -0
- package/dist/extensions/rst-parser.d.ts.map +1 -0
- package/dist/extensions/rst-parser.js +268 -0
- package/dist/extensions/rst-parser.js.map +1 -0
- package/dist/extensions/template-loops.d.ts +61 -0
- package/dist/extensions/template-loops.d.ts.map +1 -0
- package/dist/extensions/template-loops.js +418 -0
- package/dist/extensions/template-loops.js.map +1 -0
- package/dist/extensions/utilities/index.d.ts +114 -0
- package/dist/extensions/utilities/index.d.ts.map +1 -0
- package/dist/extensions/utilities/index.js +137 -0
- package/dist/extensions/utilities/index.js.map +1 -0
- package/dist/extensions/validators/index.d.ts +65 -0
- package/dist/extensions/validators/index.d.ts.map +1 -0
- package/dist/extensions/validators/index.js +88 -0
- package/dist/extensions/validators/index.js.map +1 -0
- package/dist/generators/html-generator.d.ts +184 -0
- package/dist/generators/html-generator.d.ts.map +1 -0
- package/dist/generators/html-generator.js +361 -0
- package/dist/generators/html-generator.js.map +1 -0
- package/dist/generators/pdf-generator.d.ts +165 -0
- package/dist/generators/pdf-generator.d.ts.map +1 -0
- package/dist/generators/pdf-generator.js +275 -0
- package/dist/generators/pdf-generator.js.map +1 -0
- package/dist/helpers/date-helpers.d.ts +216 -0
- package/dist/helpers/date-helpers.d.ts.map +1 -0
- package/dist/helpers/date-helpers.js +402 -0
- package/dist/helpers/date-helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +87 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +149 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/number-helpers.d.ts +269 -0
- package/dist/helpers/number-helpers.d.ts.map +1 -0
- package/dist/helpers/number-helpers.js +406 -0
- package/dist/helpers/number-helpers.js.map +1 -0
- package/dist/helpers/string-helpers.d.ts +391 -0
- package/dist/helpers/string-helpers.d.ts.map +1 -0
- package/dist/helpers/string-helpers.js +549 -0
- package/dist/helpers/string-helpers.js.map +1 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +384 -0
- package/dist/index.js.map +1 -0
- package/dist/legal-markdown.umd.min.js +2 -0
- package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
- package/dist/legal-markdown.umd.min.js.map +1 -0
- package/dist/lib/index.d.ts +150 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +265 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/parsers/content-detector.d.ts +131 -0
- package/dist/parsers/content-detector.d.ts.map +1 -0
- package/dist/parsers/content-detector.js +220 -0
- package/dist/parsers/content-detector.js.map +1 -0
- package/dist/parsers/fallback-parsers.d.ts +14 -0
- package/dist/parsers/fallback-parsers.d.ts.map +1 -0
- package/dist/parsers/fallback-parsers.js +188 -0
- package/dist/parsers/fallback-parsers.js.map +1 -0
- package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
- package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-native.js +63 -0
- package/dist/parsers/implementations/pandoc-native.js.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.js +64 -0
- package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
- package/dist/parsers/pandoc-factory.d.ts +97 -0
- package/dist/parsers/pandoc-factory.d.ts.map +1 -0
- package/dist/parsers/pandoc-factory.js +146 -0
- package/dist/parsers/pandoc-factory.js.map +1 -0
- package/dist/parsers/pandoc-loader.d.ts +24 -0
- package/dist/parsers/pandoc-loader.d.ts.map +1 -0
- package/dist/parsers/pandoc-loader.js +124 -0
- package/dist/parsers/pandoc-loader.js.map +1 -0
- package/dist/parsers/pandoc-parser.d.ts +27 -0
- package/dist/parsers/pandoc-parser.d.ts.map +1 -0
- package/dist/parsers/pandoc-parser.js +3 -0
- package/dist/parsers/pandoc-parser.js.map +1 -0
- package/dist/styles/default.css +125 -0
- package/dist/styles/headers.css +146 -0
- package/dist/styles/highlight.css +171 -0
- package/dist/tracking/field-tracker.d.ts +206 -0
- package/dist/tracking/field-tracker.d.ts.map +1 -0
- package/dist/tracking/field-tracker.js +247 -0
- package/dist/tracking/field-tracker.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +107 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/web/bundle-standalone.js +28 -0
- package/dist/web/bundle.js +17 -0
- package/dist/web/index.html +1465 -0
- package/dist/web/legal-markdown.umd.min.js +2 -0
- package/dist/web/standalone.html +390 -0
- package/dist/web/styles.css +874 -0
- package/package.json +118 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview String Manipulation and Formatting Helpers
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive string manipulation utilities designed
|
|
5
|
+
* for legal document processing. It includes functions for case conversion,
|
|
6
|
+
* text formatting, string validation, and various text processing operations
|
|
7
|
+
* commonly needed in legal document generation and formatting.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Case conversion (capitalize, title case, upper, lower)
|
|
11
|
+
* - String formatting (camelCase, kebab-case, snake_case, PascalCase)
|
|
12
|
+
* - Text manipulation (truncate, clean, pad, pluralize)
|
|
13
|
+
* - String validation and search (contains, replace)
|
|
14
|
+
* - Name processing (initials extraction)
|
|
15
|
+
* - Safe handling of null/undefined values
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { capitalize, titleCase, pluralize } from './string-helpers';
|
|
20
|
+
*
|
|
21
|
+
* // Case conversion
|
|
22
|
+
* 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 */
|
|
23
|
+
/**
|
|
24
|
+
* Capitalizes the first letter of a string
|
|
25
|
+
*
|
|
26
|
+
* Converts the first character to uppercase and the rest to lowercase.
|
|
27
|
+
* Safely handles null and undefined values by returning an empty string.
|
|
28
|
+
*
|
|
29
|
+
* @param {string | undefined | null} str - The string to capitalize
|
|
30
|
+
* @returns {string} The capitalized string, or empty string if input is null/undefined
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* capitalize('hello world'); // "Hello world"
|
|
35
|
+
* capitalize('HELLO WORLD'); // "Hello world"
|
|
36
|
+
* capitalize('hELLO wORLD'); // "Hello world"
|
|
37
|
+
* capitalize(''); // ""
|
|
38
|
+
* capitalize(null); // ""
|
|
39
|
+
* capitalize(undefined); // ""
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function capitalize(str: string | undefined | null): string;
|
|
43
|
+
/**
|
|
44
|
+
* Capitalizes the first letter of each word in a string
|
|
45
|
+
*
|
|
46
|
+
* Applies the capitalize function to each word separated by spaces,
|
|
47
|
+
* useful for formatting names, titles, and other multi-word strings.
|
|
48
|
+
*
|
|
49
|
+
* @param {string | undefined | null} str - The string to capitalize
|
|
50
|
+
* @returns {string} The string with each word capitalized
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* capitalizeWords('john doe'); // "John Doe"
|
|
55
|
+
* capitalizeWords('legal document'); // "Legal Document"
|
|
56
|
+
* capitalizeWords('HELLO WORLD'); // "Hello World"
|
|
57
|
+
* capitalizeWords('mixed CaSe WoRdS'); // "Mixed Case Words"
|
|
58
|
+
* capitalizeWords(''); // ""
|
|
59
|
+
* capitalizeWords(null); // ""
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function capitalizeWords(str: string | undefined | null): string;
|
|
63
|
+
/**
|
|
64
|
+
* Converts a string to uppercase
|
|
65
|
+
*
|
|
66
|
+
* Safely converts all characters in the string to uppercase,
|
|
67
|
+
* handling null and undefined values gracefully.
|
|
68
|
+
*
|
|
69
|
+
* @param {string | undefined | null} str - The string to convert
|
|
70
|
+
* @returns {string} The uppercase string, or empty string if input is null/undefined
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* upper('hello world'); // "HELLO WORLD"
|
|
75
|
+
* upper('Mixed Case'); // "MIXED CASE"
|
|
76
|
+
* upper(''); // ""
|
|
77
|
+
* upper(null); // ""
|
|
78
|
+
* upper(undefined); // ""
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function upper(str: string | undefined | null): string;
|
|
82
|
+
/**
|
|
83
|
+
* Converts a string to lowercase
|
|
84
|
+
*
|
|
85
|
+
* Safely converts all characters in the string to lowercase,
|
|
86
|
+
* handling null and undefined values gracefully.
|
|
87
|
+
*
|
|
88
|
+
* @param {string | undefined | null} str - The string to convert
|
|
89
|
+
* @returns {string} The lowercase string, or empty string if input is null/undefined
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* lower('HELLO WORLD'); // "hello world"
|
|
94
|
+
* lower('Mixed Case'); // "mixed case"
|
|
95
|
+
* lower(''); // ""
|
|
96
|
+
* lower(null); // ""
|
|
97
|
+
* lower(undefined); // ""
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function lower(str: string | undefined | null): string;
|
|
101
|
+
/**
|
|
102
|
+
* Converts a string to title case with proper handling of articles and prepositions
|
|
103
|
+
*
|
|
104
|
+
* Applies title case rules where the first and last words are always capitalized,
|
|
105
|
+
* and small words (articles, prepositions, conjunctions) are kept lowercase
|
|
106
|
+
* unless they appear at the beginning or end of the string.
|
|
107
|
+
*
|
|
108
|
+
* @param {string | undefined | null} str - The string to convert to title case
|
|
109
|
+
* @returns {string} The title-cased string
|
|
110
|
+
*
|
|
111
|
+
* Small words that remain lowercase: a, an, and, as, at, but, by, for, if, in,
|
|
112
|
+
* nor, of, on, or, so, the, to, up, yet
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* titleCase('the quick brown fox'); // "The Quick Brown Fox"
|
|
117
|
+
* titleCase('a tale of two cities'); // "A Tale of Two Cities"
|
|
118
|
+
* titleCase('for whom the bell tolls'); // "For Whom the Bell Tolls"
|
|
119
|
+
* titleCase('HELLO WORLD'); // "Hello World"
|
|
120
|
+
* titleCase(''); // ""
|
|
121
|
+
* titleCase(null); // ""
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function titleCase(str: string | undefined | null): string;
|
|
125
|
+
/**
|
|
126
|
+
* Converts a string to kebab-case format
|
|
127
|
+
*
|
|
128
|
+
* Transforms camelCase, PascalCase, or space-separated strings into
|
|
129
|
+
* kebab-case (lowercase with hyphens). Useful for URL slugs, CSS classes,
|
|
130
|
+
* and file names.
|
|
131
|
+
*
|
|
132
|
+
* @param {string | undefined | null} str - The string to convert
|
|
133
|
+
* @returns {string} The kebab-cased string
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* kebabCase('camelCaseString'); // "camel-case-string"
|
|
138
|
+
* kebabCase('PascalCaseString'); // "pascal-case-string"
|
|
139
|
+
* kebabCase('normal string'); // "normal-string"
|
|
140
|
+
* kebabCase('mixed_case string'); // "mixed-case-string"
|
|
141
|
+
* kebabCase(''); // ""
|
|
142
|
+
* kebabCase(null); // ""
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function kebabCase(str: string | undefined | null): string;
|
|
146
|
+
/**
|
|
147
|
+
* Converts a string to snake_case format
|
|
148
|
+
*
|
|
149
|
+
* Transforms camelCase, PascalCase, or space-separated strings into
|
|
150
|
+
* snake_case (lowercase with underscores). Commonly used for variable
|
|
151
|
+
* names, database fields, and API parameters.
|
|
152
|
+
*
|
|
153
|
+
* @param {string | undefined | null} str - The string to convert
|
|
154
|
+
* @returns {string} The snake_cased string
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* snakeCase('camelCaseString'); // "camel_case_string"
|
|
159
|
+
* snakeCase('PascalCaseString'); // "pascal_case_string"
|
|
160
|
+
* snakeCase('normal string'); // "normal_string"
|
|
161
|
+
* snakeCase('kebab-case-string'); // "kebab_case_string"
|
|
162
|
+
* snakeCase(''); // ""
|
|
163
|
+
* snakeCase(null); // ""
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export declare function snakeCase(str: string | undefined | null): string;
|
|
167
|
+
/**
|
|
168
|
+
* Converts a string to camelCase format
|
|
169
|
+
*
|
|
170
|
+
* Transforms space-separated, hyphenated, or snake_case strings into
|
|
171
|
+
* camelCase where the first word is lowercase and subsequent words
|
|
172
|
+
* are capitalized. Commonly used for JavaScript variable names.
|
|
173
|
+
*
|
|
174
|
+
* @param {string | undefined | null} str - The string to convert
|
|
175
|
+
* @returns {string} The camelCased string
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* camelCase('normal string'); // "normalString"
|
|
180
|
+
* camelCase('kebab-case-string'); // "kebabCaseString"
|
|
181
|
+
* camelCase('snake_case_string'); // "snakeCaseString"
|
|
182
|
+
* camelCase('PascalCaseString'); // "pascalCaseString"
|
|
183
|
+
* camelCase(''); // ""
|
|
184
|
+
* camelCase(null); // ""
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export declare function camelCase(str: string | undefined | null): string;
|
|
188
|
+
/**
|
|
189
|
+
* Converts a string to PascalCase format
|
|
190
|
+
*
|
|
191
|
+
* Transforms strings into PascalCase where the first letter of each word
|
|
192
|
+
* is capitalized and there are no spaces or separators. Commonly used
|
|
193
|
+
* for class names, constructor functions, and type names.
|
|
194
|
+
*
|
|
195
|
+
* @param {string | undefined | null} str - The string to convert
|
|
196
|
+
* @returns {string} The PascalCased string
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* pascalCase('normal string'); // "NormalString"
|
|
201
|
+
* pascalCase('kebab-case-string'); // "KebabCaseString"
|
|
202
|
+
* pascalCase('snake_case_string'); // "SnakeCaseString"
|
|
203
|
+
* pascalCase('camelCaseString'); // "CamelCaseString"
|
|
204
|
+
* pascalCase(''); // ""
|
|
205
|
+
* pascalCase(null); // ""
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
export declare function pascalCase(str: string | undefined | null): string;
|
|
209
|
+
/**
|
|
210
|
+
* Truncates a string to a specified length with optional suffix
|
|
211
|
+
*
|
|
212
|
+
* Shortens a string to the specified maximum length and appends a suffix
|
|
213
|
+
* (default: '...') if the string exceeds the limit. Useful for creating
|
|
214
|
+
* previews, summaries, or fitting text into constrained spaces.
|
|
215
|
+
*
|
|
216
|
+
* @param {string | undefined | null} str - The string to truncate
|
|
217
|
+
* @param {number} length - The maximum length of the result
|
|
218
|
+
* @param {string} suffix - The suffix to append when truncating (default: '...')
|
|
219
|
+
* @returns {string} The truncated string with suffix if needed
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* truncate('This is a long string', 10); // "This is a..."
|
|
224
|
+
* truncate('Short', 10); // "Short"
|
|
225
|
+
* truncate('This is a long string', 15, '…'); // "This is a long…"
|
|
226
|
+
* truncate('', 10); // ""
|
|
227
|
+
* truncate(null, 10); // ""
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
export declare function truncate(str: string | undefined | null, length: number, suffix?: string): string;
|
|
231
|
+
/**
|
|
232
|
+
* Removes extra whitespace and trims a string
|
|
233
|
+
*
|
|
234
|
+
* Collapses multiple consecutive whitespace characters into single spaces
|
|
235
|
+
* and removes leading/trailing whitespace. Useful for cleaning up user
|
|
236
|
+
* input or text from various sources.
|
|
237
|
+
*
|
|
238
|
+
* @param {string | undefined | null} str - The string to clean
|
|
239
|
+
* @returns {string} The cleaned string with normalized whitespace
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* clean(' hello world '); // "hello world"
|
|
244
|
+
* clean('\t\n text \r\n'); // "text"
|
|
245
|
+
* clean('normal spacing'); // "normal spacing"
|
|
246
|
+
* clean(''); // ""
|
|
247
|
+
* clean(null); // ""
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export declare function clean(str: string | undefined | null): string;
|
|
251
|
+
/**
|
|
252
|
+
* Pluralizes a word based on count with optional custom plural form
|
|
253
|
+
*
|
|
254
|
+
* Returns the singular form if count is 1, otherwise returns the plural form.
|
|
255
|
+
* Can accept a custom plural form or will apply basic English pluralization
|
|
256
|
+
* rules automatically.
|
|
257
|
+
*
|
|
258
|
+
* @param {string} word - The singular form of the word
|
|
259
|
+
* @param {number} count - The count to determine singular/plural
|
|
260
|
+
* @param {string} [plural] - Optional custom plural form
|
|
261
|
+
* @returns {string} The appropriate singular or plural form
|
|
262
|
+
*
|
|
263
|
+
* Basic pluralization rules applied:
|
|
264
|
+
* - Words ending in 's', 'x', 'z', 'sh', 'ch' → add 'es'
|
|
265
|
+
* - Words ending in consonant + 'y' → change 'y' to 'ies'
|
|
266
|
+
* - All other words → add 's'
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```typescript
|
|
270
|
+
* pluralize('cat', 1); // "cat"
|
|
271
|
+
* pluralize('cat', 2); // "cats"
|
|
272
|
+
* pluralize('box', 5); // "boxes"
|
|
273
|
+
* pluralize('city', 3); // "cities"
|
|
274
|
+
* pluralize('child', 2, 'children'); // "children"
|
|
275
|
+
* pluralize('person', 1, 'people'); // "person"
|
|
276
|
+
* pluralize('person', 3, 'people'); // "people"
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
export declare function pluralize(word: string, count: number, plural?: string): string;
|
|
280
|
+
/**
|
|
281
|
+
* Pads a string to a specified length from the start (left side)
|
|
282
|
+
*
|
|
283
|
+
* Adds padding characters to the beginning of a string until it reaches
|
|
284
|
+
* the specified length. Useful for formatting numbers, creating aligned
|
|
285
|
+
* text, or ensuring consistent string lengths.
|
|
286
|
+
*
|
|
287
|
+
* @param {string | undefined | null} str - The string to pad
|
|
288
|
+
* @param {number} length - The target length of the result
|
|
289
|
+
* @param {string} char - The character to use for padding (default: ' ')
|
|
290
|
+
* @returns {string} The padded string
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* padStart('42', 5); // " 42"
|
|
295
|
+
* padStart('42', 5, '0'); // "00042"
|
|
296
|
+
* padStart('hello', 8, '-'); // "---hello"
|
|
297
|
+
* padStart('toolong', 4); // "toolong" (no padding if already longer)
|
|
298
|
+
* padStart('', 3); // " "
|
|
299
|
+
* padStart(null, 5); // " "
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
export declare function padStart(str: string | undefined | null, length: number, char?: string): string;
|
|
303
|
+
/**
|
|
304
|
+
* Pads a string to a specified length from the end (right side)
|
|
305
|
+
*
|
|
306
|
+
* Adds padding characters to the end of a string until it reaches
|
|
307
|
+
* the specified length. Useful for creating aligned columns,
|
|
308
|
+
* formatting output, or ensuring consistent string lengths.
|
|
309
|
+
*
|
|
310
|
+
* @param {string | undefined | null} str - The string to pad
|
|
311
|
+
* @param {number} length - The target length of the result
|
|
312
|
+
* @param {string} char - The character to use for padding (default: ' ')
|
|
313
|
+
* @returns {string} The padded string
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* padEnd('42', 5); // "42 "
|
|
318
|
+
* padEnd('42', 5, '0'); // "42000"
|
|
319
|
+
* padEnd('hello', 8, '-'); // "hello---"
|
|
320
|
+
* padEnd('toolong', 4); // "toolong" (no padding if already longer)
|
|
321
|
+
* padEnd('', 3); // " "
|
|
322
|
+
* padEnd(null, 5); // " "
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
export declare function padEnd(str: string | undefined | null, length: number, char?: string): string;
|
|
326
|
+
/**
|
|
327
|
+
* Checks if a string contains a substring with optional case sensitivity
|
|
328
|
+
*
|
|
329
|
+
* Performs substring search with configurable case sensitivity.
|
|
330
|
+
* Useful for filtering, validation, and text analysis.
|
|
331
|
+
*
|
|
332
|
+
* @param {string | undefined | null} str - The string to search in
|
|
333
|
+
* @param {string} substring - The substring to search for
|
|
334
|
+
* @param {boolean} caseSensitive - Whether the search is case sensitive (default: false)
|
|
335
|
+
* @returns {boolean} True if the substring is found, false otherwise
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* contains('Hello World', 'hello'); // true (case insensitive)
|
|
340
|
+
* contains('Hello World', 'hello', true); // false (case sensitive)
|
|
341
|
+
* contains('Hello World', 'World'); // true
|
|
342
|
+
* contains('Hello World', 'xyz'); // false
|
|
343
|
+
* contains('', 'test'); // false
|
|
344
|
+
* contains(null, 'test'); // false
|
|
345
|
+
* contains('test', ''); // false
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
export declare function contains(str: string | undefined | null, substring: string, caseSensitive?: boolean): boolean;
|
|
349
|
+
/**
|
|
350
|
+
* Replaces all occurrences of a substring with a replacement string
|
|
351
|
+
*
|
|
352
|
+
* Performs global string replacement without using regular expressions.
|
|
353
|
+
* Useful for text processing, template substitution, and content cleanup.
|
|
354
|
+
*
|
|
355
|
+
* @param {string | undefined | null} str - The string to perform replacements on
|
|
356
|
+
* @param {string} search - The substring to search for
|
|
357
|
+
* @param {string} replace - The replacement string
|
|
358
|
+
* @returns {string} The string with all occurrences replaced
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* replaceAll('hello world hello', 'hello', 'hi'); // "hi world hi"
|
|
363
|
+
* replaceAll('a,b,c', ',', ' | '); // "a | b | c"
|
|
364
|
+
* replaceAll('test', 'x', 'y'); // "test" (no change)
|
|
365
|
+
* replaceAll('', 'x', 'y'); // ""
|
|
366
|
+
* replaceAll(null, 'x', 'y'); // ""
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export declare function replaceAll(str: string | undefined | null, search: string, replace: string): string;
|
|
370
|
+
/**
|
|
371
|
+
* Extracts initials from a name or multi-word string
|
|
372
|
+
*
|
|
373
|
+
* Takes the first character of each word (separated by spaces) and
|
|
374
|
+
* combines them into uppercase initials. Useful for creating
|
|
375
|
+
* abbreviated representations of names or titles.
|
|
376
|
+
*
|
|
377
|
+
* @param {string | undefined | null} name - The name or string to extract initials from
|
|
378
|
+
* @returns {string} The initials in uppercase
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* ```typescript
|
|
382
|
+
* initials('John Doe'); // "JD"
|
|
383
|
+
* initials('Mary Jane Watson'); // "MJW"
|
|
384
|
+
* initials('single'); // "S"
|
|
385
|
+
* initials('jean-claude van damme'); // "JVD" (hyphens treated as separators)
|
|
386
|
+
* initials(''); // ""
|
|
387
|
+
* initials(null); // ""
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
export declare function initials(name: string | undefined | null): string;
|
|
391
|
+
//# sourceMappingURL=string-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/string-helpers.ts"],"names":[],"mappings":"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"}
|