bitaboom 1.5.0 → 2.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/README.md +149 -818
- package/dist/index.d.ts +68 -112
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/package.json +10 -11
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Bitaboom
|
|
2
2
|
|
|
3
3
|
[](https://wakatime.com/badge/user/a0b906ce-b8e7-4463-8bce-383238df6d4b/project/4a00f7dd-3a49-4d59-a2ff-43c89e22d650)
|
|
4
4
|

|
|
@@ -8,838 +8,169 @@
|
|
|
8
8
|

|
|
9
9
|

|
|
10
10
|
[](https://codecov.io/gh/ragaeeb/bitaboom)
|
|
11
|
-
[](https://bundlejs.com/?q=bitaboom%40latest)
|
|
12
11
|

|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
Bitaboom is a TypeScript-first string utility toolkit focused on Arabic and bilingual (Arabic ↔ English) publishing workflows. It ships a wide surface of helpers for:
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
- Arabic script awareness (diacritics, tatweel, Urdu glyphs, punctuation harmonisation)
|
|
16
|
+
- Formatting and typography clean-up for scanned/OCRd manuscripts
|
|
17
|
+
- Sanitisation pipelines for removing noise such as references, page numbers, markdown artefacts, or escaped spaces
|
|
18
|
+
- Parsing helpers (balanced punctuation, JSON normalisation, page range parsing)
|
|
19
|
+
- Transliteration cleanup and salutation normalisation for classical Islamic texts
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
The project targets ESNext and is built/tested with Bun. All exports are tree-shakeable and documented with JSDoc.
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
## Installation
|
|
23
|
-
|
|
24
|
-
To install Bitaboom, use npm or yarn:
|
|
23
|
+
## Quick start
|
|
25
24
|
|
|
26
25
|
```bash
|
|
27
26
|
npm install bitaboom
|
|
28
27
|
# or
|
|
29
28
|
yarn add bitaboom
|
|
30
29
|
# or
|
|
31
|
-
pnpm
|
|
30
|
+
pnpm add bitaboom
|
|
32
31
|
# or
|
|
33
32
|
bun add bitaboom
|
|
34
33
|
```
|
|
35
34
|
|
|
36
|
-
## Usage
|
|
37
|
-
|
|
38
|
-
Import the library into your project:
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
import { functionName } from 'bitaboom';
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Use any function from the API in your code:
|
|
45
|
-
|
|
46
35
|
```typescript
|
|
47
|
-
|
|
48
|
-
console.log(result);
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Available Functions
|
|
52
|
-
|
|
53
|
-
### `addSpaceBeforeAndAfterPunctuation`
|
|
54
|
-
|
|
55
|
-
Adds spaces before and after punctuation marks except in specific cases like quoted text.
|
|
56
|
-
|
|
57
|
-
#### Example
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
addSpaceBeforeAndAfterPunctuation('Text,word');
|
|
61
|
-
// Output: 'Text, word'
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
---
|
|
65
|
-
|
|
66
|
-
### `addSpaceBetweenArabicTextAndNumbers`
|
|
67
|
-
|
|
68
|
-
Inserts spaces between Arabic text and numbers.
|
|
69
|
-
|
|
70
|
-
#### Example
|
|
71
|
-
|
|
72
|
-
```javascript
|
|
73
|
-
addSpaceBetweenArabicTextAndNumbers('الآية37');
|
|
74
|
-
// Output: 'الآية 37'
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
### `applySmartQuotes`
|
|
80
|
-
|
|
81
|
-
Turns regular double quotes into smart quotes and fixes any incorrect starting quotes.
|
|
82
|
-
|
|
83
|
-
#### Example
|
|
84
|
-
|
|
85
|
-
```javascript
|
|
86
|
-
applySmartQuotes('The "quick brown" fox');
|
|
87
|
-
// Output: 'The "quick brown" fox'
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
### `arabicNumeralToNumber`
|
|
93
|
-
|
|
94
|
-
Converts Arabic-Indic numerals (٠-٩) to a JavaScript number. This function finds all Arabic-Indic digits in the input string and converts them to their corresponding Arabic (Western) digits, then parses the result as an integer.
|
|
95
|
-
|
|
96
|
-
#### Example
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
arabicNumeralToNumber("١٢٣");
|
|
100
|
-
// Output: 123
|
|
101
|
-
|
|
102
|
-
arabicNumeralToNumber("٥٠");
|
|
103
|
-
// Output: 50
|
|
104
|
-
|
|
105
|
-
arabicNumeralToNumber("abc١٢٣xyz");
|
|
106
|
-
// Output: 123 (non-digits ignored)
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
---
|
|
110
|
-
|
|
111
|
-
### `cleanExtremeArabicUnderscores`
|
|
112
|
-
|
|
113
|
-
Removes extreme Arabic underscores (ـ) from the beginning or end of lines. It does not affect Hijri dates or certain Arabic terms.
|
|
114
|
-
|
|
115
|
-
#### Example
|
|
116
|
-
|
|
117
|
-
```javascript
|
|
118
|
-
cleanExtremeArabicUnderscores('ـThis is a textـ');
|
|
119
|
-
// Output: "This is a text"
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
### `cleanLiteralNewLines`
|
|
125
|
-
|
|
126
|
-
Replaces literal new line characters (`\n`) with actual line breaks.
|
|
127
|
-
|
|
128
|
-
#### Example
|
|
129
|
-
|
|
130
|
-
```javascript
|
|
131
|
-
cleanLiteralNewLines('A\nB');
|
|
132
|
-
// Output: 'A\nB'
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
---
|
|
136
|
-
|
|
137
|
-
### `cleanMultilines`
|
|
138
|
-
|
|
139
|
-
Removes trailing spaces from each line in a multiline string.
|
|
140
|
-
|
|
141
|
-
#### Example
|
|
142
|
-
|
|
143
|
-
```javascript
|
|
144
|
-
cleanMultilines(' This is a line \nAnother line ');
|
|
145
|
-
// Output: 'This is a line\nAnother line'
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
### `cleanSymbolsAndPartReferences`
|
|
151
|
-
|
|
152
|
-
Removes various symbols, part references, and numerical markers from the text.
|
|
153
|
-
|
|
154
|
-
#### Example
|
|
155
|
-
|
|
156
|
-
```javascript
|
|
157
|
-
cleanSymbolsAndPartReferences('(1) (2/3)');
|
|
158
|
-
// Output: ''
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
### `cleanTrailingPageNumbers`
|
|
164
|
-
|
|
165
|
-
Removes trailing page numbers formatted as `-[46]-` from the text.
|
|
166
|
-
|
|
167
|
-
#### Example
|
|
168
|
-
|
|
169
|
-
```javascript
|
|
170
|
-
cleanTrailingPageNumbers('This is some -[46]- text');
|
|
171
|
-
// Output: 'This is some text'
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
---
|
|
175
|
-
|
|
176
|
-
### `convertUrduSymbolsToArabic`
|
|
177
|
-
|
|
178
|
-
Converts Urdu symbols like 'ھ' and 'ی' to their Arabic equivalents 'ه' and 'ي'.
|
|
179
|
-
|
|
180
|
-
#### Example
|
|
181
|
-
|
|
182
|
-
```javascript
|
|
183
|
-
convertUrduSymbolsToArabic('ھذا');
|
|
184
|
-
// Output: 'هذا'
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
### `ensureSpaceBeforeBrackets`
|
|
190
|
-
|
|
191
|
-
Ensures there is exactly one space before parentheses that follow non-whitespace characters. Normalizes multiple spaces to a single space.
|
|
192
|
-
|
|
193
|
-
#### Example
|
|
194
|
-
|
|
195
|
-
```javascript
|
|
196
|
-
ensureSpaceBeforeBrackets('text(note)');
|
|
197
|
-
// Output: 'text (note)'
|
|
198
|
-
|
|
199
|
-
ensureSpaceBeforeBrackets('text (note)');
|
|
200
|
-
// Output: 'text (note)'
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
---
|
|
204
|
-
|
|
205
|
-
### `ensureSpaceBeforeQuotes`
|
|
206
|
-
|
|
207
|
-
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.
|
|
208
|
-
|
|
209
|
-
#### Example
|
|
210
|
-
|
|
211
|
-
```javascript
|
|
212
|
-
ensureSpaceBeforeQuotes('text«quote»');
|
|
213
|
-
// Output: 'text «quote»'
|
|
214
|
-
|
|
215
|
-
ensureSpaceBeforeQuotes('text «quote»');
|
|
216
|
-
// Output: 'text «quote»'
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
### `escapeRegex`
|
|
222
|
-
|
|
223
|
-
Escapes a string so it can be safely embedded into a RegExp source.
|
|
224
|
-
|
|
225
|
-
#### Example
|
|
226
|
-
|
|
227
|
-
```javascript
|
|
228
|
-
escapeRegex('Hello [world]');
|
|
229
|
-
// Output: 'Hello \\[world\\]'
|
|
230
|
-
```
|
|
231
|
-
|
|
232
|
-
---
|
|
233
|
-
|
|
234
|
-
### `extractInitials`
|
|
235
|
-
|
|
236
|
-
Extracts initials from the input string, typically for names or titles.
|
|
237
|
-
|
|
238
|
-
#### Example
|
|
239
|
-
|
|
240
|
-
```javascript
|
|
241
|
-
extractInitials('Nayl al-Awtar');
|
|
242
|
-
// Output: 'NA'
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
### `fixBracketTypos`
|
|
246
|
-
|
|
247
|
-
Fixes common bracket and quotation mark typos in text. Corrects malformed patterns like "(«", "»)", and misplaced digits in brackets.
|
|
248
|
-
|
|
249
|
-
#### Example
|
|
250
|
-
|
|
251
|
-
```javascript
|
|
252
|
-
fixBracketTypos('(«text»)');
|
|
253
|
-
// Output: '«text»'
|
|
254
|
-
|
|
255
|
-
fixBracketTypos(')5)');
|
|
256
|
-
// Output: '(5)'
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
---
|
|
260
|
-
|
|
261
|
-
### `fixCurlyBraces`
|
|
262
|
-
|
|
263
|
-
Fixes mismatched curly braces by converting incorrect bracket/brace combinations to proper curly braces { }.
|
|
264
|
-
|
|
265
|
-
#### Example
|
|
266
|
-
|
|
267
|
-
```javascript
|
|
268
|
-
fixCurlyBraces('(content}');
|
|
269
|
-
// Output: '{content}'
|
|
270
|
-
|
|
271
|
-
fixCurlyBraces('{content)');
|
|
272
|
-
// Output: '{content}'
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
---
|
|
276
|
-
|
|
277
|
-
### `fixMismatchedQuotationMarks`
|
|
278
|
-
|
|
279
|
-
Fixes mismatched quotation marks in Arabic text by converting various incorrect bracket/quote combinations to proper Arabic quotation marks (« »).
|
|
280
|
-
|
|
281
|
-
#### Example
|
|
282
|
-
|
|
283
|
-
```javascript
|
|
284
|
-
fixMismatchedQuotationMarks('«text)');
|
|
285
|
-
// Output: '«text»'
|
|
286
|
-
|
|
287
|
-
fixMismatchedQuotationMarks('(text»');
|
|
288
|
-
// Output: '«text»'
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
---
|
|
292
|
-
|
|
293
|
-
### `fixTrailingWow`
|
|
294
|
-
|
|
295
|
-
Corrects unnecessary trailing "و" in greetings or phrases.
|
|
296
|
-
|
|
297
|
-
#### Example
|
|
298
|
-
|
|
299
|
-
```javascript
|
|
300
|
-
fixTrailingWow('السلام عليكم و رحمة');
|
|
301
|
-
// Output: 'السلام عليكم ورحمة'
|
|
302
|
-
```
|
|
303
|
-
|
|
304
|
-
---
|
|
305
|
-
|
|
306
|
-
### `getArabicScore`
|
|
307
|
-
|
|
308
|
-
Calculates the proportion of Arabic characters in text relative to total non-whitespace characters.
|
|
309
|
-
|
|
310
|
-
#### Example
|
|
311
|
-
|
|
312
|
-
```javascript
|
|
313
|
-
getArabicScore('مرحبا hello');
|
|
314
|
-
// Output: 0.5 (5 Arabic chars out of 10 non-whitespace chars)
|
|
315
|
-
|
|
316
|
-
getArabicScore('مرحبا');
|
|
317
|
-
// Output: 1.0 (100% Arabic)
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
---
|
|
321
|
-
|
|
322
|
-
### `hasWordInSingleLine`
|
|
323
|
-
|
|
324
|
-
Checks if a line has any word by itself.
|
|
325
|
-
|
|
326
|
-
#### Example
|
|
327
|
-
|
|
328
|
-
```javascript
|
|
329
|
-
hasWordInSingleLine('Abc efg\nhij\nklmn opq');
|
|
330
|
-
// Output: true (since "hij" is by itself)
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
---
|
|
334
|
-
|
|
335
|
-
### `insertLineBreaksAfterPunctuation`
|
|
336
|
-
|
|
337
|
-
Adds line breaks after punctuation marks such as periods, exclamation points, and question marks.
|
|
338
|
-
|
|
339
|
-
#### Example
|
|
340
|
-
|
|
341
|
-
```javascript
|
|
342
|
-
insertLineBreaksAfterPunctuation('Text.');
|
|
343
|
-
// Output: 'Text.
|
|
344
|
-
'
|
|
345
|
-
```
|
|
346
|
-
|
|
347
|
-
---
|
|
348
|
-
|
|
349
|
-
### `isAllUppercase`
|
|
350
|
-
|
|
351
|
-
Detects if text is entirely in uppercase letters.
|
|
352
|
-
|
|
353
|
-
#### Example
|
|
354
|
-
|
|
355
|
-
```javascript
|
|
356
|
-
isAllUppercase('HELLO WORLD');
|
|
357
|
-
// Output: true
|
|
358
|
-
|
|
359
|
-
isAllUppercase('Hello World');
|
|
360
|
-
// Output: false
|
|
361
|
-
|
|
362
|
-
isAllUppercase('123');
|
|
363
|
-
// Output: false (no letters)
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
---
|
|
367
|
-
|
|
368
|
-
### `isBalanced`
|
|
369
|
-
|
|
370
|
-
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.
|
|
371
|
-
|
|
372
|
-
#### Example
|
|
373
|
-
|
|
374
|
-
```javascript
|
|
375
|
-
isBalanced('He said "Hello (world)!"');
|
|
376
|
-
// Output: true
|
|
377
|
-
|
|
378
|
-
isBalanced('He said "Hello (world!"');
|
|
379
|
-
// Output: false (unbalanced quote)
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
---
|
|
383
|
-
|
|
384
|
-
### `isJsonStructureValid`
|
|
385
|
-
|
|
386
|
-
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.
|
|
387
|
-
|
|
388
|
-
#### Example
|
|
389
|
-
|
|
390
|
-
```javascript
|
|
391
|
-
isJsonStructureValid("{10: 'abc', 'key': 'value'}");
|
|
392
|
-
// Output: true
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
---
|
|
396
|
-
|
|
397
|
-
### `isOnlyPunctuation`
|
|
398
|
-
|
|
399
|
-
Checks if the input string consists only of punctuation characters.
|
|
400
|
-
|
|
401
|
-
#### Example
|
|
402
|
-
|
|
403
|
-
```javascript
|
|
404
|
-
isOnlyPunctuation('!?');
|
|
405
|
-
// Output: true
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
---
|
|
409
|
-
|
|
410
|
-
### `makeDiacriticInsensitive`
|
|
411
|
-
|
|
412
|
-
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).
|
|
413
|
-
|
|
414
|
-
#### Example
|
|
415
|
-
|
|
416
|
-
```javascript
|
|
417
|
-
const pattern = makeDiacriticInsensitive('محمد');
|
|
418
|
-
const regex = new RegExp(pattern, 'gi');
|
|
419
|
-
regex.test('مُحَمَّد'); // true
|
|
420
|
-
regex.test('محمد'); // true
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
---
|
|
424
|
-
|
|
425
|
-
### `normalizeArabicPrefixesToAl`
|
|
426
|
-
|
|
427
|
-
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.
|
|
428
|
-
|
|
429
|
-
#### Example
|
|
430
|
-
|
|
431
|
-
```javascript
|
|
432
|
-
normalizeArabicPrefixesToAl('Ash-Shafiee');
|
|
433
|
-
// Output: 'al-Shafiee'
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
---
|
|
437
|
-
|
|
438
|
-
### `normalizeDoubleApostrophes`
|
|
439
|
-
|
|
440
|
-
Removes double occurrences of Arabic apostrophes such as ʿʿ or ʾʾ.
|
|
441
|
-
|
|
442
|
-
#### Example
|
|
443
|
-
|
|
444
|
-
```javascript
|
|
445
|
-
normalizeDoubleApostrophes('ʿulamāʾʾ');
|
|
446
|
-
// Output: 'ʿulamāʾ'
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
---
|
|
450
|
-
|
|
451
|
-
### `normalizeJsonSyntax`
|
|
452
|
-
|
|
453
|
-
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.
|
|
454
|
-
|
|
455
|
-
#### Example
|
|
456
|
-
|
|
457
|
-
```javascript
|
|
458
|
-
normalizeJsonSyntax("{10: 'abc', 20: 'def'}");
|
|
459
|
-
// Output: '{"10": "abc", "20": "def"}'
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
---
|
|
463
|
-
|
|
464
|
-
### `normalizeTransliteratedEnglish`
|
|
465
|
-
|
|
466
|
-
Simplifies English transliterations by removing diacritics, apostrophes, and common prefixes.
|
|
467
|
-
|
|
468
|
-
#### Example
|
|
469
|
-
|
|
470
|
-
```javascript
|
|
471
|
-
normalizeTransliteratedEnglish('Al-Jadwāl');
|
|
472
|
-
// Output: 'Jadwal'
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
---
|
|
476
|
-
|
|
477
|
-
### `normalize`
|
|
478
|
-
|
|
479
|
-
Normalizes the text by removing diacritics, apostrophes, and dashes.
|
|
480
|
-
|
|
481
|
-
#### Example
|
|
482
|
-
|
|
483
|
-
```javascript
|
|
484
|
-
normalize('Al-Jadwāl');
|
|
485
|
-
// Output: 'AlJadwal'
|
|
486
|
-
```
|
|
487
|
-
|
|
488
|
-
---
|
|
489
|
-
|
|
490
|
-
### `parsePageRanges`
|
|
491
|
-
|
|
492
|
-
Parses page input string into array of page numbers, supporting ranges and lists.
|
|
493
|
-
|
|
494
|
-
#### Example
|
|
495
|
-
|
|
496
|
-
```javascript
|
|
497
|
-
parsePageRanges('1-5');
|
|
498
|
-
// Output: [1, 2, 3, 4, 5]
|
|
499
|
-
|
|
500
|
-
parsePageRanges('1,3,5');
|
|
501
|
-
// Output: [1, 3, 5]
|
|
502
|
-
|
|
503
|
-
parsePageRanges('10-8');
|
|
504
|
-
// Throws Error: 'Start page cannot be greater than end page'
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
---
|
|
508
|
-
|
|
509
|
-
### `removeArabicPrefixes`
|
|
510
|
-
|
|
511
|
-
Strips common Arabic prefixes like 'al-', 'bi-', 'fī', 'wa-', etc., from the beginning of words.
|
|
512
|
-
|
|
513
|
-
#### Example
|
|
514
|
-
|
|
515
|
-
```javascript
|
|
516
|
-
removeArabicPrefixes('al-Bukhari');
|
|
517
|
-
// Output: 'Bukhari'
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
---
|
|
521
|
-
|
|
522
|
-
### `removeDeathYear`
|
|
523
|
-
|
|
524
|
-
Removes death year references like "(d. 390H)" and "[d. 100h]" from the text.
|
|
525
|
-
|
|
526
|
-
#### Example
|
|
527
|
-
|
|
528
|
-
```javascript
|
|
529
|
-
removeDeathYear('Sufyān ibn 'Uyaynah (d. 198h)');
|
|
530
|
-
// Output: 'Sufyān ibn 'Uyaynah'
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
---
|
|
534
|
-
|
|
535
|
-
### `removeMarkdownFormatting`
|
|
536
|
-
|
|
537
|
-
Removes common Markdown formatting syntax from text.
|
|
538
|
-
|
|
539
|
-
#### Example
|
|
540
|
-
|
|
541
|
-
```javascript
|
|
542
|
-
removeMarkdownFormatting('**Bold** and *italic* text');
|
|
543
|
-
// Output: 'Bold and italic text'
|
|
544
|
-
|
|
545
|
-
removeMarkdownFormatting('# Header\n- List item');
|
|
546
|
-
// Output: 'Header\nList item'
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
---
|
|
550
|
-
|
|
551
|
-
### `removeNonIndexSignatures`
|
|
552
|
-
|
|
553
|
-
Removes single-digit numbers and dashes from Arabic text but preserves numbers used as indexes.
|
|
554
|
-
|
|
555
|
-
#### Example
|
|
556
|
-
|
|
557
|
-
```javascript
|
|
558
|
-
removeNonIndexSignatures('الورقه 3 المصدر');
|
|
559
|
-
// Output: 'الورقه المصدر'
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
---
|
|
563
|
-
|
|
564
|
-
### `removeNumbersAndDashes`
|
|
565
|
-
|
|
566
|
-
Removes numeric digits and dashes from the text.
|
|
567
|
-
|
|
568
|
-
#### Example
|
|
569
|
-
|
|
570
|
-
```javascript
|
|
571
|
-
removeNumbersAndDashes('ABC 123-Xyz');
|
|
572
|
-
// Output: 'ABC Xyz'
|
|
573
|
-
```
|
|
574
|
-
|
|
575
|
-
---
|
|
576
|
-
|
|
577
|
-
### `removeRedundantPunctuation`
|
|
578
|
-
|
|
579
|
-
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 (!).
|
|
580
|
-
|
|
581
|
-
#### Example
|
|
582
|
-
|
|
583
|
-
```javascript
|
|
584
|
-
removeRedundantPunctuation('كيف حالك؟.');
|
|
585
|
-
// Output: 'كيف حالك؟'
|
|
586
|
-
|
|
587
|
-
removeRedundantPunctuation('ممتاز!،');
|
|
588
|
-
// Output: 'ممتاز!'
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
---
|
|
592
|
-
|
|
593
|
-
### `removeSingleDigitReferences`
|
|
594
|
-
|
|
595
|
-
Removes single digit references like (1), «2», [3] from the text.
|
|
596
|
-
|
|
597
|
-
#### Example
|
|
598
|
-
|
|
599
|
-
```javascript
|
|
600
|
-
removeSingleDigitReferences('Ref (1), Ref «2», Ref [3]');
|
|
601
|
-
// Output: 'Ref , Ref , Ref '
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
---
|
|
605
|
-
|
|
606
|
-
### `removeSingularCodes`
|
|
607
|
-
|
|
608
|
-
Removes Arabic letters or Arabic-Indic numerals enclosed in square brackets or parentheses.
|
|
609
|
-
|
|
610
|
-
#### Example
|
|
611
|
-
|
|
612
|
-
```javascript
|
|
613
|
-
removeSingularCodes('[س]');
|
|
614
|
-
// Output: ''
|
|
615
|
-
```
|
|
616
|
-
|
|
617
|
-
---
|
|
618
|
-
|
|
619
|
-
### `removeSolitaryArabicLetters`
|
|
620
|
-
|
|
621
|
-
Removes solitary Arabic letters unless they are 'ha' used in Hijri years.
|
|
622
|
-
|
|
623
|
-
#### Example
|
|
624
|
-
|
|
625
|
-
```javascript
|
|
626
|
-
removeSolitaryArabicLetters('ب ا الكلمات ت');
|
|
627
|
-
// Output: 'ا الكلمات'
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
---
|
|
631
|
-
|
|
632
|
-
### `removeUrls`
|
|
633
|
-
|
|
634
|
-
Removes URLs from the text.
|
|
635
|
-
|
|
636
|
-
#### Example
|
|
637
|
-
|
|
638
|
-
```javascript
|
|
639
|
-
removeUrls('Visit https://example.com');
|
|
640
|
-
// Output: 'Visit '
|
|
641
|
-
```
|
|
642
|
-
|
|
643
|
-
### `replaceDoubleBracketsWithArrows`
|
|
644
|
-
|
|
645
|
-
Replaces double parentheses with single arrow quotation marks. Converts `((text))` format to `«text»` format, handling optional spaces inside the brackets.
|
|
646
|
-
|
|
647
|
-
#### Example
|
|
648
|
-
|
|
649
|
-
```javascript
|
|
650
|
-
replaceDoubleBracketsWithArrows('((text))');
|
|
651
|
-
// Output: '«text»'
|
|
652
|
-
|
|
653
|
-
replaceDoubleBracketsWithArrows('(( spaced text ))');
|
|
654
|
-
// Output: '«spaced text»'
|
|
655
|
-
```
|
|
656
|
-
|
|
657
|
-
---
|
|
658
|
-
|
|
659
|
-
### `replaceEnglishPunctuationWithArabic`
|
|
660
|
-
|
|
661
|
-
Replaces English punctuation marks (e.g., ? and ;) with their Arabic equivalents.
|
|
662
|
-
|
|
663
|
-
#### Example
|
|
664
|
-
|
|
665
|
-
```javascript
|
|
666
|
-
replaceEnglishPunctuationWithArabic('This; and, that?');
|
|
667
|
-
// Output: 'This؛and، that؟'
|
|
668
|
-
```
|
|
669
|
-
|
|
670
|
-
---
|
|
671
|
-
|
|
672
|
-
### `replaceLineBreaksWithSpaces`
|
|
673
|
-
|
|
674
|
-
Replaces consecutive line breaks and whitespace characters with a single space.
|
|
675
|
-
|
|
676
|
-
#### Example
|
|
677
|
-
|
|
678
|
-
```javascript
|
|
679
|
-
replaceLineBreaksWithSpaces('a\nb');
|
|
680
|
-
// Output: 'a b'
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
---
|
|
684
|
-
|
|
685
|
-
### `replaceSalutationsWithSymbol`
|
|
686
|
-
|
|
687
|
-
Replaces common salutations like "sallahu alayhi wasallam" with "ﷺ". Handles variations like 'peace and blessings be upon him'.
|
|
688
|
-
|
|
689
|
-
#### Example
|
|
690
|
-
|
|
691
|
-
```javascript
|
|
692
|
-
replaceSalutationsWithSymbol('Then Muḥammad (sallahu alayhi wasallam)');
|
|
693
|
-
// Output: 'Then Muḥammad ﷺ'
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
---
|
|
697
|
-
|
|
698
|
-
### `splitByQuotes`
|
|
699
|
-
|
|
700
|
-
Splits a string by spaces but keeps quoted substrings intact. Substrings enclosed in double quotes are treated as a single part.
|
|
701
|
-
|
|
702
|
-
#### Example
|
|
703
|
-
|
|
704
|
-
```javascript
|
|
705
|
-
splitByQuotes('"This is" "a part of the" "string and"');
|
|
706
|
-
// Output: ["This is", "a part of the", "string and"]
|
|
707
|
-
```
|
|
708
|
-
|
|
709
|
-
### `stripAllDigits`
|
|
710
|
-
|
|
711
|
-
Removes all numeric digits from the text.
|
|
712
|
-
|
|
713
|
-
#### Example
|
|
714
|
-
|
|
715
|
-
```javascript
|
|
716
|
-
stripAllDigits('abc123');
|
|
717
|
-
// Output: 'abc'
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
---
|
|
721
|
-
|
|
722
|
-
### `toTitleCase`
|
|
723
|
-
|
|
724
|
-
Converts a string to title case (first letter of each word capitalized).
|
|
725
|
-
|
|
726
|
-
#### Example
|
|
727
|
-
|
|
728
|
-
```javascript
|
|
729
|
-
toTitleCase('hello world');
|
|
730
|
-
// Output: 'Hello World'
|
|
731
|
-
|
|
732
|
-
toTitleCase('the quick brown fox');
|
|
733
|
-
// Output: 'The Quick Brown Fox'
|
|
734
|
-
```
|
|
735
|
-
|
|
736
|
-
---
|
|
737
|
-
|
|
738
|
-
### `truncate`
|
|
739
|
-
|
|
740
|
-
Truncates a string to a specified length, adding an ellipsis if truncated.
|
|
741
|
-
|
|
742
|
-
#### Example
|
|
743
|
-
|
|
744
|
-
```javascript
|
|
745
|
-
truncate('The quick brown fox jumps over the lazy dog', 20);
|
|
746
|
-
// Output: 'The quick brown fox…'
|
|
747
|
-
|
|
748
|
-
truncate('Short text', 50);
|
|
749
|
-
// Output: 'Short text'
|
|
750
|
-
```
|
|
751
|
-
|
|
752
|
-
---
|
|
753
|
-
|
|
754
|
-
### `truncateMiddle`
|
|
755
|
-
|
|
756
|
-
Truncates a string from the middle, preserving both the beginning and end portions.
|
|
757
|
-
|
|
758
|
-
#### Example
|
|
759
|
-
|
|
760
|
-
```javascript
|
|
761
|
-
truncateMiddle('The quick brown fox jumps right over the lazy dog', 20);
|
|
762
|
-
// Output: 'The quick bro…zy dog'
|
|
763
|
-
|
|
764
|
-
truncateMiddle('The quick brown fox jumps right over the lazy dog', 25, 8);
|
|
765
|
-
// Output: 'The quick brown …lazy dog'
|
|
766
|
-
|
|
767
|
-
truncateMiddle('Short text', 50);
|
|
768
|
-
// Output: 'Short text'
|
|
769
|
-
```
|
|
770
|
-
|
|
771
|
-
---
|
|
772
|
-
|
|
773
|
-
### `unescapeSpaces`
|
|
774
|
-
|
|
775
|
-
Unescapes backslash-escaped spaces and trims whitespace from both ends. Commonly used to clean file paths that have been escaped when pasted into terminals.
|
|
776
|
-
|
|
777
|
-
#### Example
|
|
778
|
-
|
|
779
|
-
```javascript
|
|
780
|
-
unescapeSpaces('My\\ Folder\\ Name');
|
|
781
|
-
// Output: 'My Folder Name'
|
|
782
|
-
|
|
783
|
-
unescapeSpaces(' /path/to/My\\ Document.txt ');
|
|
784
|
-
// Output: '/path/to/My Document.txt'
|
|
785
|
-
|
|
786
|
-
unescapeSpaces('regular text');
|
|
787
|
-
// Output: 'regular text'
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
---
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
## sanitizeArabic — unified Arabic text sanitizer
|
|
794
|
-
|
|
795
|
-
`sanitizeArabic(input, optionsOrPreset)` provides fast, configurable cleanup for Arabic text and replaces older per-rule utilities.
|
|
796
|
-
It supports presets (`"light"`, `"search"`, `"aggressive"`) and fine-grained options like `stripDiacritics`, `stripTatweel`, `normalizeAlif`,
|
|
797
|
-
`replaceAlifMaqsurah`, `replaceTaMarbutahWithHa`, `stripZeroWidth`, `zeroWidthToSpace`, `stripLatinAndSymbols`, `lettersAndSpacesOnly`,
|
|
798
|
-
`keepOnlyArabicLetters`, `collapseWhitespace`, `trim`, and `removeHijriMarker`. For one-off rules, use `base: 'none'` to apply only what you specify.
|
|
799
|
-
|
|
800
|
-
**Examples**
|
|
801
|
-
|
|
802
|
-
```ts
|
|
803
|
-
import { sanitizeArabic } from 'bitaboom';
|
|
804
|
-
|
|
805
|
-
// Light display cleanup
|
|
806
|
-
sanitizeArabic(' مرحبا\u200C\u200D بالعالم ', 'light'); // → 'مرحبا بالعالم'
|
|
807
|
-
|
|
808
|
-
// Tolerant search normalization
|
|
809
|
-
sanitizeArabic('اَلسَّلَامُ عَلَيْكُمْ', 'search'); // → 'السلام عليكم'
|
|
810
|
-
|
|
811
|
-
// Indexing-friendly text (letters + spaces only)
|
|
812
|
-
sanitizeArabic('اَلسَّلَامُ 1435/3/29 هـ — www', 'aggressive'); // → 'السلام'
|
|
813
|
-
|
|
814
|
-
// Tatweel-only, preserving dates/list markers
|
|
815
|
-
sanitizeArabic('أبـــتِـــكَةُ', { base: 'none', stripTatweel: true }); // → 'أبتِكَةُ'
|
|
816
|
-
|
|
817
|
-
// Zero-width controls → spaces
|
|
818
|
-
sanitizeArabic('يَخْلُوَ . قَالَ غَرِيبٌ . ', { base: 'none', stripZeroWidth: true, zeroWidthToSpace: true });
|
|
819
|
-
// → 'يَخْلُوَ . قَالَ غَرِيبٌ . '
|
|
820
|
-
```
|
|
821
|
-
|
|
822
|
-
## makeDiacriticInsensitiveRegex — tolerant Arabic matcher
|
|
823
|
-
|
|
824
|
-
`makeDiacriticInsensitiveRegex(needle, opts?)` returns a `RegExp` that matches Arabic text while ignoring diacritics,
|
|
825
|
-
optionally tolerating tatweel, and treating common equivalents as equal (`ا~أ~إ~آ`, `ة~ه`, `ى~ي`). Whitespace in the needle
|
|
826
|
-
is treated as `\s+` by default, making it robust across spacing variants.
|
|
827
|
-
|
|
828
|
-
**Examples**
|
|
829
|
-
|
|
830
|
-
```ts
|
|
831
|
-
import { makeDiacriticInsensitiveRegex } from 'bitaboom';
|
|
36
|
+
import { makeDiacriticInsensitiveRegex, removeMarkdownFormatting } from 'bitaboom';
|
|
832
37
|
|
|
833
38
|
const rx = makeDiacriticInsensitiveRegex('أنا إلى الآفاق');
|
|
834
|
-
rx.test('انا
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
39
|
+
rx.test('انا الي الافاق'); // true
|
|
40
|
+
|
|
41
|
+
const plain = removeMarkdownFormatting('**Bold** _italic_ [link](https://example.com)');
|
|
42
|
+
console.log(plain); // "Bold italic link"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Feature highlights
|
|
46
|
+
|
|
47
|
+
- **Arabic-first matching** – build diacritic-insensitive regular expressions, collapse tatweel, score Arabic content density, and replace Urdu glyphs.
|
|
48
|
+
- **Rich typography normalisers** – more than 30 helpers to fix punctuation spacing, quotes, brackets, ellipses, smart quotes, uppercase detection, and whitespace quirks.
|
|
49
|
+
- **Sanitisation pipelines** – strip references, URLs, part markers, markdown decorations, escaped spaces, or numbers in bilingual text.
|
|
50
|
+
- **Parsing helpers** – validate JSON-ish blobs, split search queries by quotes, balance parentheses/quotes, and expand page range strings.
|
|
51
|
+
- **Transliteration polish** – normalise common Arabic prefixes (`al-`, `wa-`, `bi-`), dedupe apostrophes, replace salutations with ﷺ, and extract initials from transliterated names.
|
|
52
|
+
- **Bun-native toolchain** – tests run through `bun test` and builds use an in-repo `tsdown` pipeline powered by `bun build` + `tsc` for declarations.
|
|
53
|
+
|
|
54
|
+
## API overview
|
|
55
|
+
|
|
56
|
+
All modules are exported from `src/index.ts`. Functions are grouped below by feature area.
|
|
57
|
+
|
|
58
|
+
### Arabic helpers (`src/arabic.ts`)
|
|
59
|
+
|
|
60
|
+
| Function | Description |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `arabicNumeralToNumber` | Convert Arabic-Indic numerals (٠-٩) embedded in a string into a JavaScript number. |
|
|
63
|
+
| `cleanExtremeArabicUnderscores` | Remove decorative tatweel/underscores at line edges without touching Hijri date suffixes. |
|
|
64
|
+
| `convertUrduSymbolsToArabic` | Map Urdu variants such as ھ → ه and ی → ي. |
|
|
65
|
+
| `getArabicScore` | Return the ratio of Arabic letters to total non-space, non-digit characters (0 → 1). |
|
|
66
|
+
| `fixTrailingWow` | Collapse stray "و" separators in greetings (e.g. `عليكم و رحمة` → `عليكم ورحمة`). |
|
|
67
|
+
| `addSpaceBetweenArabicTextAndNumbers` | Insert a space between Arabic text segments and following numbers. |
|
|
68
|
+
| `removeNonIndexSignatures` | Drop single-digit indices and dangling dashes surrounded by Arabic text. |
|
|
69
|
+
| `removeSingularCodes` | Strip single Arabic letters or digits enclosed in (), [], or «». |
|
|
70
|
+
| `removeSolitaryArabicLetters` | Remove isolated Arabic letters (excluding Hijri "ه"). |
|
|
71
|
+
| `replaceEnglishPunctuationWithArabic` | Replace ASCII `?` and `;` with Arabic equivalents (`؟`, `؛`) and normalise commas. |
|
|
72
|
+
|
|
73
|
+
### Cleaning & tolerant matching (`src/cleaning.ts`, `src/sanitization.ts`)
|
|
74
|
+
|
|
75
|
+
| Function | Description |
|
|
76
|
+
| --- | --- |
|
|
77
|
+
| `escapeRegex` | Safely escape special characters for inclusion in regular expression sources. |
|
|
78
|
+
| `makeDiacriticInsensitiveRegex` | Build a `RegExp` tolerant of Arabic diacritics, tatweel, whitespace variants, and letter equivalences. |
|
|
79
|
+
| `makeDiacriticInsensitive` | Produce a pattern string (no delimiters) for diacritic-insensitive matching of Arabic text. |
|
|
80
|
+
| `cleanSymbolsAndPartReferences` | Remove bracketed part markers, Arabic ornaments, and numeric references. |
|
|
81
|
+
| `cleanTrailingPageNumbers` | Drop `-[123]-` page markers. |
|
|
82
|
+
| `replaceLineBreaksWithSpaces` | Collapse whitespace and newline runs to single spaces. |
|
|
83
|
+
| `stripAllDigits` | Remove ASCII digits. |
|
|
84
|
+
| `removeDeathYear` | Strip `(d. ####H)`/`[d. ####h]` style death-year mentions. |
|
|
85
|
+
| `removeNumbersAndDashes` | Remove digits and dash characters everywhere. |
|
|
86
|
+
| `removeSingleDigitReferences` | Delete single digit markers like `(1)`, `[2]`, `«3»`. |
|
|
87
|
+
| `removeUrls` | Remove `http(s)` URLs. |
|
|
88
|
+
| `removeMarkdownFormatting` | Drop markdown bold/italic/link/list/header/backtick syntax. |
|
|
89
|
+
| `truncate` | Trim strings to a maximum length with ellipsis (`…`). |
|
|
90
|
+
| `truncateMiddle` | Preserve start/end segments while truncating the middle with ellipsis. |
|
|
91
|
+
| `unescapeSpaces` | Convert escaped spaces (`\ `) back to regular spaces and trim ends. |
|
|
92
|
+
|
|
93
|
+
### Formatting & typography (`src/formatting.ts`)
|
|
94
|
+
|
|
95
|
+
| Function | Description |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `insertLineBreaksAfterPunctuation` | Add line breaks after `.`, `!`, `?`, and `؟`. |
|
|
98
|
+
| `addSpaceBeforeAndAfterPunctuation` | Normalise spacing around punctuation while respecting quotes and ayah markers. |
|
|
99
|
+
| `applySmartQuotes` | Convert straight quotes to smart quotes and fix opening quotes. |
|
|
100
|
+
| `cleanLiteralNewLines` | Replace literal `\n`/`\r` sequences with actual newlines. |
|
|
101
|
+
| `cleanMultilines` | Trim trailing spaces per line. |
|
|
102
|
+
| `hasWordInSingleLine` | Detect whether a line contains a single standalone word. |
|
|
103
|
+
| `isOnlyPunctuation` | Check whether a string consists solely of punctuation/digits. |
|
|
104
|
+
| `cleanSpacesBeforePeriod` | Remove stray spaces before punctuation marks. |
|
|
105
|
+
| `condenseAsterisks` | Collapse multiple `*` into a single asterisk. |
|
|
106
|
+
| `condenseColons` | Normalise colon clusters like `.:.` → `:`. |
|
|
107
|
+
| `condenseDashes` | Reduce consecutive dashes to a single dash. |
|
|
108
|
+
| `condenseEllipsis` | Convert runs of periods to a single ellipsis character. |
|
|
109
|
+
| `reduceMultilineBreaksToDouble` | Limit blank lines to at most two consecutive newlines. |
|
|
110
|
+
| `reduceMultilineBreaksToSingle` | Collapse multiple blank lines to a single newline. |
|
|
111
|
+
| `condensePeriods` | Normalise spaced dot sequences (`. . .`). |
|
|
112
|
+
| `condenseUnderscores` | Collapse repeated underscores and tatweel runs. |
|
|
113
|
+
| `doubleToSingleBrackets` | Replace doubled parentheses/brackets with single ones. |
|
|
114
|
+
| `ensureSpaceBeforeBrackets` | Guarantee a single space before bracketed notes. |
|
|
115
|
+
| `ensureSpaceBeforeQuotes` | Ensure spacing before Arabic guillemets « ». |
|
|
116
|
+
| `fixBracketTypos` | Repair mismatched bracket pairs (e.g. `(«` or `)3)`). |
|
|
117
|
+
| `fixCurlyBraces` | Normalise `{}` curly brace mismatches. |
|
|
118
|
+
| `fixMismatchedQuotationMarks` | Fix malformed Arabic guillemets and parentheses combos. |
|
|
119
|
+
| `formatStringBySentence` | Reflow paragraphs while keeping numbered footnotes on separate lines. |
|
|
120
|
+
| `isAllUppercase` | Detect text containing only uppercase letters (ignoring non-letters). |
|
|
121
|
+
| `normalizeSlashInReferences` | Convert spaced fractions `127 / 11` → `127/11`. |
|
|
122
|
+
| `normalizeSpaces` | Collapse spaces/tabs to single spaces. |
|
|
123
|
+
| `removeRedundantPunctuation` | Remove redundant punctuation following Arabic `؟`/`!`. |
|
|
124
|
+
| `removeSpaceInsideBrackets` | Trim internal spaces inside brackets/parentheses. |
|
|
125
|
+
| `replaceDoubleBracketsWithArrows` | Turn `((text))` into `«text»`. |
|
|
126
|
+
| `stripBoldStyling` | Remove bold stylisation by decomposing Unicode. |
|
|
127
|
+
| `stripItalicsStyling` | Replace italic Unicode letters with plain equivalents. |
|
|
128
|
+
| `stripStyling` | Convenience combo of bold + italics stripping. |
|
|
129
|
+
| `toTitleCase` | Convert strings to title case, respecting Unicode letters. |
|
|
130
|
+
| `trimSpaceInsideQuotes` | Remove spaces immediately inside quotes/guillemets. |
|
|
131
|
+
|
|
132
|
+
### Parsing helpers (`src/parsing.ts`)
|
|
133
|
+
|
|
134
|
+
| Function | Description |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `normalizeJsonSyntax` | Convert pseudo-JSON with numeric keys/single quotes into valid JSON. |
|
|
137
|
+
| `isJsonStructureValid` | Detect JSON-like key/value blobs that can be normalised. |
|
|
138
|
+
| `splitByQuotes` | Split by spaces while keeping quoted substrings intact. |
|
|
139
|
+
| `isBalanced` | Ensure quotes and brackets are balanced and properly nested. |
|
|
140
|
+
| `parsePageRanges` | Expand range/list strings (`1-3,5`) into numeric arrays. |
|
|
141
|
+
|
|
142
|
+
### Transliteration (`src/transliteration.ts`)
|
|
143
|
+
|
|
144
|
+
| Function | Description |
|
|
145
|
+
| --- | --- |
|
|
146
|
+
| `normalizeArabicPrefixesToAl` | Normalise Arabic definite article prefixes to `al-`. |
|
|
147
|
+
| `normalizeDoubleApostrophes` | Collapse duplicated Arabic apostrophes (`ʿʿ`, `ʾʾ`). |
|
|
148
|
+
| `replaceSalutationsWithSymbol` | Replace salutations like "sallallahu alayhi wasallam" with ﷺ. |
|
|
149
|
+
| `normalize` | Strip diacritics, apostrophes, and dashes from transliterated text. |
|
|
150
|
+
| `removeArabicPrefixes` | Remove prefixes such as `al-`, `wa-`, `bi-`, `fī`, `li-`. |
|
|
151
|
+
| `normalizeTransliteratedEnglish` | Combine prefix removal + diacritic stripping. |
|
|
152
|
+
| `extractInitials` | Extract the first letters from up to two words (after normalisation). |
|
|
153
|
+
|
|
154
|
+
## Build & development
|
|
155
|
+
|
|
156
|
+
| Task | Command |
|
|
157
|
+
| --- | --- |
|
|
158
|
+
| Build library | `bun run build` (invokes the in-repo `scripts/tsdown.ts` pipeline, which bundles via `bun build` then emits declarations through `tsc`). |
|
|
159
|
+
| Run tests | `bun test` |
|
|
160
|
+
| Lint | `bun run lint` |
|
|
161
|
+
| Format | `bun run format` |
|
|
162
|
+
| Continuous lint | `bun run lint:ci` |
|
|
163
|
+
|
|
164
|
+
The custom `tsdown` script ensures reproducible builds without relying on `tsup`. It cleans the `dist/` directory, bundles `src/index.ts` with Bun's bundler (minified ESM output + sourcemap), and finally emits `.d.ts` files using `tsc --emitDeclarationOnly`.
|
|
165
|
+
|
|
166
|
+
## Contributing
|
|
167
|
+
|
|
168
|
+
1. Fork the repository and clone it locally.
|
|
169
|
+
2. Install Bun (`curl -fsSL https://bun.sh/install | bash`).
|
|
170
|
+
3. Run tests with `bun test` and format with `bun run format` before opening a pull request.
|
|
171
|
+
|
|
172
|
+
Issues and PRs are welcome—please include tests whenever you add or change behaviour.
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
MIT © Ragaeeb Haq
|