bitaboom 1.3.0 → 1.4.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/README.md +224 -57
- package/dist/index.d.ts +150 -78
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/package.json +23 -26
- package/dist/main.js +0 -502
- package/dist/main.js.map +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
# Bitaboom - A String Utilities Library
|
|
15
15
|
|
|
16
|
-
Bitaboom is a NodeJS string utility library written in TypeScript, designed to provide a collection of helpful string manipulation functions. It supports the latest ESNext features and is tested using
|
|
16
|
+
Bitaboom is a NodeJS string utility library written in TypeScript, designed to provide a collection of helpful string manipulation functions. It supports the latest ESNext features and is tested using Bun's test runner.
|
|
17
17
|
|
|
18
18
|
## Demo
|
|
19
19
|
|
|
@@ -29,6 +29,8 @@ npm install bitaboom
|
|
|
29
29
|
yarn add bitaboom
|
|
30
30
|
# or
|
|
31
31
|
pnpm i bitaboom
|
|
32
|
+
# or
|
|
33
|
+
bun add bitaboom
|
|
32
34
|
```
|
|
33
35
|
|
|
34
36
|
## Usage
|
|
@@ -52,7 +54,7 @@ console.log(result);
|
|
|
52
54
|
|
|
53
55
|
Adds spaces before and after punctuation marks except in specific cases like quoted text.
|
|
54
56
|
|
|
55
|
-
#### Example
|
|
57
|
+
#### Example
|
|
56
58
|
|
|
57
59
|
```javascript
|
|
58
60
|
addSpaceBeforeAndAfterPunctuation('Text,word');
|
|
@@ -65,7 +67,7 @@ addSpaceBeforeAndAfterPunctuation('Text,word');
|
|
|
65
67
|
|
|
66
68
|
Inserts spaces between Arabic text and numbers.
|
|
67
69
|
|
|
68
|
-
#### Example
|
|
70
|
+
#### Example
|
|
69
71
|
|
|
70
72
|
```javascript
|
|
71
73
|
addSpaceBetweenArabicTextAndNumbers('الآية37');
|
|
@@ -78,11 +80,11 @@ addSpaceBetweenArabicTextAndNumbers('الآية37');
|
|
|
78
80
|
|
|
79
81
|
Turns regular double quotes into smart quotes and fixes any incorrect starting quotes.
|
|
80
82
|
|
|
81
|
-
#### Example
|
|
83
|
+
#### Example
|
|
82
84
|
|
|
83
85
|
```javascript
|
|
84
86
|
applySmartQuotes('The "quick brown" fox');
|
|
85
|
-
// Output: 'The
|
|
87
|
+
// Output: 'The "quick brown" fox'
|
|
86
88
|
```
|
|
87
89
|
|
|
88
90
|
---
|
|
@@ -91,7 +93,7 @@ applySmartQuotes('The "quick brown" fox');
|
|
|
91
93
|
|
|
92
94
|
Removes extreme Arabic underscores (ـ) from the beginning or end of lines. It does not affect Hijri dates or certain Arabic terms.
|
|
93
95
|
|
|
94
|
-
#### Example
|
|
96
|
+
#### Example
|
|
95
97
|
|
|
96
98
|
```javascript
|
|
97
99
|
cleanExtremeArabicUnderscores('ـThis is a textـ');
|
|
@@ -104,7 +106,7 @@ cleanExtremeArabicUnderscores('ـThis is a textـ');
|
|
|
104
106
|
|
|
105
107
|
Cleans unnecessary spaces and punctuation from text.
|
|
106
108
|
|
|
107
|
-
#### Example
|
|
109
|
+
#### Example
|
|
108
110
|
|
|
109
111
|
```javascript
|
|
110
112
|
cleanJunkFromText('Some text !@#\nAnother line.');
|
|
@@ -115,7 +117,7 @@ cleanJunkFromText('Some text !@#\nAnother line.');
|
|
|
115
117
|
|
|
116
118
|
Replaces literal new line characters (`\n`) with actual line breaks.
|
|
117
119
|
|
|
118
|
-
#### Example
|
|
120
|
+
#### Example
|
|
119
121
|
|
|
120
122
|
```javascript
|
|
121
123
|
cleanLiteralNewLines('A\nB');
|
|
@@ -128,7 +130,7 @@ cleanLiteralNewLines('A\nB');
|
|
|
128
130
|
|
|
129
131
|
Removes trailing spaces from each line in a multiline string.
|
|
130
132
|
|
|
131
|
-
#### Example
|
|
133
|
+
#### Example
|
|
132
134
|
|
|
133
135
|
```javascript
|
|
134
136
|
cleanMultilines(' This is a line \nAnother line ');
|
|
@@ -141,7 +143,7 @@ cleanMultilines(' This is a line \nAnother line ');
|
|
|
141
143
|
|
|
142
144
|
Removes various symbols, part references, and numerical markers from the text.
|
|
143
145
|
|
|
144
|
-
#### Example
|
|
146
|
+
#### Example
|
|
145
147
|
|
|
146
148
|
```javascript
|
|
147
149
|
cleanSymbolsAndPartReferences('(1) (2/3)');
|
|
@@ -154,7 +156,7 @@ cleanSymbolsAndPartReferences('(1) (2/3)');
|
|
|
154
156
|
|
|
155
157
|
Removes trailing page numbers formatted as `-[46]-` from the text.
|
|
156
158
|
|
|
157
|
-
#### Example
|
|
159
|
+
#### Example
|
|
158
160
|
|
|
159
161
|
```javascript
|
|
160
162
|
cleanTrailingPageNumbers('This is some -[46]- text');
|
|
@@ -167,7 +169,7 @@ cleanTrailingPageNumbers('This is some -[46]- text');
|
|
|
167
169
|
|
|
168
170
|
Converts Urdu symbols like 'ھ' and 'ی' to their Arabic equivalents 'ه' and 'ي'.
|
|
169
171
|
|
|
170
|
-
#### Example
|
|
172
|
+
#### Example
|
|
171
173
|
|
|
172
174
|
```javascript
|
|
173
175
|
convertUrduSymbolsToArabic('ھذا');
|
|
@@ -180,7 +182,7 @@ convertUrduSymbolsToArabic('ھذا');
|
|
|
180
182
|
|
|
181
183
|
Ensures there is exactly one space before parentheses that follow non-whitespace characters. Normalizes multiple spaces to a single space.
|
|
182
184
|
|
|
183
|
-
#### Example
|
|
185
|
+
#### Example
|
|
184
186
|
|
|
185
187
|
```javascript
|
|
186
188
|
ensureSpaceBeforeBrackets('text(note)');
|
|
@@ -192,22 +194,86 @@ ensureSpaceBeforeBrackets('text (note)');
|
|
|
192
194
|
|
|
193
195
|
---
|
|
194
196
|
|
|
197
|
+
### `ensureSpaceBeforeQuotes`
|
|
198
|
+
|
|
199
|
+
Ensures at most 1 space exists before any word before Arabic quotation marks. Adds a space if there isn't one, or reduces multiple spaces to one.
|
|
200
|
+
|
|
201
|
+
#### Example
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
ensureSpaceBeforeQuotes('text«quote»');
|
|
205
|
+
// Output: 'text «quote»'
|
|
206
|
+
|
|
207
|
+
ensureSpaceBeforeQuotes('text «quote»');
|
|
208
|
+
// Output: 'text «quote»'
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
195
213
|
### `extractInitials`
|
|
196
214
|
|
|
197
215
|
Extracts initials from the input string, typically for names or titles.
|
|
198
216
|
|
|
199
|
-
#### Example
|
|
217
|
+
#### Example
|
|
200
218
|
|
|
201
219
|
```javascript
|
|
202
220
|
extractInitials('Nayl al-Awtar');
|
|
203
221
|
// Output: 'NA'
|
|
204
222
|
```
|
|
205
223
|
|
|
224
|
+
### `fixBracketTypos`
|
|
225
|
+
|
|
226
|
+
Fixes common bracket and quotation mark typos in text. Corrects malformed patterns like "(«", "»)", and misplaced digits in brackets.
|
|
227
|
+
|
|
228
|
+
#### Example
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
fixBracketTypos('(«text»)');
|
|
232
|
+
// Output: '«text»'
|
|
233
|
+
|
|
234
|
+
fixBracketTypos(')5)');
|
|
235
|
+
// Output: '(5)'
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
### `fixCurlyBraces`
|
|
241
|
+
|
|
242
|
+
Fixes mismatched curly braces by converting incorrect bracket/brace combinations to proper curly braces { }.
|
|
243
|
+
|
|
244
|
+
#### Example
|
|
245
|
+
|
|
246
|
+
```javascript
|
|
247
|
+
fixCurlyBraces('(content}');
|
|
248
|
+
// Output: '{content}'
|
|
249
|
+
|
|
250
|
+
fixCurlyBraces('{content)');
|
|
251
|
+
// Output: '{content}'
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
### `fixMismatchedQuotationMarks`
|
|
257
|
+
|
|
258
|
+
Fixes mismatched quotation marks in Arabic text by converting various incorrect bracket/quote combinations to proper Arabic quotation marks (« »).
|
|
259
|
+
|
|
260
|
+
#### Example
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
fixMismatchedQuotationMarks('«text)');
|
|
264
|
+
// Output: '«text»'
|
|
265
|
+
|
|
266
|
+
fixMismatchedQuotationMarks('(text»');
|
|
267
|
+
// Output: '«text»'
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
206
272
|
### `fixTrailingWow`
|
|
207
273
|
|
|
208
274
|
Corrects unnecessary trailing "و" in greetings or phrases.
|
|
209
275
|
|
|
210
|
-
#### Example
|
|
276
|
+
#### Example
|
|
211
277
|
|
|
212
278
|
```javascript
|
|
213
279
|
fixTrailingWow('السلام عليكم و رحمة');
|
|
@@ -216,11 +282,27 @@ fixTrailingWow('السلام عليكم و رحمة');
|
|
|
216
282
|
|
|
217
283
|
---
|
|
218
284
|
|
|
285
|
+
### `getArabicScore`
|
|
286
|
+
|
|
287
|
+
Calculates the proportion of Arabic characters in text relative to total non-whitespace characters.
|
|
288
|
+
|
|
289
|
+
#### Example
|
|
290
|
+
|
|
291
|
+
```javascript
|
|
292
|
+
getArabicScore('مرحبا hello');
|
|
293
|
+
// Output: 0.5 (5 Arabic chars out of 10 non-whitespace chars)
|
|
294
|
+
|
|
295
|
+
getArabicScore('مرحبا');
|
|
296
|
+
// Output: 1.0 (100% Arabic)
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
219
301
|
### `hasWordInSingleLine`
|
|
220
302
|
|
|
221
303
|
Checks if a line has any word by itself.
|
|
222
304
|
|
|
223
|
-
#### Example
|
|
305
|
+
#### Example
|
|
224
306
|
|
|
225
307
|
```javascript
|
|
226
308
|
hasWordInSingleLine('Abc efg\nhij\nklmn opq');
|
|
@@ -233,7 +315,7 @@ hasWordInSingleLine('Abc efg\nhij\nklmn opq');
|
|
|
233
315
|
|
|
234
316
|
Adds line breaks after punctuation marks such as periods, exclamation points, and question marks.
|
|
235
317
|
|
|
236
|
-
#### Example
|
|
318
|
+
#### Example
|
|
237
319
|
|
|
238
320
|
```javascript
|
|
239
321
|
insertLineBreaksAfterPunctuation('Text.');
|
|
@@ -243,11 +325,30 @@ insertLineBreaksAfterPunctuation('Text.');
|
|
|
243
325
|
|
|
244
326
|
---
|
|
245
327
|
|
|
328
|
+
### `isAllUppercase`
|
|
329
|
+
|
|
330
|
+
Detects if text is entirely in uppercase letters.
|
|
331
|
+
|
|
332
|
+
#### Example
|
|
333
|
+
|
|
334
|
+
```javascript
|
|
335
|
+
isAllUppercase('HELLO WORLD');
|
|
336
|
+
// Output: true
|
|
337
|
+
|
|
338
|
+
isAllUppercase('Hello World');
|
|
339
|
+
// Output: false
|
|
340
|
+
|
|
341
|
+
isAllUppercase('123');
|
|
342
|
+
// Output: false (no letters)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
246
347
|
### `isBalanced`
|
|
247
348
|
|
|
248
349
|
Checks if both quotes and brackets are balanced in a string. A string is considered balanced when all double quotes have matching pairs (even count) and all brackets (parentheses, square brackets, curly braces) are properly matched and nested.
|
|
249
350
|
|
|
250
|
-
#### Example
|
|
351
|
+
#### Example
|
|
251
352
|
|
|
252
353
|
```javascript
|
|
253
354
|
isBalanced('He said "Hello (world)!"');
|
|
@@ -263,7 +364,7 @@ isBalanced('He said "Hello (world!"');
|
|
|
263
364
|
|
|
264
365
|
Checks if a given string resembles a JSON object with numeric or quoted keys and values that are single or double quoted. Useful for detecting malformed JSON-like structures that can be fixed.
|
|
265
366
|
|
|
266
|
-
#### Example
|
|
367
|
+
#### Example
|
|
267
368
|
|
|
268
369
|
```javascript
|
|
269
370
|
isJsonStructureValid("{10: 'abc', 'key': 'value'}");
|
|
@@ -276,7 +377,7 @@ isJsonStructureValid("{10: 'abc', 'key': 'value'}");
|
|
|
276
377
|
|
|
277
378
|
Checks if the input string consists only of punctuation characters.
|
|
278
379
|
|
|
279
|
-
#### Example
|
|
380
|
+
#### Example
|
|
280
381
|
|
|
281
382
|
```javascript
|
|
282
383
|
isOnlyPunctuation('!?');
|
|
@@ -285,11 +386,26 @@ isOnlyPunctuation('!?');
|
|
|
285
386
|
|
|
286
387
|
---
|
|
287
388
|
|
|
389
|
+
### `makeDiacriticInsensitive`
|
|
390
|
+
|
|
391
|
+
Creates a diacritic-insensitive regex pattern for Arabic text matching. Normalizes text, handles character equivalences (ا/آ/أ/إ, ة/ه, ى/ي), and makes each character tolerant of Arabic diacritics (Tashkeel/Harakat).
|
|
392
|
+
|
|
393
|
+
#### Example
|
|
394
|
+
|
|
395
|
+
```javascript
|
|
396
|
+
const pattern = makeDiacriticInsensitive('محمد');
|
|
397
|
+
const regex = new RegExp(pattern, 'gi');
|
|
398
|
+
regex.test('مُحَمَّد'); // true
|
|
399
|
+
regex.test('محمد'); // true
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
288
404
|
### `normalizeAlifVariants`
|
|
289
405
|
|
|
290
406
|
Simplifies all forms of 'alif' (أ, إ, and آ) to the basic 'ا'.
|
|
291
407
|
|
|
292
|
-
#### Example
|
|
408
|
+
#### Example
|
|
293
409
|
|
|
294
410
|
```javascript
|
|
295
411
|
normalizeAlifVariants('أنا إلى الآفاق');
|
|
@@ -298,12 +414,12 @@ normalizeAlifVariants('أنا إلى الآفاق');
|
|
|
298
414
|
|
|
299
415
|
### `normalizeApostrophes`
|
|
300
416
|
|
|
301
|
-
Replaces various apostrophe characters like ‛,
|
|
417
|
+
Replaces various apostrophe characters like ‛, ', and ' with the standard apostrophe (').
|
|
302
418
|
|
|
303
|
-
#### Example
|
|
419
|
+
#### Example
|
|
304
420
|
|
|
305
421
|
```javascript
|
|
306
|
-
normalizeApostrophes('‛ulama
|
|
422
|
+
normalizeApostrophes('‛ulama' al-su'');
|
|
307
423
|
// Output: "'ulama' al-su'"
|
|
308
424
|
```
|
|
309
425
|
|
|
@@ -311,9 +427,9 @@ normalizeApostrophes('‛ulama’ al-su‘');
|
|
|
311
427
|
|
|
312
428
|
### `normalizeArabicPrefixesToAl`
|
|
313
429
|
|
|
314
|
-
Replaces common Arabic prefixes like 'Al-', 'Ar-', 'Ash-', etc., with 'al-' in the text.
|
|
430
|
+
Replaces common Arabic prefixes like 'Al-', 'Ar-', 'Ash-', etc., with 'al-' in the text. Handles variations and lam-assimilation patterns (before sun letters), and avoids changes where assimilation rules do not apply.
|
|
315
431
|
|
|
316
|
-
#### Example
|
|
432
|
+
#### Example
|
|
317
433
|
|
|
318
434
|
```javascript
|
|
319
435
|
normalizeArabicPrefixesToAl('Ash-Shafiee');
|
|
@@ -326,7 +442,7 @@ normalizeArabicPrefixesToAl('Ash-Shafiee');
|
|
|
326
442
|
|
|
327
443
|
Removes double occurrences of Arabic apostrophes such as ʿʿ or ʾʾ.
|
|
328
444
|
|
|
329
|
-
#### Example
|
|
445
|
+
#### Example
|
|
330
446
|
|
|
331
447
|
```javascript
|
|
332
448
|
normalizeDoubleApostrophes('ʿulamāʾʾ');
|
|
@@ -339,7 +455,7 @@ normalizeDoubleApostrophes('ʿulamāʾʾ');
|
|
|
339
455
|
|
|
340
456
|
Converts a string that resembles JSON but has numeric keys and single-quoted values into valid JSON format. The function replaces numeric keys with quoted numeric keys and ensures all values are double-quoted, as required by JSON.
|
|
341
457
|
|
|
342
|
-
#### Example
|
|
458
|
+
#### Example
|
|
343
459
|
|
|
344
460
|
```javascript
|
|
345
461
|
normalizeJsonSyntax("{10: 'abc', 20: 'def'}");
|
|
@@ -352,7 +468,7 @@ normalizeJsonSyntax("{10: 'abc', 20: 'def'}");
|
|
|
352
468
|
|
|
353
469
|
Simplifies English transliterations by removing diacritics, apostrophes, and common prefixes.
|
|
354
470
|
|
|
355
|
-
#### Example
|
|
471
|
+
#### Example
|
|
356
472
|
|
|
357
473
|
```javascript
|
|
358
474
|
normalizeTransliteratedEnglish('Al-Jadwāl');
|
|
@@ -365,7 +481,7 @@ normalizeTransliteratedEnglish('Al-Jadwāl');
|
|
|
365
481
|
|
|
366
482
|
Normalizes the text by removing diacritics, apostrophes, and dashes.
|
|
367
483
|
|
|
368
|
-
#### Example
|
|
484
|
+
#### Example
|
|
369
485
|
|
|
370
486
|
```javascript
|
|
371
487
|
normalize('Al-Jadwāl');
|
|
@@ -374,11 +490,30 @@ normalize('Al-Jadwāl');
|
|
|
374
490
|
|
|
375
491
|
---
|
|
376
492
|
|
|
493
|
+
### `parsePageRanges`
|
|
494
|
+
|
|
495
|
+
Parses page input string into array of page numbers, supporting ranges and lists.
|
|
496
|
+
|
|
497
|
+
#### Example
|
|
498
|
+
|
|
499
|
+
```javascript
|
|
500
|
+
parsePageRanges('1-5');
|
|
501
|
+
// Output: [1, 2, 3, 4, 5]
|
|
502
|
+
|
|
503
|
+
parsePageRanges('1,3,5');
|
|
504
|
+
// Output: [1, 3, 5]
|
|
505
|
+
|
|
506
|
+
parsePageRanges('10-8');
|
|
507
|
+
// Throws Error: 'Start page cannot be greater than end page'
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
---
|
|
511
|
+
|
|
377
512
|
### `removeArabicPrefixes`
|
|
378
513
|
|
|
379
514
|
Strips common Arabic prefixes like 'al-', 'bi-', 'fī', 'wa-', etc., from the beginning of words.
|
|
380
515
|
|
|
381
|
-
#### Example
|
|
516
|
+
#### Example
|
|
382
517
|
|
|
383
518
|
```javascript
|
|
384
519
|
removeArabicPrefixes('al-Bukhari');
|
|
@@ -391,11 +526,27 @@ removeArabicPrefixes('al-Bukhari');
|
|
|
391
526
|
|
|
392
527
|
Removes death year references like "(d. 390H)" and "[d. 100h]" from the text.
|
|
393
528
|
|
|
394
|
-
#### Example
|
|
529
|
+
#### Example
|
|
530
|
+
|
|
531
|
+
```javascript
|
|
532
|
+
removeDeathYear('Sufyān ibn 'Uyaynah (d. 198h)');
|
|
533
|
+
// Output: 'Sufyān ibn 'Uyaynah'
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
### `removeMarkdownFormatting`
|
|
539
|
+
|
|
540
|
+
Removes common Markdown formatting syntax from text.
|
|
541
|
+
|
|
542
|
+
#### Example
|
|
395
543
|
|
|
396
544
|
```javascript
|
|
397
|
-
|
|
398
|
-
// Output: '
|
|
545
|
+
removeMarkdownFormatting('**Bold** and *italic* text');
|
|
546
|
+
// Output: 'Bold and italic text'
|
|
547
|
+
|
|
548
|
+
removeMarkdownFormatting('# Header\n- List item');
|
|
549
|
+
// Output: 'Header\nList item'
|
|
399
550
|
```
|
|
400
551
|
|
|
401
552
|
---
|
|
@@ -404,7 +555,7 @@ removeDeathYear('Sufyān ibn ‘Uyaynah (d. 198h)');
|
|
|
404
555
|
|
|
405
556
|
Removes single-digit numbers and dashes from Arabic text but preserves numbers used as indexes.
|
|
406
557
|
|
|
407
|
-
#### Example
|
|
558
|
+
#### Example
|
|
408
559
|
|
|
409
560
|
```javascript
|
|
410
561
|
removeNonIndexSignatures('الورقه 3 المصدر');
|
|
@@ -417,7 +568,7 @@ removeNonIndexSignatures('الورقه 3 المصدر');
|
|
|
417
568
|
|
|
418
569
|
Removes numeric digits and dashes from the text.
|
|
419
570
|
|
|
420
|
-
#### Example
|
|
571
|
+
#### Example
|
|
421
572
|
|
|
422
573
|
```javascript
|
|
423
574
|
removeNumbersAndDashes('ABC 123-Xyz');
|
|
@@ -430,7 +581,7 @@ removeNumbersAndDashes('ABC 123-Xyz');
|
|
|
430
581
|
|
|
431
582
|
Removes redundant punctuation marks that follow Arabic question marks or exclamation marks. This function cleans up text by removing periods (.) or Arabic commas (،) that immediately follow Arabic question marks (؟) or exclamation marks (!).
|
|
432
583
|
|
|
433
|
-
#### Example
|
|
584
|
+
#### Example
|
|
434
585
|
|
|
435
586
|
```javascript
|
|
436
587
|
removeRedundantPunctuation('كيف حالك؟.');
|
|
@@ -446,7 +597,7 @@ removeRedundantPunctuation('ممتاز!،');
|
|
|
446
597
|
|
|
447
598
|
Removes single digit references like (1), «2», [3] from the text.
|
|
448
599
|
|
|
449
|
-
#### Example
|
|
600
|
+
#### Example
|
|
450
601
|
|
|
451
602
|
```javascript
|
|
452
603
|
removeSingleDigitReferences('Ref (1), Ref «2», Ref [3]');
|
|
@@ -459,7 +610,7 @@ removeSingleDigitReferences('Ref (1), Ref «2», Ref [3]');
|
|
|
459
610
|
|
|
460
611
|
Removes Arabic letters or Arabic-Indic numerals enclosed in square brackets or parentheses.
|
|
461
612
|
|
|
462
|
-
#### Example
|
|
613
|
+
#### Example
|
|
463
614
|
|
|
464
615
|
```javascript
|
|
465
616
|
removeSingularCodes('[س]');
|
|
@@ -472,7 +623,7 @@ removeSingularCodes('[س]');
|
|
|
472
623
|
|
|
473
624
|
Removes solitary Arabic letters unless they are 'ha' used in Hijri years.
|
|
474
625
|
|
|
475
|
-
#### Example
|
|
626
|
+
#### Example
|
|
476
627
|
|
|
477
628
|
```javascript
|
|
478
629
|
removeSolitaryArabicLetters('ب ا الكلمات ت');
|
|
@@ -485,7 +636,7 @@ removeSolitaryArabicLetters('ب ا الكلمات ت');
|
|
|
485
636
|
|
|
486
637
|
Removes tatweel characters while preserving dates references and numbered list items. Example: "1435/3/29 هـ" remains as "1435/3/29 هـ" but "أبـــتِـــكَةُ" becomes "أبتِكَةُ". Also preserves tatweels in numbered list items like "3 ـ item".
|
|
487
638
|
|
|
488
|
-
#### Example
|
|
639
|
+
#### Example
|
|
489
640
|
|
|
490
641
|
```javascript
|
|
491
642
|
removeTatwil('أبـــتِـــكَةُ');
|
|
@@ -504,7 +655,7 @@ removeTatwil('3 ـ وشريط');
|
|
|
504
655
|
|
|
505
656
|
Removes URLs from the text.
|
|
506
657
|
|
|
507
|
-
#### Example
|
|
658
|
+
#### Example
|
|
508
659
|
|
|
509
660
|
```javascript
|
|
510
661
|
removeUrls('Visit https://example.com');
|
|
@@ -515,7 +666,7 @@ removeUrls('Visit https://example.com');
|
|
|
515
666
|
|
|
516
667
|
Replaces 'alif maqsurah' (ى) with 'ya' (ي).
|
|
517
668
|
|
|
518
|
-
#### Example
|
|
669
|
+
#### Example
|
|
519
670
|
|
|
520
671
|
```javascript
|
|
521
672
|
replaceAlifMaqsurah('رؤيى');
|
|
@@ -528,7 +679,7 @@ replaceAlifMaqsurah('رؤيى');
|
|
|
528
679
|
|
|
529
680
|
Replaces double parentheses with single arrow quotation marks. Converts `((text))` format to `«text»` format, handling optional spaces inside the brackets.
|
|
530
681
|
|
|
531
|
-
#### Example
|
|
682
|
+
#### Example
|
|
532
683
|
|
|
533
684
|
```javascript
|
|
534
685
|
replaceDoubleBracketsWithArrows('((text))');
|
|
@@ -544,7 +695,7 @@ replaceDoubleBracketsWithArrows('(( spaced text ))');
|
|
|
544
695
|
|
|
545
696
|
Replaces English punctuation marks (e.g., ? and ;) with their Arabic equivalents.
|
|
546
697
|
|
|
547
|
-
#### Example
|
|
698
|
+
#### Example
|
|
548
699
|
|
|
549
700
|
```javascript
|
|
550
701
|
replaceEnglishPunctuationWithArabic('This; and, that?');
|
|
@@ -557,7 +708,7 @@ replaceEnglishPunctuationWithArabic('This; and, that?');
|
|
|
557
708
|
|
|
558
709
|
Replaces consecutive line breaks and whitespace characters with a single space.
|
|
559
710
|
|
|
560
|
-
#### Example
|
|
711
|
+
#### Example
|
|
561
712
|
|
|
562
713
|
```javascript
|
|
563
714
|
replaceLineBreaksWithSpaces('a\nb');
|
|
@@ -570,7 +721,7 @@ replaceLineBreaksWithSpaces('a\nb');
|
|
|
570
721
|
|
|
571
722
|
Replaces common salutations like "sallahu alayhi wasallam" with "ﷺ". Handles variations like 'peace and blessings be upon him'.
|
|
572
723
|
|
|
573
|
-
#### Example
|
|
724
|
+
#### Example
|
|
574
725
|
|
|
575
726
|
```javascript
|
|
576
727
|
replaceSalutationsWithSymbol('Then Muḥammad (sallahu alayhi wasallam)');
|
|
@@ -583,7 +734,7 @@ replaceSalutationsWithSymbol('Then Muḥammad (sallahu alayhi wasallam)');
|
|
|
583
734
|
|
|
584
735
|
Replaces 'ta marbutah' (ة) with 'ha' (ه).
|
|
585
736
|
|
|
586
|
-
#### Example
|
|
737
|
+
#### Example
|
|
587
738
|
|
|
588
739
|
```javascript
|
|
589
740
|
replaceTaMarbutahWithHa('مدرسة');
|
|
@@ -596,7 +747,7 @@ replaceTaMarbutahWithHa('مدرسة');
|
|
|
596
747
|
|
|
597
748
|
Splits a string by spaces but keeps quoted substrings intact. Substrings enclosed in double quotes are treated as a single part.
|
|
598
749
|
|
|
599
|
-
#### Example
|
|
750
|
+
#### Example
|
|
600
751
|
|
|
601
752
|
```javascript
|
|
602
753
|
splitByQuotes('"This is" "a part of the" "string and"');
|
|
@@ -607,7 +758,7 @@ splitByQuotes('"This is" "a part of the" "string and"');
|
|
|
607
758
|
|
|
608
759
|
Removes all numeric digits from the text.
|
|
609
760
|
|
|
610
|
-
#### Example
|
|
761
|
+
#### Example
|
|
611
762
|
|
|
612
763
|
```javascript
|
|
613
764
|
stripAllDigits('abc123');
|
|
@@ -620,10 +771,10 @@ stripAllDigits('abc123');
|
|
|
620
771
|
|
|
621
772
|
Removes Arabic diacritics (tashkeel) and the elongation character (ـ).
|
|
622
773
|
|
|
623
|
-
#### Example
|
|
774
|
+
#### Example
|
|
624
775
|
|
|
625
776
|
```javascript
|
|
626
|
-
stripDiacritics('
|
|
777
|
+
stripDiacritics('مُحَمَّدٌ');
|
|
627
778
|
// Output: 'محمد'
|
|
628
779
|
```
|
|
629
780
|
|
|
@@ -633,7 +784,7 @@ stripDiacritics('مُحَمَّدٌ');
|
|
|
633
784
|
|
|
634
785
|
Removes English letters and symbols from the text.
|
|
635
786
|
|
|
636
|
-
#### Example
|
|
787
|
+
#### Example
|
|
637
788
|
|
|
638
789
|
```javascript
|
|
639
790
|
stripEnglishCharactersAndSymbols('أحب & لنفسي');
|
|
@@ -646,7 +797,7 @@ stripEnglishCharactersAndSymbols('أحب & لنفسي');
|
|
|
646
797
|
|
|
647
798
|
Removes zero-width characters like ZWJ and other invisible characters.
|
|
648
799
|
|
|
649
|
-
#### Example
|
|
800
|
+
#### Example
|
|
650
801
|
|
|
651
802
|
```javascript
|
|
652
803
|
stripZeroWidthCharacters('يَخْلُوَ .');
|
|
@@ -655,11 +806,27 @@ stripZeroWidthCharacters('يَخْلُوَ .');
|
|
|
655
806
|
|
|
656
807
|
---
|
|
657
808
|
|
|
809
|
+
### `toTitleCase`
|
|
810
|
+
|
|
811
|
+
Converts a string to title case (first letter of each word capitalized).
|
|
812
|
+
|
|
813
|
+
#### Example
|
|
814
|
+
|
|
815
|
+
```javascript
|
|
816
|
+
toTitleCase('hello world');
|
|
817
|
+
// Output: 'Hello World'
|
|
818
|
+
|
|
819
|
+
toTitleCase('the quick brown fox');
|
|
820
|
+
// Output: 'The Quick Brown Fox'
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
---
|
|
824
|
+
|
|
658
825
|
### `truncate`
|
|
659
826
|
|
|
660
827
|
Truncates a string to a specified length, adding an ellipsis if truncated.
|
|
661
828
|
|
|
662
|
-
#### Example
|
|
829
|
+
#### Example
|
|
663
830
|
|
|
664
831
|
```javascript
|
|
665
832
|
truncate('The quick brown fox jumps over the lazy dog', 20);
|
|
@@ -675,7 +842,7 @@ truncate('Short text', 50);
|
|
|
675
842
|
|
|
676
843
|
Truncates a string from the middle, preserving both the beginning and end portions.
|
|
677
844
|
|
|
678
|
-
#### Example
|
|
845
|
+
#### Example
|
|
679
846
|
|
|
680
847
|
```javascript
|
|
681
848
|
truncateMiddle('The quick brown fox jumps right over the lazy dog', 20);
|
|
@@ -694,7 +861,7 @@ truncateMiddle('Short text', 50);
|
|
|
694
861
|
|
|
695
862
|
Unescapes backslash-escaped spaces and trims whitespace from both ends. Commonly used to clean file paths that have been escaped when pasted into terminals.
|
|
696
863
|
|
|
697
|
-
#### Example
|
|
864
|
+
#### Example
|
|
698
865
|
|
|
699
866
|
```javascript
|
|
700
867
|
unescapeSpaces('My\\ Folder\\ Name');
|