@hichchi/utils 0.0.1-alpha.1 → 0.0.1-beta.1

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 (106) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +6236 -1032
  3. package/constants/constants.d.ts +223 -0
  4. package/constants/constants.js +227 -0
  5. package/constants/constants.js.map +1 -0
  6. package/constants/english-inflection-rules.d.ts +53 -0
  7. package/constants/english-inflection-rules.js +360 -0
  8. package/constants/english-inflection-rules.js.map +1 -0
  9. package/constants/index.d.ts +2 -0
  10. package/constants/index.js +6 -0
  11. package/constants/index.js.map +1 -0
  12. package/enums/index.d.ts +1 -0
  13. package/{src → enums}/index.js +1 -1
  14. package/enums/index.js.map +1 -0
  15. package/enums/template-tag.enum.d.ts +33 -0
  16. package/enums/template-tag.enum.js +39 -0
  17. package/enums/template-tag.enum.js.map +1 -0
  18. package/index.d.ts +5 -0
  19. package/index.js +9 -0
  20. package/index.js.map +1 -0
  21. package/interfaces/index.d.ts +3 -0
  22. package/interfaces/index.js +7 -0
  23. package/interfaces/index.js.map +1 -0
  24. package/interfaces/infinite-object.interface.d.ts +45 -0
  25. package/interfaces/infinite-object.interface.js +3 -0
  26. package/interfaces/infinite-object.interface.js.map +1 -0
  27. package/interfaces/inflection-rule.interfaces.d.ts +142 -0
  28. package/interfaces/inflection-rule.interfaces.js +3 -0
  29. package/interfaces/inflection-rule.interfaces.js.map +1 -0
  30. package/interfaces/path-value-set.interface.d.ts +79 -0
  31. package/interfaces/path-value-set.interface.js +3 -0
  32. package/interfaces/path-value-set.interface.js.map +1 -0
  33. package/package.json +4 -4
  34. package/readme-top.md +182 -6
  35. package/types/deep-partial.type.d.ts +47 -0
  36. package/types/deep-partial.type.js +3 -0
  37. package/types/deep-partial.type.js.map +1 -0
  38. package/types/index.d.ts +34 -0
  39. package/types/index.js +38 -0
  40. package/types/index.js.map +1 -0
  41. package/types/is-already-in-path.type.d.ts +24 -0
  42. package/types/is-already-in-path.type.js +3 -0
  43. package/types/is-already-in-path.type.js.map +1 -0
  44. package/types/is-empty.type.d.ts +25 -0
  45. package/types/is-empty.type.js +3 -0
  46. package/types/is-empty.type.js.map +1 -0
  47. package/types/is-primitive.type.d.ts +27 -0
  48. package/types/is-primitive.type.js +4 -0
  49. package/types/is-primitive.type.js.map +1 -0
  50. package/types/literal-object.type.d.ts +49 -0
  51. package/types/literal-object.type.js +3 -0
  52. package/types/literal-object.type.js.map +1 -0
  53. package/{src/lib/types.d.ts → types/loose-autocomplete.type.d.ts} +18 -6
  54. package/types/loose-autocomplete.type.js +3 -0
  55. package/types/loose-autocomplete.type.js.map +1 -0
  56. package/types/partial-with-null.type.d.ts +27 -0
  57. package/types/partial-with-null.type.js +3 -0
  58. package/types/partial-with-null.type.js.map +1 -0
  59. package/types/prettify.type.d.ts +23 -0
  60. package/types/prettify.type.js +3 -0
  61. package/types/prettify.type.js.map +1 -0
  62. package/types/type.type.d.ts +21 -0
  63. package/{src/lib/interfaces.js → types/type.type.js} +1 -1
  64. package/types/type.type.js.map +1 -0
  65. package/utils/assertions.utils.d.ts +150 -0
  66. package/utils/assertions.utils.js +163 -0
  67. package/utils/assertions.utils.js.map +1 -0
  68. package/utils/file.utils.d.ts +87 -0
  69. package/{src/lib → utils}/file.utils.js +78 -26
  70. package/utils/file.utils.js.map +1 -0
  71. package/{src/lib → utils}/index.d.ts +3 -5
  72. package/{src/lib → utils}/index.js +3 -5
  73. package/utils/index.js.map +1 -0
  74. package/utils/object.utils.d.ts +912 -0
  75. package/utils/object.utils.js +1069 -0
  76. package/utils/object.utils.js.map +1 -0
  77. package/utils/string-template.utils.d.ts +169 -0
  78. package/utils/string-template.utils.js +269 -0
  79. package/utils/string-template.utils.js.map +1 -0
  80. package/utils/string.utils.d.ts +932 -0
  81. package/utils/string.utils.js +1255 -0
  82. package/utils/string.utils.js.map +1 -0
  83. package/utils/url.utils.d.ts +99 -0
  84. package/utils/url.utils.js +112 -0
  85. package/utils/url.utils.js.map +1 -0
  86. package/src/index.d.ts +0 -1
  87. package/src/index.js.map +0 -1
  88. package/src/lib/assertions.utils.d.ts +0 -55
  89. package/src/lib/assertions.utils.js +0 -68
  90. package/src/lib/assertions.utils.js.map +0 -1
  91. package/src/lib/file.utils.d.ts +0 -25
  92. package/src/lib/file.utils.js.map +0 -1
  93. package/src/lib/index.js.map +0 -1
  94. package/src/lib/interfaces.d.ts +0 -6
  95. package/src/lib/interfaces.js.map +0 -1
  96. package/src/lib/object.utils.d.ts +0 -265
  97. package/src/lib/object.utils.js +0 -414
  98. package/src/lib/object.utils.js.map +0 -1
  99. package/src/lib/string-template.utils.d.ts +0 -25
  100. package/src/lib/string-template.utils.js +0 -40
  101. package/src/lib/string-template.utils.js.map +0 -1
  102. package/src/lib/string.utils.d.ts +0 -217
  103. package/src/lib/string.utils.js +0 -314
  104. package/src/lib/string.utils.js.map +0 -1
  105. package/src/lib/types.js +0 -4
  106. package/src/lib/types.js.map +0 -1
@@ -0,0 +1,932 @@
1
+ /**
2
+ * Breaks a string into an array of words based on common separator patterns.
3
+ *
4
+ * This function intelligently splits strings into individual words by detecting various
5
+ * word boundary patterns, including:
6
+ * - Camel case boundaries ("helloWorld" → ["hello", "world"])
7
+ * - Snake case boundaries ("hello_world" → ["hello", "world"])
8
+ * - Kebab case boundaries ("hello-world" → ["hello", "world"])
9
+ * - Space-separated words ("hello world" → ["hello", "world"])
10
+ * - Uppercase acronyms ("APIClient" → ["api", "client"])
11
+ *
12
+ * The returned words are all converted to lowercase.
13
+ *
14
+ * @param {string} str - The string to split into words
15
+ * @returns {string[]} - An array of lowercase words
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * breakToWords("helloWorld"); // ['hello', 'world']
20
+ * breakToWords("hello_world"); // ['hello', 'world']
21
+ * breakToWords("hello-world"); // ['hello', 'world']
22
+ * breakToWords("hello world"); // ['hello', 'world']
23
+ * breakToWords("APIConfig"); // ['api', 'config']
24
+ * breakToWords("123Test456"); // ['123', 'test', '456']
25
+ * ```
26
+ *
27
+ * @remarks
28
+ * - Returns an empty array for empty, null, or undefined input
29
+ * - Preserves numbers as separate words
30
+ * - Handles consecutive uppercase letters as acronyms (preserving them as a single word)
31
+ */
32
+ export declare function breakToWords(str: string): string[];
33
+ /**
34
+ * Breaks a string into words and formats them using a provided function.
35
+ *
36
+ * This overload splits a string into words using the same logic as the array version,
37
+ * but additionally applies a formatting function to each word and joins them with spaces.
38
+ *
39
+ * Common use cases include:
40
+ * - Converting camelCase to Title Case
41
+ * - Formatting identifiers for display
42
+ * - Normalizing different string formats
43
+ *
44
+ * @param {string} str - The string to split and format
45
+ * @param {(str: string) => string} format - A function to apply to each word
46
+ * @returns {string} - A space-joined string of formatted words
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Convert camelCase to Sentence case
51
+ * breakToWords("helloWorld", toFirstCase); // "Hello world"
52
+ *
53
+ * // Convert snake_case to Title Case
54
+ * breakToWords("user_profile_data", toFirstCase); // "User profile data"
55
+ *
56
+ * // Format with a custom function
57
+ * breakToWords("SYSTEM_ERROR", word => word.toLowerCase()); // "system error"
58
+ * ```
59
+ */
60
+ export declare function breakToWords(str: string, format: (str: string) => string): string;
61
+ /**
62
+ * Converts a string to lowercase with safe handling of undefined or null values.
63
+ *
64
+ * This utility function provides a safe way to convert strings to lowercase, automatically
65
+ * handling edge cases where the input might be undefined, null, or empty. Unlike the native
66
+ * String.prototype.toLowerCase() method, this function won't throw an error when called
67
+ * with undefined or null values, instead returning an empty string.
68
+ *
69
+ * This is particularly useful when working with user input, API responses, or any scenario
70
+ * where string values might be optional or potentially undefined. It's commonly used for
71
+ * case-insensitive comparisons, search functionality, or normalizing text data.
72
+ *
73
+ * @param {string} [str] - The string to convert to lowercase. Can be undefined or null.
74
+ * @returns {string} The lowercase version of the input string, or an empty string if input is falsy
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * // Basic string conversion
79
+ * const result1 = toLowerCase("Hello World");
80
+ * // Returns: "hello world"
81
+ *
82
+ * const result2 = toLowerCase("JAVASCRIPT");
83
+ * // Returns: "javascript"
84
+ * ```
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Safe handling of undefined/null values
89
+ * const result1 = toLowerCase(undefined);
90
+ * // Returns: ""
91
+ *
92
+ * const result2 = toLowerCase(null);
93
+ * // Returns: ""
94
+ *
95
+ * const result3 = toLowerCase("");
96
+ * // Returns: ""
97
+ * ```
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * // Use in case-insensitive search
102
+ * function searchUsers(users: User[], searchTerm: string): User[] {
103
+ * const normalizedSearch = toLowerCase(searchTerm);
104
+ * return users.filter(user =>
105
+ * toLowerCase(user.name).includes(normalizedSearch) ||
106
+ * toLowerCase(user.email).includes(normalizedSearch)
107
+ * );
108
+ * }
109
+ * ```
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * // Use in form validation
114
+ * function validateEmail(email?: string): boolean {
115
+ * const normalizedEmail = toLowerCase(email);
116
+ * const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
117
+ * return emailRegex.test(normalizedEmail);
118
+ * }
119
+ * ```
120
+ *
121
+ * @remarks
122
+ * - Returns an empty string for any falsy input (undefined, null, empty string)
123
+ * - Uses the native String.prototype.toLowerCase() method for actual conversion
124
+ * - Does not modify the original string (strings are immutable in JavaScript)
125
+ * - Handles all Unicode characters correctly, following locale-independent rules
126
+ * - More robust than direct .toLowerCase() calls when input might be undefined
127
+ *
128
+ * @see {@link toUpperCase} Function for converting strings to uppercase
129
+ * @see {@link toLowerCaseBreak} Function for converting to lowercase and breaking into words
130
+ */
131
+ export declare function toLowerCase(str?: string): string;
132
+ /**
133
+ * Converts a string to lowercase and breaks it into words, joining them with a specified separator.
134
+ *
135
+ * This utility function combines word breaking and case conversion in a single operation.
136
+ * It first breaks the input string into individual words using intelligent pattern recognition
137
+ * (handling camelCase, snake_case, kebab-case, etc.), converts each word to lowercase,
138
+ * and then joins them with the specified separator or a space by default.
139
+ *
140
+ * This is particularly useful for converting various naming conventions to a consistent
141
+ * lowercase format, creating readable labels from variable names, generating search-friendly
142
+ * text, or preparing strings for further processing where consistent word separation is needed.
143
+ *
144
+ * @param {string} [str] - The string to convert and break into words. Can be undefined or null.
145
+ * @param {string} [join=" "] - The separator to use when joining the words. Defaults to a single space.
146
+ * @returns {string} A lowercase string with words separated by the specified join character,
147
+ * or an empty string if input is falsy
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * // Basic camelCase conversion
152
+ * const result1 = toLowerCaseBreak("HelloWorld");
153
+ * // Returns: "hello world"
154
+ *
155
+ * const result2 = toLowerCaseBreak("getUserProfile");
156
+ * // Returns: "get user profile"
157
+ * ```
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // Custom separators
162
+ * const result1 = toLowerCaseBreak("HelloWorld", "-");
163
+ * // Returns: "hello-world"
164
+ *
165
+ * const result2 = toLowerCaseBreak("APIResponseHandler", "_");
166
+ * // Returns: "api_response_handler"
167
+ *
168
+ * const result3 = toLowerCaseBreak("userAccountSettings", " | ");
169
+ * // Returns: "user | account | settings"
170
+ * ```
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * // Various input formats
175
+ * const result1 = toLowerCaseBreak("snake_case_example");
176
+ * // Returns: "snake case example"
177
+ *
178
+ * const result2 = toLowerCaseBreak("kebab-case-example");
179
+ * // Returns: "kebab case example"
180
+ *
181
+ * const result3 = toLowerCaseBreak("CONSTANT_VALUE");
182
+ * // Returns: "constant value"
183
+ * ```
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Creating user-friendly labels
188
+ * function createLabel(fieldName: string): string {
189
+ * return toLowerCaseBreak(fieldName)
190
+ * .split(' ')
191
+ * .map(word => word.charAt(0).toUpperCase() + word.slice(1))
192
+ * .join(' ');
193
+ * }
194
+ *
195
+ * createLabel("firstName"); // "First Name"
196
+ * createLabel("emailAddress"); // "Email Address"
197
+ * ```
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * // Safe handling of edge cases
202
+ * const result1 = toLowerCaseBreak(undefined);
203
+ * // Returns: ""
204
+ *
205
+ * const result2 = toLowerCaseBreak("", "-");
206
+ * // Returns: ""
207
+ *
208
+ * const result3 = toLowerCaseBreak("singleword");
209
+ * // Returns: "singleword"
210
+ * ```
211
+ *
212
+ * @remarks
213
+ * - Returns an empty string for any falsy input (undefined, null, empty string)
214
+ * - Uses the same intelligent word-breaking algorithm as the breakToWords function
215
+ * - Handles camelCase, PascalCase, snake_case, kebab-case, and mixed formats
216
+ * - Preserves numbers as separate words when they appear in the string
217
+ * - The join parameter can be any string, including empty string for concatenation
218
+ * - More efficient than calling breakToWords and toLowerCase separately
219
+ *
220
+ * @see {@link breakToWords} Function for breaking strings into word arrays
221
+ * @see {@link toLowerCase} Function for simple lowercase conversion
222
+ * @see {@link toUpperCaseBreak} Function for uppercase word breaking
223
+ */
224
+ export declare function toLowerCaseBreak(str?: string, join?: string): string;
225
+ /**
226
+ * Converts a string to uppercase with safe handling of undefined or null values.
227
+ *
228
+ * This utility function provides a safe way to convert strings to uppercase, automatically
229
+ * handling edge cases where the input might be undefined, null, or empty. Unlike the native
230
+ * String.prototype.toUpperCase() method, this function won't throw an error when called
231
+ * with undefined or null values, instead returning an empty string.
232
+ *
233
+ * This is particularly useful when working with user input, API responses, or any scenario
234
+ * where string values might be optional or potentially undefined. It's commonly used for
235
+ * creating constants, formatting display text, generating identifiers, or normalizing text
236
+ * data that needs to be in uppercase format.
237
+ *
238
+ * @param {string} [str] - The string to convert to uppercase. Can be undefined or null.
239
+ * @returns {string} The uppercase version of the input string, or an empty string if input is falsy
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // Basic string conversion
244
+ * const result1 = toUpperCase("hello world");
245
+ * // Returns: "HELLO WORLD"
246
+ *
247
+ * const result2 = toUpperCase("javascript");
248
+ * // Returns: "JAVASCRIPT"
249
+ * ```
250
+ *
251
+ * @example
252
+ * ```typescript
253
+ * // Safe handling of undefined/null values
254
+ * const result1 = toUpperCase(undefined);
255
+ * // Returns: ""
256
+ *
257
+ * const result2 = toUpperCase(null);
258
+ * // Returns: ""
259
+ *
260
+ * const result3 = toUpperCase("");
261
+ * // Returns: ""
262
+ * ```
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * // Creating constants or identifiers
267
+ * function generateConstantName(variableName: string): string {
268
+ * return toUpperCase(variableName.replace(/[^a-zA-Z0-9]/g, '_'));
269
+ * }
270
+ *
271
+ * generateConstantName("user-profile"); // "USER_PROFILE"
272
+ * generateConstantName("api.endpoint"); // "API_ENDPOINT"
273
+ * ```
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // Use in text formatting
278
+ * function formatTitle(title?: string): string {
279
+ * if (!title) return "UNTITLED";
280
+ * return toUpperCase(title.trim());
281
+ * }
282
+ *
283
+ * formatTitle("my document"); // "MY DOCUMENT"
284
+ * formatTitle(undefined); // "UNTITLED"
285
+ * ```
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * // Use in case-insensitive comparisons
290
+ * function compareIgnoreCase(str1?: string, str2?: string): boolean {
291
+ * return toUpperCase(str1) === toUpperCase(str2);
292
+ * }
293
+ *
294
+ * compareIgnoreCase("Hello", "HELLO"); // true
295
+ * compareIgnoreCase("Test", "test"); // true
296
+ * ```
297
+ *
298
+ * @remarks
299
+ * - Returns an empty string for any falsy input (undefined, null, empty string)
300
+ * - Uses the native String.prototype.toUpperCase() method for actual conversion
301
+ * - Does not modify the original string (strings are immutable in JavaScript)
302
+ * - Handles all Unicode characters correctly, following locale-independent rules
303
+ * - More robust than direct .toUpperCase() calls when input might be undefined
304
+ * - Particularly useful for creating constants, headers, or display text
305
+ *
306
+ * @see {@link toLowerCase} Function for converting strings to lowercase
307
+ * @see {@link toUpperCaseBreak} Function for converting to uppercase and breaking into words
308
+ */
309
+ export declare function toUpperCase(str?: string): string;
310
+ /**
311
+ * Compares two strings for similarity using Levenshtein distance algorithm.
312
+ *
313
+ * The Levenshtein distance is a measure of the difference between two strings
314
+ * by counting the minimum number of single-character edits (insertions, deletions,
315
+ * or substitutions) required to change one string into another.
316
+ *
317
+ * @param {string} str1 - First string to compare
318
+ * @param {string} str2 - Second string to compare
319
+ * @returns {number} - A value between 0 and 1, where 1 means identical strings
320
+ *
321
+ * @example
322
+ * ```typescript
323
+ * stringSimilarity("hello", "hallo"); // 0.8 (4/5 characters match)
324
+ * stringSimilarity("kitten", "sitting"); // ~0.57 (higher distance)
325
+ * stringSimilarity("same", "same"); // 1.0 (identical)
326
+ * ```
327
+ */
328
+ export declare function stringSimilarity(str1: string, str2: string): number;
329
+ /**
330
+ * Generates a slug from a string, suitable for URLs or file names.
331
+ *
332
+ * @param {string} str - The string to convert to a slug
333
+ * @param {string} [separator="-"] - The character to use as separator
334
+ * @returns {string} - The slug string
335
+ *
336
+ * @example
337
+ * ```typescript
338
+ * slugify("Hello World"); // "hello-world"
339
+ * slugify("10 Tips & Tricks!"); // "10-tips-tricks"
340
+ * slugify("My Product (2023 Edition)"); // "my-product-2023-edition"
341
+ * slugify("Über résumé"); // "uber-resume"
342
+ * slugify("Blog Post", "_"); // "blog_post"
343
+ * ```
344
+ */
345
+ export declare function slugify(str: string, separator?: string): string;
346
+ /**
347
+ * Extracts all email addresses from a string.
348
+ *
349
+ * @param {string} str - The string to extract emails from
350
+ * @returns {string[]} - Array of found email addresses
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * extractEmails("Contact us at support@example.com or sales@example.com");
355
+ * // ["support@example.com", "sales@example.com"]
356
+ * ```
357
+ */
358
+ export declare function extractEmails(str: string): string[];
359
+ /**
360
+ * Extracts all URLs from a string.
361
+ *
362
+ * @param {string} str - The string to extract URLs from
363
+ * @returns {string[]} - Array of found URLs
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * extractUrls("Visit https://example.com or http://test.org/page?id=5");
368
+ * // ["https://example.com", "http://test.org/page?id=5"]
369
+ * ```
370
+ */
371
+ export declare function extractUrls(str: string): string[];
372
+ /**
373
+ * Converts a string to a secure hash using SHA-256.
374
+ *
375
+ * Note: This is a browser-compatible implementation using the Web Crypto API.
376
+ * For Node.js environments, you might want to use the crypto module instead.
377
+ *
378
+ * @param {string} str - The string to hash
379
+ * @returns {Promise<string>} - Promise resolving to the hex hash string
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * // Browser usage
384
+ * await hashString("password123");
385
+ * // "ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f"
386
+ * ```
387
+ */
388
+ export declare function hashString(str: string): Promise<string>;
389
+ /**
390
+ * Generates a random string with specified length and character set.
391
+ *
392
+ * @param {number} length - The length of the random string
393
+ * @param {string} [charset] - The characters to use (defaults to alphanumeric)
394
+ * @returns {string} - The generated random string
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * // Default alphanumeric string
399
+ * randomString(8);
400
+ * // e.g. "A7bC9Df3"
401
+ *
402
+ * // Hex string
403
+ * randomString(6, "0123456789abcdef");
404
+ * // e.g. "a3f9d2"
405
+ *
406
+ * // PIN code
407
+ * randomString(4, "0123456789");
408
+ * // e.g. "8302"
409
+ * ```
410
+ */
411
+ export declare function randomString(length: number, charset?: string): string;
412
+ /**
413
+ * Masks a portion of a string, useful for displaying sensitive information.
414
+ *
415
+ * @param {string} str - The string to mask
416
+ * @param {number} [visibleStart=0] - Number of characters to show at the beginning
417
+ * @param {number} [visibleEnd=0] - Number of characters to show at the end
418
+ * @param {string} [maskChar="*"] - Character to use for masking
419
+ * @returns {string} - The masked string
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * // Mask credit card
424
+ * maskString("4111111111111111", 4, 4);
425
+ * // "4111********1111"
426
+ *
427
+ * // Mask email
428
+ * maskString("user@example.com", 2, 4, "x");
429
+ * // "usxxxxxx.com"
430
+ *
431
+ * // Mask phone number
432
+ * maskString("+1-555-123-4567", 0, 4);
433
+ * // "*********4567"
434
+ * ```
435
+ */
436
+ export declare function maskString(str: string, visibleStart?: number, visibleEnd?: number, maskChar?: string): string;
437
+ /**
438
+ * Convert a string to first case (Capitalize first letter of the string).
439
+ * @param {string} [str] Optional string to join the words with.
440
+ * @returns {string} String in first case.
441
+ *
442
+ * @example
443
+ * ```TypeScript
444
+ * toFirstCase("hello world"); // "Hello world"
445
+ * ```
446
+ */
447
+ export declare function toFirstCase(str?: string): string;
448
+ /**
449
+ * Converts a string to a camelCase or PascalCase variable name.
450
+ *
451
+ * @param {string} str - The string to convert
452
+ * @param {boolean} [pascalCase=false] - Whether to use PascalCase (true) or camelCase (false)
453
+ * @returns {string} - The variable name
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * toVariableName("Hello World"); // "helloWorld"
458
+ * toVariableName("API Response"); // "apiResponse"
459
+ * toVariableName("first-name"); // "firstName"
460
+ * toVariableName("user_id", true); // "UserId"
461
+ * ```
462
+ */
463
+ export declare function toVariableName(str: string, pascalCase?: boolean): string;
464
+ /**
465
+ * Wraps words in a string to ensure each line is no longer than a specified length.
466
+ *
467
+ * @param {string} str - The string to wrap
468
+ * @param {number} [lineLength=80] - Maximum length of each line
469
+ * @param {string} [breakChar="\n"] - Character(s) to insert at line breaks
470
+ * @returns {string} - The wrapped string
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * const text = "This is a long sentence that needs to be wrapped to fit within a certain width.";
475
+ *
476
+ * wordWrap(text, 20);
477
+ * // "This is a long\nsentence that needs\nto be wrapped to\nfit within a\ncertain width."
478
+ *
479
+ * wordWrap(text, 30, "<br>");
480
+ * // "This is a long sentence that<br>needs to be wrapped to fit<br>within a certain width."
481
+ * ```
482
+ */
483
+ export declare function wordWrap(str: string, lineLength?: number, breakChar?: string): string;
484
+ /**
485
+ * Creates an excerpt from a longer text by extracting a portion around a search term.
486
+ * Useful for search result highlighting or previews.
487
+ *
488
+ * @param {string} text - The full text to create an excerpt from
489
+ * @param {string} searchTerm - The search term to find in the text
490
+ * @param {number} [contextLength=40] - Number of characters to include before and after the search term
491
+ * @param {string} [ellipsis="..."] - Characters to use for indicating truncated text
492
+ * @returns {string} - The excerpt with the search term in context
493
+ *
494
+ * @example
495
+ * ```typescript
496
+ * const article = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in dui mauris.";
497
+ *
498
+ * createExcerpt(article, "dolor", 10);
499
+ * // "...ipsum dolor sit amet..."
500
+ *
501
+ * createExcerpt(article, "consectetur", 15, "[...]");
502
+ * // "[...]sit amet, consectetur adipiscing[...]"
503
+ * ```
504
+ */
505
+ export declare function createExcerpt(text: string, searchTerm: string, contextLength?: number, ellipsis?: string): string;
506
+ /**
507
+ * Normalizes a string by removing accents, diacritics, and converting to lowercase.
508
+ *
509
+ * @param {string} str - The string to normalize
510
+ * @returns {string} - The normalized string
511
+ *
512
+ * @example
513
+ * ```typescript
514
+ * normalizeString("Café"); // "cafe"
515
+ * normalizeString("Über"); // "uber"
516
+ * normalizeString("résumé"); // "resume"
517
+ * normalizeString("ESPAÑA"); // "espana"
518
+ * ```
519
+ */
520
+ export declare function normalizeString(str: string): string;
521
+ /**
522
+ * Convert a string to upper cases and break into words with optional join or space.
523
+ * @param {string} [str] String to convert to upper cases and break into words.
524
+ * @param {string} [join] Optional string to join the words with.
525
+ * @returns {string} String in upper cases and broken into words.
526
+ *
527
+ * @example
528
+ * ```TypeScript
529
+ * toUpperCaseBreak("HelloWorld"); // "HELLO WORLD"
530
+ * ```
531
+ *
532
+ * @example
533
+ * ```TypeScript
534
+ * toUpperCaseBreak("HelloWorld", "! "); // "HELLO! WORLD"
535
+ */
536
+ export declare function toUpperCaseBreak(str?: string, join?: string): string;
537
+ /**
538
+ * Converts a string to Sentence case (first word capitalized, rest lowercase) with customizable word separators.
539
+ *
540
+ * This function breaks a string into words, capitalizes the first word, converts remaining
541
+ * words to lowercase, and then joins them using a custom separator (or space by default).
542
+ *
543
+ * Unlike `toFirstCase()` which works on a single word, this function processes multi-word
544
+ * strings from various formats (camelCase, snake_case, etc.) and gives control over how
545
+ * the words are joined back together.
546
+ *
547
+ * @param {string} [str] - The input string to convert
548
+ * @param {string} [join] - Optional separator to join words (defaults to space)
549
+ * @returns {string} - The formatted string with first word capitalized and custom separators,
550
+ * or empty string if input is falsy
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * // With default space separator
555
+ * toFirstCaseBreak("helloWorld"); // "Hello world"
556
+ * toFirstCaseBreak("SYSTEM_ERROR"); // "System error"
557
+ * toFirstCaseBreak("api-request-log"); // "Api request log"
558
+ *
559
+ * // With custom separators
560
+ * toFirstCaseBreak("hello_world", "-"); // "Hello-world"
561
+ * toFirstCaseBreak("userAuthConfig", "."); // "User.auth.config"
562
+ * toFirstCaseBreak("GET_USER_DATA", "/"); // "Get/user/data"
563
+ * ```
564
+ *
565
+ * @see {@link toFirstCase} For capitalizing a single word
566
+ * @see {@link toTitleCase} For capitalizing the first letter of every word
567
+ * @see {@link breakToWords} The underlying function used to split input into words
568
+ */
569
+ export declare function toFirstCaseBreak(str?: string, join?: string): string;
570
+ /**
571
+ * Convert a string to title case (Capitalize first letter of each word).
572
+ * @param {string} [str] String to convert to title case.
573
+ * @returns {string} String in title case.
574
+ *
575
+ * @example
576
+ * ```TypeScript
577
+ * toTitleCase("hello world"); // "Hello World"
578
+ * ```
579
+ */
580
+ export declare function toTitleCase(str?: string): string;
581
+ /**
582
+ * Convert a string to camel case.
583
+ * @param {string} [str] String to convert to camel case.
584
+ * @returns {string} String in camel case.
585
+ *
586
+ * @example
587
+ * ```TypeScript
588
+ * toCamelCase("hello world"); // "helloWorld"
589
+ * ```
590
+ */
591
+ export declare function toCamelCase(str?: string): string;
592
+ /**
593
+ * Convert a string to pascal case.
594
+ * @param {string} [str] String to convert to pascal case.
595
+ * @returns {string} String in pascal case.
596
+ *
597
+ * @example
598
+ * ```TypeScript
599
+ * toPascalCase("hello world"); // "HelloWorld"
600
+ * ```
601
+ */
602
+ export declare function toPascalCase(str?: string): string;
603
+ /**
604
+ * Convert a string to sentence case. (Capitalize first letter of every sentence).
605
+ * @param {string} [str] String to convert to sentence case.
606
+ * @returns {string} String in sentence case.
607
+ *
608
+ * @example
609
+ * ```TypeScript
610
+ * toSentenceCase("hello world. how are you?"); // "Hello world. How are you?"
611
+ * ```
612
+ */
613
+ export declare function toSentenceCase(str: string): string;
614
+ /**
615
+ * Converts a string to snake_case format.
616
+ *
617
+ * This function transforms a string from any common case format (camel, pascal, kebab, etc.)
618
+ * into snake_case, where words are lowercase and separated by underscores.
619
+ *
620
+ * When the optional `caps` parameter is set to true, the result will be UPPER_SNAKE_CASE
621
+ * (also known as SCREAMING_SNAKE_CASE or CONSTANT_CASE).
622
+ *
623
+ * @param {string} [str] - The input string to convert
624
+ * @param {boolean} [caps=false] - When true, converts to UPPER_SNAKE_CASE
625
+ * @returns {string} - The converted snake_case string, or empty string if input is falsy
626
+ *
627
+ * @example
628
+ * ```typescript
629
+ * // From various formats to snake_case
630
+ * toSnakeCase("hello world"); // "hello_world"
631
+ * toSnakeCase("HelloWorld"); // "hello_world"
632
+ * toSnakeCase("hello-world"); // "hello_world"
633
+ * toSnakeCase("HELLO WORLD"); // "hello_world"
634
+ *
635
+ * // To UPPER_SNAKE_CASE (CONSTANT_CASE)
636
+ * toSnakeCase("hello world", true); // "HELLO_WORLD"
637
+ * toSnakeCase("helloWorld", true); // "HELLO_WORLD"
638
+ * ```
639
+ *
640
+ * @remarks
641
+ * This function first splits the string into words using `breakToWords()`,
642
+ * then joins them with underscores, applying the requested case transformation.
643
+ */
644
+ export declare function toSnakeCase(str?: string, caps?: boolean): string;
645
+ /**
646
+ * Convert a string to kebab case.
647
+ * @param {string} [str] String to convert to kebab case.
648
+ * @param {boolean} [caps] Whether to convert to upper case.
649
+ * @returns {string} String in kebab case.
650
+ *
651
+ * @example
652
+ * ```TypeScript
653
+ * toKebabCase("hello world"); // "hello-world"
654
+ * ```
655
+ *
656
+ * @example
657
+ * ```TypeScript
658
+ * toKebabCase("hello world", true); // "HELLO-WORLD"
659
+ * ```
660
+ */
661
+ export declare function toKebabCase(str?: string, caps?: boolean): string;
662
+ /**
663
+ * Converts a string to a number.
664
+ * @param {number|string} str String to convert to a number.
665
+ * @returns {number|undefined} Number or undefined.
666
+ *
667
+ * @example
668
+ * ```TypeScript
669
+ * toNumber("123"); // 123
670
+ * ```
671
+ */
672
+ export declare function toNumber(str: number | string): number | undefined;
673
+ /**
674
+ * Remove HTML tags from a string and return plain text.
675
+ * @param {string} str String to remove HTML tags from.
676
+ * @returns {string} Plain text.
677
+ *
678
+ * @example
679
+ * ```TypeScript
680
+ * htmlToText("<h1>Hello World</h1>"); // "Hello World"
681
+ * ```
682
+ */
683
+ export declare function htmlToText(str: string): string;
684
+ /**
685
+ * Converts a singular English word to its plural form.
686
+ *
687
+ * This function applies common English pluralization rules to transform
688
+ * singular words into their plural equivalents. It handles regular patterns
689
+ * as well as many irregular cases and special rules for different word endings.
690
+ *
691
+ * @param {string} str - The singular word to convert to plural form
692
+ * @returns {string} - The plural form of the word, or the original string if:
693
+ * - Input is empty/falsy
694
+ * - The word is already plural
695
+ *
696
+ * @example
697
+ * ```typescript
698
+ * // Regular plurals
699
+ * plural("cat"); // "cats"
700
+ * plural("dog"); // "dogs"
701
+ *
702
+ * // Words ending in -y
703
+ * plural("party"); // "parties"
704
+ * plural("day"); // "days"
705
+ *
706
+ * // Words ending in -f or -fe
707
+ * plural("wolf"); // "wolves"
708
+ * plural("knife"); // "knives"
709
+ *
710
+ * // Words ending in -o
711
+ * plural("potato"); // "potatoes"
712
+ * plural("photo"); // "photos"
713
+ *
714
+ * // Irregular plurals
715
+ * plural("child"); // "children"
716
+ * plural("man"); // "men"
717
+ * plural("foot"); // "feet"
718
+ *
719
+ * // Latin/Greek words
720
+ * plural("cactus"); // "cacti"
721
+ * plural("analysis"); // "analyses"
722
+ * ```
723
+ *
724
+ * @remarks
725
+ * - This function is designed for English language words only
726
+ * - It pairs well with the `singular()` function for round-trip conversion
727
+ */
728
+ export declare function plural(str: string): string;
729
+ /**
730
+ * Truncates a string to a specified length and adds an ellipsis if needed.
731
+ *
732
+ * @param {string} str - The string to truncate
733
+ * @param {number} length - Maximum length of the truncated string (excluding ellipsis)
734
+ * @param {string} [ellipsis="..."] - The ellipsis to add to truncated strings
735
+ * @returns {string} - The truncated string with ellipsis if needed
736
+ *
737
+ * @example
738
+ * ```typescript
739
+ * truncate("This is a long sentence", 10); // "This is a..."
740
+ * truncate("Short", 10); // "Short"
741
+ * truncate("Custom ellipsis", 6, " [more]"); // "Custom [more]"
742
+ * ```
743
+ */
744
+ export declare function truncate(str: string, length: number, ellipsis?: string): string;
745
+ /**
746
+ * Pads a string to a specified length with a specified character.
747
+ *
748
+ * @param {string} str - The string to pad
749
+ * @param {number} length - The target length of the resulting string
750
+ * @param {string} [char=" "] - The character to pad with (defaults to space)
751
+ * @param {boolean} [padEnd=true] - Whether to pad at the end (true) or beginning (false)
752
+ * @returns {string} - The padded string
753
+ *
754
+ * @example
755
+ * ```typescript
756
+ * padString("Hello", 10); // "Hello "
757
+ * padString("Hello", 10, "*"); // "Hello*****"
758
+ * padString("Hello", 10, "0", false); // "00000Hello"
759
+ * ```
760
+ */
761
+ export declare function padString(str: string, length: number, char?: string, padEnd?: boolean): string;
762
+ /**
763
+ * Escapes special characters in a string for use in regular expressions.
764
+ *
765
+ * @param {string} str - The string to escape
766
+ * @returns {string} - The escaped string safe for use in RegExp
767
+ *
768
+ * @example
769
+ * ```typescript
770
+ * escapeRegExp("hello.world*"); // "hello\.world\*"
771
+ *
772
+ * // Usage in RegExp:
773
+ * const userInput = "hello.world*";
774
+ * const regex = new RegExp(escapeRegExp(userInput));
775
+ * ```
776
+ */
777
+ export declare function escapeRegExp(str: string): string;
778
+ /**
779
+ * Capitalizes each word in a string according to title case rules.
780
+ *
781
+ * This function implements proper title case rules, where:
782
+ * - The first and last words are always capitalized
783
+ * - All other major words are capitalized
784
+ * - Minor words (articles, conjunctions, short prepositions) are not capitalized
785
+ * unless they are the first or last word
786
+ *
787
+ * @param {string} str - The string to convert to title case
788
+ * @returns {string} - The string in proper title case format
789
+ *
790
+ * @example
791
+ * ```typescript
792
+ * toProperTitleCase("the quick brown fox jumps over the lazy dog");
793
+ * // "The Quick Brown Fox Jumps over the Lazy Dog"
794
+ *
795
+ * toProperTitleCase("a tale of two cities");
796
+ * // "A Tale of Two Cities"
797
+ * ```
798
+ */
799
+ export declare function toProperTitleCase(str: string): string;
800
+ /**
801
+ * Formats a string by replacing indexed placeholders with provided values.
802
+ *
803
+ * This implementation uses {n} syntax for indexed placeholders where n is the
804
+ * position of the value in the arguments list (0-based).
805
+ *
806
+ * @param {string} template - The template string with {0}, {1}, etc. placeholders
807
+ * @param {...(string|number|boolean|null|undefined)} values - Values to insert into the template
808
+ * @returns {string} - The formatted string
809
+ *
810
+ * @example
811
+ * ```typescript
812
+ * format("Hello, {0}!", "World"); // "Hello, World!"
813
+ *
814
+ * format("User {0} has {1} points", "John", 100);
815
+ * // "User John has 100 points"
816
+ * ```
817
+ */
818
+ export declare function format(template: string, ...values: (string | number | boolean | null | undefined)[]): string;
819
+ /**
820
+ * Formats a string by replacing named placeholders with values from an object.
821
+ *
822
+ * This implementation uses {name} syntax for named placeholders where 'name'
823
+ * corresponds to a property in the provided values object.
824
+ *
825
+ * @param {string} template - The template string with {propertyName} placeholders
826
+ * @param {Record<string, string|number|boolean|null|undefined>} values - Object with values to insert
827
+ * @returns {string} - The formatted string
828
+ *
829
+ * @example
830
+ * ```typescript
831
+ * // Named placeholders with object
832
+ * format("Hello, {name}! You have {count} messages.", { name: "Alice", count: 5 });
833
+ * // "Hello, Alice! You have 5 messages."
834
+ * ```
835
+ */
836
+ export declare function format(template: string, values: Record<string, string | number | boolean | null | undefined>): string;
837
+ /**
838
+ * Counts the occurrences of a substring within a string.
839
+ *
840
+ * @param {string} str - The string to search within
841
+ * @param {string} searchValue - The substring to search for
842
+ * @param {boolean} [caseSensitive=true] - Whether the search should be case-sensitive
843
+ * @returns {number} - The number of occurrences
844
+ *
845
+ * @example
846
+ * ```typescript
847
+ * countOccurrences("hello hello world", "hello"); // 2
848
+ * countOccurrences("Hello hello", "hello", false); // 2
849
+ * countOccurrences("Hello hello", "hello", true); // 1
850
+ * ```
851
+ */
852
+ export declare function countOccurrences(str: string, searchValue: string, caseSensitive?: boolean): number;
853
+ /**
854
+ * Reverses a string.
855
+ *
856
+ * @param {string} str - The string to reverse
857
+ * @returns {string} - The reversed string
858
+ *
859
+ * @example
860
+ * ```typescript
861
+ * reverse("hello"); // "olleh"
862
+ * reverse("12345"); // "54321"
863
+ * ```
864
+ */
865
+ export declare function reverse(str: string): string;
866
+ /**
867
+ * Checks if a string contains only alphanumeric characters.
868
+ *
869
+ * @param {string} str - The string to check
870
+ * @returns {boolean} - True if the string contains only alphanumeric characters
871
+ *
872
+ * @example
873
+ * ```typescript
874
+ * isAlphanumeric("abc123"); // true
875
+ * isAlphanumeric("abc-123"); // false
876
+ * ```
877
+ */
878
+ export declare function isAlphanumeric(str: string): boolean;
879
+ /**
880
+ * Removes all whitespace from a string.
881
+ *
882
+ * @param {string} str - The string to process
883
+ * @returns {string} - The string with all whitespace removed
884
+ *
885
+ * @example
886
+ * ```typescript
887
+ * removeWhitespace("hello world"); // "helloworld"
888
+ * removeWhitespace(" spaces tabs "); // "spacestabs"
889
+ * ```
890
+ */
891
+ export declare function removeWhitespace(str: string): string;
892
+ /**
893
+ * Converts plural English words to their singular form.
894
+ *
895
+ * This function applies a series of linguistic rules and exceptions to transform
896
+ * plural English words into their singular equivalents. It handles irregular plurals
897
+ * (e.g., "children" → "child"), common suffix patterns (e.g., "parties" → "party"),
898
+ * and Latin-derived words (e.g., "cacti" → "cactus").
899
+ *
900
+ * The function applies rules in priority order, from most specific to most general,
901
+ * to ensure correct handling of special cases.
902
+ *
903
+ * @param {string} str - The plural word to convert to singular form
904
+ * @returns {string} - The singular form of the word, or the original string if:
905
+ * - Input is empty/falsy
906
+ * - No singular form is recognized
907
+ * - The word is already singular
908
+ *
909
+ * @example
910
+ * ```typescript
911
+ * // Irregular plurals
912
+ * singular("children"); // "child"
913
+ * singular("men"); // "man"
914
+ * singular("feet"); // "foot"
915
+ *
916
+ * // Common patterns
917
+ * singular("cats"); // "cat"
918
+ * singular("boxes"); // "box"
919
+ * singular("parties"); // "party"
920
+ * singular("wolves"); // "wolf"
921
+ *
922
+ * // Latin-derived words
923
+ * singular("cacti"); // "cactus"
924
+ * singular("phenomena"); // "phenomenon"
925
+ * ```
926
+ *
927
+ * @remarks
928
+ * - This function is designed for English language words only
929
+ * - It handles many common cases but isn't exhaustive for all English plurals
930
+ * - Words that are identical in singular and plural form (e.g., "sheep") are returned unchanged
931
+ */
932
+ export declare function singular(str: string): string;