bitaboom 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.MD ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Ragaeeb Haq>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,547 @@
1
+ # Table of Contents
2
+
3
+ [![wakatime](https://wakatime.com/badge/user/a0b906ce-b8e7-4463-8bce-383238df6d4b/project/4a00f7dd-3a49-4d59-a2ff-43c89e22d650.svg)](https://wakatime.com/badge/user/a0b906ce-b8e7-4463-8bce-383238df6d4b/project/4a00f7dd-3a49-4d59-a2ff-43c89e22d650) ![GitHub](https://img.shields.io/github/license/ragaeeb/bitaboom) ![npm](https://img.shields.io/npm/v/bitaboom) ![npm](https://img.shields.io/npm/dm/bitaboom) ![GitHub issues](https://img.shields.io/github/issues/ragaeeb/bitaboom) ![GitHub stars](https://img.shields.io/github/stars/ragaeeb/bitaboom?style=social) ![GitHub Release](https://img.shields.io/github/v/release/ragaeeb/bitaboom) [![codecov](https://codecov.io/gh/ragaeeb/bitaboom/graph/badge.svg?token=7Z3E38HXCD)](https://codecov.io/gh/ragaeeb/bitaboom) [![Size](https://deno.bundlejs.com/badge?q=bitaboom@1.0.0&badge=detailed)](https://bundlejs.com/?q=bitaboom%401.0.0) ![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label&color=blue)
4
+
5
+ # Bitaboom - A String Utilities Library
6
+
7
+ 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 Vitest.
8
+
9
+ ## Installation
10
+
11
+ To install Bitaboom, use npm or yarn:
12
+
13
+ ```bash
14
+ npm install bitaboom
15
+ # or
16
+ yarn add bitaboom
17
+ # or
18
+ pnpm i bitaboom
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Import the library into your project:
24
+
25
+ ```typescript
26
+ import { functionName } from 'bitaboom';
27
+ ```
28
+
29
+ Use any function from the API in your code:
30
+
31
+ ```typescript
32
+ const result = functionName('inputString');
33
+ console.log(result);
34
+ ```
35
+
36
+ ## Available Functions
37
+
38
+ ### `addSpaceBeforeAndAfterPunctuation`
39
+
40
+ Adds spaces before and after punctuation marks except in specific cases like quoted text.
41
+
42
+ #### Example:
43
+
44
+ ```javascript
45
+ addSpaceBeforeAndAfterPunctuation('Text,word');
46
+ // Output: 'Text, word'
47
+ ```
48
+
49
+ ---
50
+
51
+ ### `addSpaceBetweenArabicTextAndNumbers`
52
+
53
+ Inserts spaces between Arabic text and numbers.
54
+
55
+ #### Example:
56
+
57
+ ```javascript
58
+ addSpaceBetweenArabicTextAndNumbers('الآية37');
59
+ // Output: 'الآية 37'
60
+ ```
61
+
62
+ ---
63
+
64
+ ### `applySmartQuotes`
65
+
66
+ Turns regular double quotes into smart quotes and fixes any incorrect starting quotes.
67
+
68
+ #### Example:
69
+
70
+ ```javascript
71
+ applySmartQuotes('The "quick brown" fox');
72
+ // Output: 'The “quick brown” fox'
73
+ ```
74
+
75
+ ---
76
+
77
+ ### `cleanExtremeArabicUnderscores`
78
+
79
+ Removes extreme Arabic underscores (ـ) from the beginning or end of lines. It does not affect Hijri dates or certain Arabic terms.
80
+
81
+ #### Example:
82
+
83
+ ```javascript
84
+ cleanExtremeArabicUnderscores('ـThis is a textـ');
85
+ // Output: "This is a text"
86
+ ```
87
+
88
+ ---
89
+
90
+ ### `cleanJunkFromText`
91
+
92
+ Cleans unnecessary spaces and punctuation from text.
93
+
94
+ #### Example:
95
+
96
+ ```javascript
97
+ cleanJunkFromText('Some text !@#\nAnother line.');
98
+ // Output: 'Some text\nAnother line.'
99
+ ```
100
+
101
+ ### `cleanLiteralNewLines`
102
+
103
+ Replaces literal new line characters (`\n`) with actual line breaks.
104
+
105
+ #### Example:
106
+
107
+ ```javascript
108
+ cleanLiteralNewLines('A\nB');
109
+ // Output: 'A\nB'
110
+ ```
111
+
112
+ ---
113
+
114
+ ### `cleanMultilines`
115
+
116
+ Removes trailing spaces from each line in a multiline string.
117
+
118
+ #### Example:
119
+
120
+ ```javascript
121
+ cleanMultilines(' This is a line \nAnother line ');
122
+ // Output: 'This is a line\nAnother line'
123
+ ```
124
+
125
+ ---
126
+
127
+ ### `cleanSymbolsAndPartReferences`
128
+
129
+ Removes various symbols, part references, and numerical markers from the text.
130
+
131
+ #### Example:
132
+
133
+ ```javascript
134
+ cleanSymbolsAndPartReferences('(1) (2/3)');
135
+ // Output: ''
136
+ ```
137
+
138
+ ---
139
+
140
+ ### `cleanTrailingPageNumbers`
141
+
142
+ Removes trailing page numbers formatted as `-[46]-` from the text.
143
+
144
+ #### Example:
145
+
146
+ ```javascript
147
+ cleanTrailingPageNumbers('This is some -[46]- text');
148
+ // Output: 'This is some text'
149
+ ```
150
+
151
+ ---
152
+
153
+ ### `convertUrduSymbolsToArabic`
154
+
155
+ Converts Urdu symbols like 'ھ' and 'ی' to their Arabic equivalents 'ه' and 'ي'.
156
+
157
+ #### Example:
158
+
159
+ ```javascript
160
+ convertUrduSymbolsToArabic('ھذا');
161
+ // Output: 'هذا'
162
+ ```
163
+
164
+ ---
165
+
166
+ ### `extractInitials`
167
+
168
+ Extracts initials from the input string, typically for names or titles.
169
+
170
+ #### Example:
171
+
172
+ ```javascript
173
+ extractInitials('Nayl al-Awtar');
174
+ // Output: 'NA'
175
+ ```
176
+
177
+ ### `fixTrailingWow`
178
+
179
+ Corrects unnecessary trailing "و" in greetings or phrases.
180
+
181
+ #### Example:
182
+
183
+ ```javascript
184
+ fixTrailingWow('السلام عليكم و رحمة');
185
+ // Output: 'السلام عليكم ورحمة'
186
+ ```
187
+
188
+ ---
189
+
190
+ ### `insertLineBreaksAfterPunctuation`
191
+
192
+ Adds line breaks after punctuation marks such as periods, exclamation points, and question marks.
193
+
194
+ #### Example:
195
+
196
+ ```javascript
197
+ insertLineBreaksAfterPunctuation('Text.');
198
+ // Output: 'Text.
199
+ '
200
+ ```
201
+
202
+ ---
203
+
204
+ ### `isJsonStructureValid`
205
+
206
+ 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.
207
+
208
+ #### Example:
209
+
210
+ ```javascript
211
+ isJsonStructureValid("{10: 'abc', 'key': 'value'}");
212
+ // Output: true
213
+ ```
214
+
215
+ ---
216
+
217
+ ### `isOnlyPunctuation`
218
+
219
+ Checks if the input string consists only of punctuation characters.
220
+
221
+ #### Example:
222
+
223
+ ```javascript
224
+ isOnlyPunctuation('!?');
225
+ // Output: true
226
+ ```
227
+
228
+ ---
229
+
230
+ ### `normalizeAlifVariants`
231
+
232
+ Simplifies all forms of 'alif' (أ, إ, and آ) to the basic 'ا'.
233
+
234
+ #### Example:
235
+
236
+ ```javascript
237
+ normalizeAlifVariants('أنا إلى الآفاق');
238
+ // Output: 'انا الى الافاق'
239
+ ```
240
+
241
+ ### `normalizeApostrophes`
242
+
243
+ Replaces various apostrophe characters like ‛, ’, and ‘ with the standard apostrophe (').
244
+
245
+ #### Example:
246
+
247
+ ```javascript
248
+ normalizeApostrophes('‛ulama’ al-su‘');
249
+ // Output: "'ulama' al-su'"
250
+ ```
251
+
252
+ ---
253
+
254
+ ### `normalizeArabicPrefixesToAl`
255
+
256
+ Replaces common Arabic prefixes like 'Al-', 'Ar-', 'Ash-', etc., with 'al-' in the text. It handles different variations of prefixes but does not modify cases where the second word does not start with 'S'.
257
+
258
+ #### Example:
259
+
260
+ ```javascript
261
+ normalizeArabicPrefixesToAl('Ash-Shafiee');
262
+ // Output: 'al-Shafiee'
263
+ ```
264
+
265
+ ---
266
+
267
+ ### `normalizeDoubleApostrophes`
268
+
269
+ Removes double occurrences of Arabic apostrophes such as ʿʿ or ʾʾ.
270
+
271
+ #### Example:
272
+
273
+ ```javascript
274
+ normalizeDoubleApostrophes('ʿulamāʾʾ');
275
+ // Output: 'ʿulamāʾ'
276
+ ```
277
+
278
+ ---
279
+
280
+ ### `normalizeJsonSyntax`
281
+
282
+ 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.
283
+
284
+ #### Example:
285
+
286
+ ```javascript
287
+ normalizeJsonSyntax("{10: 'abc', 20: 'def'}");
288
+ // Output: '{"10": "abc", "20": "def"}'
289
+ ```
290
+
291
+ ---
292
+
293
+ ### `normalizeTransliteratedEnglish`
294
+
295
+ Simplifies English transliterations by removing diacritics, apostrophes, and common prefixes.
296
+
297
+ #### Example:
298
+
299
+ ```javascript
300
+ normalizeTransliteratedEnglish('Al-Jadwāl');
301
+ // Output: 'Jadwal'
302
+ ```
303
+
304
+ ---
305
+
306
+ ### `normalize`
307
+
308
+ Normalizes the text by removing diacritics, apostrophes, and dashes.
309
+
310
+ #### Example:
311
+
312
+ ```javascript
313
+ normalize('Al-Jadwāl');
314
+ // Output: 'AlJadwal'
315
+ ```
316
+
317
+ ---
318
+
319
+ ### `removeArabicPrefixes`
320
+
321
+ Strips common Arabic prefixes like 'al-', 'bi-', 'fī', 'wa-', etc., from the beginning of words.
322
+
323
+ #### Example:
324
+
325
+ ```javascript
326
+ removeArabicPrefixes('al-Bukhari');
327
+ // Output: 'Bukhari'
328
+ ```
329
+
330
+ ---
331
+
332
+ ### `removeDeathYear`
333
+
334
+ Removes death year references like "(d. 390H)" and "[d. 100h]" from the text.
335
+
336
+ #### Example:
337
+
338
+ ```javascript
339
+ removeDeathYear('Sufyān ibn ‘Uyaynah (d. 198h)');
340
+ // Output: 'Sufyān ibn ‘Uyaynah'
341
+ ```
342
+
343
+ ---
344
+
345
+ ### `removeNonIndexSignatures`
346
+
347
+ Removes single-digit numbers and dashes from Arabic text but preserves numbers used as indexes.
348
+
349
+ #### Example:
350
+
351
+ ```javascript
352
+ removeNonIndexSignatures('الورقه 3 المصدر');
353
+ // Output: 'الورقه المصدر'
354
+ ```
355
+
356
+ ---
357
+
358
+ ### `removeNumbersAndDashes`
359
+
360
+ Removes numeric digits and dashes from the text.
361
+
362
+ #### Example:
363
+
364
+ ```javascript
365
+ removeNumbersAndDashes('ABC 123-Xyz');
366
+ // Output: 'ABC Xyz'
367
+ ```
368
+
369
+ ---
370
+
371
+ ### `removeSingleDigitReferences`
372
+
373
+ Removes single digit references like (1), «2», [3] from the text.
374
+
375
+ #### Example:
376
+
377
+ ```javascript
378
+ removeSingleDigitReferences('Ref (1), Ref «2», Ref [3]');
379
+ // Output: 'Ref , Ref , Ref '
380
+ ```
381
+
382
+ ---
383
+
384
+ ### `removeSingularCodes`
385
+
386
+ Removes Arabic letters or Arabic-Indic numerals enclosed in square brackets or parentheses.
387
+
388
+ #### Example:
389
+
390
+ ```javascript
391
+ removeSingularCodes('[س]');
392
+ // Output: ''
393
+ ```
394
+
395
+ ---
396
+
397
+ ### `removeSolitaryArabicLetters`
398
+
399
+ Removes solitary Arabic letters unless they are 'ha' used in Hijri years.
400
+
401
+ #### Example:
402
+
403
+ ```javascript
404
+ removeSolitaryArabicLetters('ب ا الكلمات ت');
405
+ // Output: 'ا الكلمات'
406
+ ```
407
+
408
+ ---
409
+
410
+ ### `removeUrls`
411
+
412
+ Removes URLs from the text.
413
+
414
+ #### Example:
415
+
416
+ ```javascript
417
+ removeUrls('Visit https://example.com');
418
+ // Output: 'Visit '
419
+ ```
420
+
421
+ ### `replaceAlifMaqsurah`
422
+
423
+ Replaces 'alif maqsurah' (ى) with 'ya' (ي).
424
+
425
+ #### Example:
426
+
427
+ ```javascript
428
+ replaceAlifMaqsurah('رؤيى');
429
+ // Output: 'رؤيي'
430
+ ```
431
+
432
+ ---
433
+
434
+ ### `replaceEnglishPunctuationWithArabic`
435
+
436
+ Replaces English punctuation marks (e.g., ? and ;) with their Arabic equivalents.
437
+
438
+ #### Example:
439
+
440
+ ```javascript
441
+ replaceEnglishPunctuationWithArabic('This; and, that?');
442
+ // Output: 'This؛and، that؟'
443
+ ```
444
+
445
+ ---
446
+
447
+ ### `replaceLineBreaksWithSpaces`
448
+
449
+ Replaces consecutive line breaks and whitespace characters with a single space.
450
+
451
+ #### Example:
452
+
453
+ ```javascript
454
+ replaceLineBreaksWithSpaces('a\nb');
455
+ // Output: 'a b'
456
+ ```
457
+
458
+ ---
459
+
460
+ ### `replaceSalutationsWithSymbol`
461
+
462
+ Replaces common salutations like "sallahu alayhi wasallam" with "ﷺ". Handles variations like 'peace and blessings be upon him'.
463
+
464
+ #### Example:
465
+
466
+ ```javascript
467
+ replaceSalutationsWithSymbol('Then Muḥammad (sallahu alayhi wasallam)');
468
+ // Output: 'Then Muḥammad ﷺ'
469
+ ```
470
+
471
+ ---
472
+
473
+ ### `replaceTaMarbutahWithHa`
474
+
475
+ Replaces 'ta marbutah' (ة) with 'ha' (ه).
476
+
477
+ #### Example:
478
+
479
+ ```javascript
480
+ replaceTaMarbutahWithHa('مدرسة');
481
+ // Output: 'مدرسه'
482
+ ```
483
+
484
+ ---
485
+
486
+ ### `splitByQuotes`
487
+
488
+ Splits a string by spaces but keeps quoted substrings intact. Substrings enclosed in double quotes are treated as a single part.
489
+
490
+ #### Example:
491
+
492
+ ```javascript
493
+ splitByQuotes('"This is" "a part of the" "string and"');
494
+ // Output: ["This is", "a part of the", "string and"]
495
+ ```
496
+
497
+ ### `stripAllDigits`
498
+
499
+ Removes all numeric digits from the text.
500
+
501
+ #### Example:
502
+
503
+ ```javascript
504
+ stripAllDigits('abc123');
505
+ // Output: 'abc'
506
+ ```
507
+
508
+ ---
509
+
510
+ ### `stripDiacritics`
511
+
512
+ Removes Arabic diacritics (tashkeel) and the elongation character (ـ).
513
+
514
+ #### Example:
515
+
516
+ ```javascript
517
+ stripDiacritics('مُحَمَّدٌ');
518
+ // Output: 'محمد'
519
+ ```
520
+
521
+ ---
522
+
523
+ ### `stripEnglishCharactersAndSymbols`
524
+
525
+ Removes English letters and symbols from the text.
526
+
527
+ #### Example:
528
+
529
+ ```javascript
530
+ stripEnglishCharactersAndSymbols('أحب & لنفسي');
531
+ // Output: 'أحب لنفسي'
532
+ ```
533
+
534
+ ---
535
+
536
+ ### `stripZeroWidthCharacters`
537
+
538
+ Removes zero-width characters like ZWJ and other invisible characters.
539
+
540
+ #### Example:
541
+
542
+ ```javascript
543
+ stripZeroWidthCharacters('يَخْلُوَ ‏.');
544
+ // Output: 'يَخْلُوَ .'
545
+ ```
546
+
547
+ ---