Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justgo97/arabic-utils
An NPM package designed for use in both browser and Node environments. It offers a range of convenient utilities specifically tailored for Arabic string manipulation, including functionalities like token search, removing diacritics and more.
https://github.com/justgo97/arabic-utils
arabic arabic-diacritics arabic-language diacritics javascript npm npm-package typescript
Last synced: about 2 months ago
JSON representation
An NPM package designed for use in both browser and Node environments. It offers a range of convenient utilities specifically tailored for Arabic string manipulation, including functionalities like token search, removing diacritics and more.
- Host: GitHub
- URL: https://github.com/justgo97/arabic-utils
- Owner: justgo97
- License: mit
- Created: 2023-06-16T16:46:17.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-01T14:32:12.000Z (9 months ago)
- Last Synced: 2024-11-11T08:38:14.448Z (2 months ago)
- Topics: arabic, arabic-diacritics, arabic-language, diacritics, javascript, npm, npm-package, typescript
- Language: TypeScript
- Homepage: https://arabic-utils.pages.dev
- Size: 630 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# arabic-utils
[![build](https://github.com/justgo97/arabic-utils/actions/workflows/release_package.yml/badge.svg)](https://github.com/justgo97/arabic-utils/actions) [![img](https://img.shields.io/npm/v/arabic-utils.svg)](https://www.npmjs.com/package/arabic-utils) [![img](https://img.shields.io/npm/dt/arabic-utils.svg)](https://www.npmjs.com/package/arabic-utils) [![img](https://img.shields.io/npm/l/arabic-utils.svg)](https://github.com/justgo97/arabic-utils/blob/main/LICENSE)
An NPM package designed for use in both browser and Node environments. It offers a range of convenient utilities specifically tailored for Arabic string manipulation, including functionalities like token search, removing diacritics and more.
# Installation
`npm install arabic-utils`
# Usage
```javascript
import { ArabicString } from "arabic-utils";
```### getMatches(searchToken: string, matchOptions?: IMatchOptions)
Retrieves the matched parts from the given Arabic text based on the search token.
Example:
```javascript
const input = "خُلقتَ طَليقاً كَطَيفِ النَّسيمِ";
const token = "النسيم";
console.log(ArabicString(input).getMatches(token))./*
* Output:
* [
* { text: "خُلقتَ طَليقاً كَطَيفِ ", isMatch: false },
* { text: "النَّسيمِ", isMatch: true },
* ]
*/
```### removeDiacritics()
Removes diacritics from the input string.
Example:
```javascript
const normalized = ArabicString("السَّلَامُ عَلَيْكُمُ").removeDiacritics();
console.log(normalized); // "السلام عليكم"
```### removeTatweel()
Removes ARABIC TATWEEL characters (U+0640) from an Arabic text string.
Example:
```javascript
console.log(ArabicString("كتــــــــــــــــاب").removeTatweel()); // "كتاب"
```### includes(searchString: string, position?: number)
Checks if the Arabic text includes a specified search string.
Example:
```javascript
console.log(ArabicString("السَّلَامُ عَلَيْكُمُ").includes("السلام")); // true
```### startsWith(searchString: string, position?: number)
Checks if the Arabic text starts with a specified search string.
Example:
```javascript
console.log(ArabicString("السَّلَامُ عَلَيْكُمُ").startsWith("السلام")); // true
```### normalizeAlef()
Normalizes the occurrence of the letters "آ", "إ", and "أ" in the given Arabic text by replacing them with the letter "ا".
Example:
```javascript
console.log(ArabicString("الآن").normalizeAlef()); // "الان"
```### remove(textToRemove: string)
Removes an occurrence of a specified text from an Arabic string.
Example:
```javascript
const newString = ArabicString("السَّلَامُ عَلَيْكُمُ").remove("السلام");
console.log(newString); // " عَلَيْكُمُ"
```### Notes:
Do not nest calls to `ArabicString` in each other it will cause undesired behavior
Example:
```javascript
import { ArabicString } from "arabic-utils";// ❌ This is invalid syntax
const newString = ArabicString("السلام عليكم").remove(
ArabicString("السَّلَامُ").removeDiacritics()
);
console.log(newString); // ""
``````javascript
import { ArabicString } from "arabic-utils";// ✅ This is valid
const normalizedToken = ArabicString("السَّلَامُ").removeDiacritics();
const newString = ArabicString("السلام عليكم").remove(normalizedToken);
console.log(newString); // " عليكم"
``````javascript
import { ArabicString, ArabicClass } from "arabic-utils";// ✅ This is also valid
const newString = ArabicString("السلام عليكم").remove(
ArabicClass.removeDiacritics("السَّلَامُ")
);
console.log(newString); // " عليكم"
```⚠️ More examples and use cases are in the [test files](/test/)
# Demo
Demo website to show the main functionalities of the package: [arabic-utils.pages.dev](https://arabic-utils.pages.dev/)
# License
[MIT](LICENSE)