├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── npm-publish.yml │ └── test.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── README_AR.md ├── example.html ├── jest.config.cjs ├── package-lock.json ├── package.json ├── src ├── constants │ ├── arabic-letters.ts │ ├── banned-words.ts │ ├── index.ts │ └── tashkeel.ts ├── index.ts ├── options.ts ├── scripts │ ├── index.ts │ └── scripts.ts └── utils │ ├── index.ts │ └── string.util.ts ├── tests ├── constants.test.ts └── scripts.test.ts ├── tsconfig.json └── webpack.config.cjs /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = tab 7 | indent_size = 4 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | end_of_line = lf 11 | trailing_comma = all 12 | bracket_spacing = true 13 | arrow_parens = always 14 | prose_wrap = preserve 15 | 16 | [*.ts] 17 | quote_type = single 18 | 19 | [*.md] 20 | max_line_length = off 21 | trim_trailing_whitespace = false 22 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /coverage 2 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'], 4 | plugins: ['@typescript-eslint', 'prettier'], 5 | rules: { 6 | 'prettier/prettier': [ 7 | 'error', 8 | { 9 | endOfLine: 'auto', 10 | }, 11 | ], 12 | }, 13 | env: { 14 | node: true, 15 | jest: true, 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | ## وصف المشكلة (Bug Description) 10 | 11 | يرجى وصف المشكلة التي تواجهها بوضوح هنا. يمكن أن تكون هذه المشكلة خللاً في السلوك الحالي للمكتبة أو الوظيفة، أو تنفيذًا غير صحيح لمتطلبات معينة. 12 | 13 | ## خطوات لإعادة إنتاج المشكلة (Steps to Reproduce) 14 | 15 | يرجى توضيح الخطوات اللازمة لإعادة إنتاج المشكلة بوضوح. يمكن أن تكون هذه الخطوات مفصلة لمساعدتنا على تحديد المشكلة وإصلاحها. 16 | 17 | 1. خطوة 1 18 | 2. خطوة 2 19 | 3. ... 20 | 21 | ## السياق الإضافي (Additional Context) 22 | 23 | هل هناك أي سياق إضافي يمكن أن يساعد في فهم المشكلة؟ يمكنك توضيح الظروف التي تسببت في ظهور هذا الخلل أو المزيد من التفاصيل التقنية حول البيئة التي كنت تعمل بها. 24 | 25 | ## بيئة العمل (Environment) 26 | 27 | يرجى توضيح البيئة التي كنت تستخدمها عند حدوث المشكلة. يمكن ذلك أن يشمل: 28 | 29 | - نسخة لغة البرمجة (مثل Python 3.8) 30 | - نظام التشغيل (مثل Windows 10 أو Ubuntu 20.04) 31 | - المكتبات البرمجية المعنية وإصداراتها 32 | 33 | ## السلوك المتوقع (Expected Behavior) 34 | 35 | صف بوضوح كيف ينبغي أن يكون سلوك المكتبة أو الوظيفة الصحيح. ما هو التصرف المتوقع في هذه الحالة؟ 36 | 37 | ## السيناريو الحالي (Current Behavior) 38 | 39 | صف بوضوح سلوك المكتبة أو الوظيفة الحالي الذي تعتبره خاطئًا أو يسبب المشكلة. 40 | 41 | ## الخطوات المقترحة (Proposed Solution) 42 | 43 | إذا كنت تعتقد أنك تعرف السبب ولديك اقتراح لحل المشكلة، يرجى توضيحه هنا. يمكنك تقديم أفكار أو رؤية لكيفية إصلاح الخلل. 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | --- 8 | 9 | ## وصف الفكرة (Feature Idea) 10 | 11 | يرجى وصف الفكرة أو الميزة الجديدة التي تود إضافتها إلى المشروع بوضوح هنا. يمكن أن تكون هذه الفكرة ميزة جديدة أو تحسين على ميزة موجودة. 12 | 13 | ## الهدف (Goal) 14 | 15 | ما الهدف من هذه الميزة؟ ما الفائدة التي ستقدمها للمستخدمين والمطورين؟ يرجى توضيح الفائدة والقيمة المضافة التي ستحققها هذه الفكرة. 16 | 17 | ## سياق الاستخدام (Use Case) 18 | 19 | يرجى توضيح سيناريوهات الاستخدام التي تتطلب هذه الميزة. ما هي الحالات التي ستُستخدم فيها؟ وما الأوضاع التي تحتاج إلى هذه الميزة؟ 20 | 21 | ## توصيف تفصيلي (Detailed Description) 22 | 23 | يرجى تقديم توصيف مفصل لكيفية عمل هذه الميزة والتفاصيل الفنية اللازمة لتنفيذها. يمكنك توضيح واجهة المستخدم المقترحة، وكيفية تفاعل المستخدم مع الميزة، وأي تأثيرات قد تكون لها على المشروع. 24 | 25 | ## السياق الإضافي (Additional Context) 26 | 27 | هل هناك أي سياق إضافي يمكن أن يساعد في فهم الفكرة وأهميتها؟ يمكنك توضيح المزيد من التفاصيل التقنية أو وضع روابط لموارد مرتبطة بالفكرة. 28 | 29 | ## الأهمية (Priority) 30 | 31 | هل تعتبر هذه الميزة ذات أهمية عالية أم منخفضة؟ يرجى تحديد درجة الأهمية بوضوح. 32 | 33 | - [ ] عالية الأهمية 34 | - [ ] متوسطة الأهمية 35 | - [ ] منخفضة الأهمية 36 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## وصف الفكرة (Feature Idea) 2 | 3 | يرجى وصف الفكرة أو الميزة الجديدة التي تود إضافتها إلى المشروع بوضوح هنا. يمكن أن تكون هذه الفكرة ميزة جديدة أو تحسين على ميزة موجودة. 4 | 5 | ## الهدف (Goal) 6 | 7 | ما الهدف من هذه الميزة؟ ما الفائدة التي ستقدمها للمستخدمين والمطورين؟ يرجى توضيح الفائدة والقيمة المضافة التي ستحققها هذه الفكرة. 8 | 9 | ## سياق الاستخدام (Use Case) 10 | 11 | يرجى توضيح سيناريوهات الاستخدام التي تتطلب هذه الميزة. ما هي الحالات التي ستُستخدم فيها؟ وما الأوضاع التي تحتاج إلى هذه الميزة؟ 12 | 13 | ## توصيف تفصيلي (Detailed Description) 14 | 15 | يرجى تقديم توصيف مفصل لكيفية عمل هذه الميزة والتفاصيل الفنية اللازمة لتنفيذها. يمكنك توضيح واجهة المستخدم المقترحة، وكيفية تفاعل المستخدم مع الميزة، وأي تأثيرات قد تكون لها على المشروع. 16 | 17 | ## السياق الإضافي (Additional Context) 18 | 19 | هل هناك أي سياق إضافي يمكن أن يساعد في فهم الفكرة وأهميتها؟ يمكنك توضيح المزيد من التفاصيل التقنية أو وضع روابط لموارد مرتبطة بالفكرة. 20 | 21 | ## الأهمية (Priority) 22 | 23 | هل تعتبر هذه الميزة ذات أهمية عالية أم منخفضة؟ يرجى تحديد درجة الأهمية بوضوح. 24 | 25 | - [ ] عالية الأهمية 26 | - [ ] متوسطة الأهمية 27 | - [ ] منخفضة الأهمية 28 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish Package to npmjs 2 | 3 | # Trigger this workflow when a release is published 4 | on: 5 | release: 6 | types: [published] 7 | 8 | jobs: 9 | build: 10 | # Specify the runner environment 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | # Step 1: Check out the repository's code 15 | - name: Check out repository 16 | uses: actions/checkout@v4 17 | 18 | # Step 2: Set up Node.js environment 19 | - name: Set up Node.js 20 | uses: actions/setup-node@v3 21 | with: 22 | node-version: '20.x' # Specify the Node.js version 23 | registry-url: 'https://registry.npmjs.org' 24 | 25 | # Step 3: Install dependencies using npm ci 26 | - name: Install dependencies 27 | run: npm ci 28 | 29 | # Step 4: Publish the package to npm 30 | - name: Publish to npm 31 | run: npm publish 32 | env: 33 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 34 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | strategy: 12 | matrix: 13 | node-version: [16.x] 14 | 15 | steps: 16 | - name: Checkout repository 17 | uses: actions/checkout@v2 18 | 19 | - name: Use Node.js ${{ matrix.node-version }} 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: ${{ matrix.node-version }} 23 | 24 | - name: Cache Node.js modules 25 | uses: actions/cache@v2 26 | with: 27 | path: ~/.npm 28 | key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} 29 | restore-keys: | 30 | ${{ runner.OS }}-node- 31 | 32 | - name: Install dependencies 33 | run: npm ci 34 | 35 | - name: Run build and tests 36 | run: npm run build && npm test 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node modules 2 | node_modules/ 3 | 4 | # TypeScript build output 5 | dist/ 6 | 7 | # Logs 8 | npm-debug.log* 9 | yarn-debug.log* 10 | yarn-error.log* 11 | 12 | # OS generated files 13 | .DS_Store 14 | Thumbs.db 15 | 16 | # Test results and coverage 17 | coverage/ 18 | *.test.ts.snap 19 | 20 | # Environment variables 21 | .env 22 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Source files (TypeScript) 2 | src/ 3 | 4 | # Testing 5 | __tests__/ 6 | coverage/ 7 | jest.config.js 8 | *.test.ts 9 | *.test.ts.snap 10 | 11 | # Configurations 12 | tsconfig.json 13 | 14 | # IDE and Editor files 15 | .vscode/ 16 | .idea/ 17 | *.swp 18 | *.swo 19 | 20 | # OS generated files 21 | .DS_Store 22 | Thumbs.db 23 | 24 | # Logs 25 | npm-debug.log* 26 | yarn-debug.log* 27 | yarn-error.log* 28 | 29 | # Other files 30 | .gitignore 31 | README.md.orig 32 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | /dist 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/prettierrc", 3 | "printWidth": 120, 4 | "tabWidth": 4, 5 | "useTabs": true, 6 | "semi": true, 7 | "singleQuote": true, 8 | "quoteProps": "as-needed", 9 | "trailingComma": "all", 10 | "bracketSpacing": true, 11 | "bracketSameLine": false, 12 | "arrowParens": "always", 13 | "htmlWhitespaceSensitivity": "css", 14 | "endOfLine": "lf", 15 | "embeddedLanguageFormatting": "auto", 16 | "insertPragma": false, 17 | "requirePragma": false, 18 | "proseWrap": "preserve" 19 | } 20 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": ["ALEF", "DOTLESS", "Tashkeel", "Tatweel"], 3 | "formattingToggle.affects": ["editor.formatOnSave"], 4 | "editor.formatOnSave": true, 5 | "editor.defaultFormatter": "esbenp.prettier-vscode", 6 | "editor.codeActionsOnSave": { 7 | "source.organizeImports": "explicit" 8 | }, 9 | "prettier.configPath": ".prettierrc", 10 | "prettier.printWidth": 120, 11 | "prettier.tabWidth": 4, 12 | "prettier.singleQuote": true, 13 | "prettier.trailingComma": "all", 14 | "javascript.updateImportsOnFileMove.enabled": "always", 15 | "typescript.updateImportsOnFileMove.enabled": "always", 16 | "javascript.preferences.importModuleSpecifier": "relative", 17 | "typescript.preferences.importModuleSpecifier": "relative" 18 | } 19 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 |

📜 Changelog - سجل التغيير

2 |

All notable changes to this project will be documented in this file.

3 | 4 | ## [Unreleased](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.7...HEAD) 5 | 6 | ## [1.0.7](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.7) - 2024-01-19 (07 Rajab 1445) 7 | 8 | ### Updated 9 | 10 | - **Improved Old Arabic Letters** in [PR #25](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/pull/25): Introduced options for handling specific Arabic characters to avoid distortion issues in certain fonts or text editors. These enhancements include: 11 | - `replaceMidNoonWithBah`: An option to transform the mid-word Noon character to a dotless Bah (enabled by default). 12 | - `replaceMidYahWithBah`: An option to transform the mid-word Yah character to a dotless Bah (disabled by default). 13 | 14 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.6...v1.0.7) 15 | 16 | ## [1.0.6](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.6) - 2023-12-03 (19 Jumada al-awwal 1445) 17 | 18 | ### Fixed 19 | 20 | - Remove Arabic Affixes does not work with sentences ([#21](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/21)) 21 | 22 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.5...v1.0.6) 23 | 24 | ## [1.0.5](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.5) - 2023-12-03 (19 Jumada al-awwal 1445) 25 | 26 | ### Updated 27 | 28 | - Trim text before converting ([#22](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/22)) 29 | 30 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.4...v1.0.5) 31 | 32 | ## [1.0.4](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.4) - 2023-11-30 (16 Jumada al-awwal 1445) 33 | 34 | ### Updated 35 | 36 | - rename `Panned` to `Banned`: which is the correct translation of `محظور` ([PR #19](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/pull/19)) 37 | 38 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.3...v1.0.4) 39 | 40 | ## [1.0.3](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.3) - 2023-11-18 (04 Jumada al-awwal 1445) 41 | 42 | ### Added 43 | 44 | - Convert To Old Arabic And Tashfeer Banned Words: Transform Arabic text into old script and replace Banned Arabic text with visually similar characters for encoding purposes. (Banned words are words that considered as hate speech in social media) ([#18](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/18)) 45 | 46 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.2...v1.0.3) 47 | 48 | ## [1.0.2](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.2) - 2023-11-18 (04 Jumada al-awwal 1445) 49 | 50 | ### Added 51 | 52 | - Tashfeer Banned Words: Replaces Banned Arabic text with visually similar characters for encoding purposes. (Banned words are words that considered as hate speech in social media) ([#16](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/16)) 53 | - Remove Arabic Affixes: Removes predefined affixes (prefixes and suffixes) from an Arabic word if it starts or ends with those affixes. ([#17](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/17)) 54 | 55 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/v1.0.1...v1.0.2) 56 | 57 | ## [1.0.1](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/v1.0.1) - 2023-11-15 (Jumada al-awwal 1445) 58 | 59 | ### Added 60 | 61 | - Word To Letters: Convert Arabic word to its pronounced letters. ([#2](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/2)) 62 | 63 | [Full Changelog](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/compare/1.0.0...v1.0.1) 64 | 65 | ## [1.0.0](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/releases/tag/1.0.0) - 2023-11-07 (23 Rabi` al Thani 1445) 66 | 67 | ### Added 68 | 69 | - Initial release of the library with the following functionalities: 70 | - Tashkeel Removal: Easily remove Tashkeel from Arabic text. ([#12](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/12)) 71 | - Tatweel Removal: Remove Tatweel character from Arabic phrases. ([#8](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/8)) 72 | - Convert To Old Arabic: Transform Arabic text into old script. ([#9](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/9)) 73 | - Tashfeer: Replaces Arabic text with visually similar characters for encoding purposes. ([#13](https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues/13)) 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 |

Arabic Services JavaScript

8 | 9 |

10 | بعض الخدمات البرمجية على نصوص اللغة العربية 11 |
12 | A versatile library offering utility functions for processing and transforming Arabic text. 13 | Can be used in Node.js and the browser. 14 | 15 |

16 | 17 | 36 | 37 | ## 📋 Features 38 | 39 | - **Tashkeel Removal**: Easily remove Tashkeel from Arabic text. 40 | - **Tatweel Removal**: Remove Tatweel character from Arabic phrases. 41 | - **Convert To Old Arabic**: Transform Arabic text into old script. 42 | - **Convert To Old Arabic And Tashfeer Banned Words**: Transform Arabic text into old script and replace Banned Arabic text with visually similar characters for encoding purposes. (Banned words are words that considered as hate speech in social media) 43 | - **Tashfeer**: Replaces Arabic text with visually similar characters for encoding purposes. 44 | - **Tashfeer Banned Words**: Replaces Banned Arabic text with visually similar characters for encoding purposes. (Banned words are words that considered as hate speech in social media) 45 | - **Remove Arabic Affixes**: Removes predefined affixes (prefixes and suffixes) from an Arabic word if it starts or ends with those affixes. 46 | - **Word To Letters**: Convert Arabic word to its pronounced letters. 47 | - ... and more! 48 | 49 |

➡️ Check out the usage and detailed documentation on each feature ⬅️

50 | 51 | ## 🚀 Getting Started 52 | 53 | Arabic-Services was designed to work in both the browser and NodeJS applications. 54 | 55 | ### Browser 56 | 57 | We provide both ESM and UMD bundles for use in the browser. 58 | You can find it with the latest release files. 59 | 60 | ```html 61 | 62 | 66 | ``` 67 | 68 | ### NodeJS 69 | 70 | Both CommonJS and ES Module libraries are provided. 71 | 72 | ```bash 73 | npm install arabic-services 74 | ``` 75 | 76 | **CommonJS:** 77 | 78 | ```javascript 79 | const { ArabicServices } = require('arabic-services'); 80 | console.log(ArabicServices.removeTashkeel('الخَيْلُ وَاللّيْلُ وَالبَيْداءُ تَعرِفُني')); 81 | // Output: 'الخيل والليل والبيداء تعرفني' 82 | ``` 83 | 84 | **ES Module:** 85 | 86 | ```javascript 87 | import { ArabicServices } from 'arabic-services'; 88 | console.log(ArabicServices.removeTashkeel('الخَيْلُ وَاللّيْلُ وَالبَيْداءُ تَعرِفُني')); 89 | // Output: 'الخيل والليل والبيداء تعرفني' 90 | ``` 91 | 92 | ## 💡 Contributing 93 | 94 | Arabic Services is made publicly available to provide a well tested and well documented library for processing and transforming Arabic text to all developers. We accept feature contributions provided that they are properly documented and include the appropriate unit tests. 95 | 96 | - 🚀 If you want to contribute to this project and make it better with new ideas, your pull request is very welcomed. 97 | - 📝 If you find any issue just put it in the repository issue section, thank you. 98 | 99 | ## 🌟 Star this repository 100 | 101 | Please ⭐️ this repo and share it with others 102 | 103 | ## 📜 License 104 | 105 | This project is licensed under the GPL-3.0 License. See the [LICENSE](./LICENSE) file for more details. 106 | 107 | ## 💬 Contact 108 | 109 | - 📩 Email: [SeenDevelopment@gmail.com](mailto:SeenDevelopment@gmail.com) 110 | - 🌎 [Website](https://seen-arabic.github.io/) 111 | -------------------------------------------------------------------------------- /README_AR.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 |
6 | 7 |

خدمات اللغة العربية بلغة جافا سكريبت

8 | 9 |

10 | مكتبة متنوعة تقدم وظائف مساعدة لمعالجة وتحويل النصوص العربية. 11 | يمكن استخدامها في Node.js والمتصفح. 12 |

13 | 14 | 33 | 34 | ## 📋 الميزات 35 | 36 | - **إزالة التشكيل:** إزالة التشكيل من النص العربي. 37 | - **إزالة التطويل:** إزالة أحرف التطويل غير الضرورية من العبارات العربية. 38 | - **التحويل إلى العربية القديمة:** تحويل النص العربي إلى الخط العربي القديم. 39 | - **التحويل إلى العربية القديمة وتشفير الكلمات المحظورة:** تحويل النص العربي إلى الخط العربي القديم واستبدال النصوص العربية المحظورة بأحرف مشابهة بصريًا لأغراض الترميز. (الكلمات المحظورة هي الكلمات التي تعتبر كلمات مسيئة في وسائل التواصل الاجتماعي) 40 | - **التشفير:** استبدال النص العربي بأحرف مشابهة بصريًا لأغراض الترميز. 41 | - **تشفير الكلمات المحظورة:** استبدال النصوص العربية المحظورة بأحرف مشابهة بصريًا لأغراض الترميز. (الكلمات المحظورة هي الكلمات التي تعتبر كلمات مسيئة في وسائل التواصل الاجتماعي) 42 | - **إزالة اللواحق العربية:** إزالة اللواحق المحددة (البادئات واللاحقات) من كلمة عربية إذا بدأت أو انتهت بهذه اللواحق. 43 | - **الكلمة إلى حروفها:** تحويل الكلمة العربية إلى حروفها المنطوقة. 44 | - ...والمزيد! 45 | 46 |

➡️ شاهد استخدام كل ميزة من المكتبة وطريقة استخدامها في الكود ⬅️

47 | 48 | ## 🚀 التثبيت 49 | 50 | تم تصميم خدمات العربية لتعمل في كل من المتصفح وتطبيقات NodeJS. 51 | 52 | ### المتصفح 53 | 54 | نوفر حزم ESM و UMD للاستخدام في المتصفح. يمكن العثور عليها مع ملفات الإصدار الأخير. 55 | 56 | ```html 57 | 58 | 62 | ``` 63 | 64 | ### NodeJS 65 | 66 | تم توفير مكتبات CommonJS و ES Module. 67 | 68 | ```bash 69 | npm install arabic-services 70 | ``` 71 | 72 | **CommonJS:** 73 | 74 | ```javascript 75 | const { ArabicServices } = require('arabic-services'); 76 | console.log(ArabicServices.removeTashkeel('الخَيْلُ وَاللّيْلُ وَالبَيْداءُ تَعرِفُني')); 77 | // Output: 'الخيل والليل والبيداء تعرفني' 78 | ``` 79 | 80 | **ES Module:** 81 | 82 | ```javascript 83 | import { ArabicServices } from 'arabic-services'; 84 | console.log(ArabicServices.removeTashkeel('الخَيْلُ وَاللّيْلُ وَالبَيْداءُ تَعرِفُني')); 85 | // Output: 'الخيل والليل والبيداء تعرفني' 86 | ``` 87 | 88 | ## 💡 المساهمة 89 | 90 | تم إتاحة خدمات اللغة العربية للجمهور لتوفير مكتبة مُجربة جيدًا وموثقة بشكل جيد لمعالجة وتحويل النصوص العربية لجميع المطورين. نحن نقبل مساهمات الميزات بشرط أن تكون موثقة بشكل صحيح وتشمل الاختبارات المناسبة. 91 | 92 | - 🚀 إذا كنت ترغب في المساهمة في هذا المشروع وتحسينه بأفكار جديدة، فبإمكانك عمل pull request وطلبك مرحب به للغاية. 93 | - 📝 إذا وجدت أي مشكلة، فقط ضعها في قسم الـIssues في المستودع، شكرًا لك. 94 | 95 |
96 |

🌟 ضع نجمة على هذا المستودع 🌟

97 | 98 | من فضلك ضع ⭐️ على هذا المستودع وشاركه مع الآخرين 99 | 100 |
101 | 102 |
103 | 104 | ## 📜 الرخصة 105 | 106 | هذا المشروع مرخص تحت رخصة GPL-3.0. انظر ملف [الرخصة](./LICENSE) لمزيد من التفاصيل. 107 | 108 | ## 💬 الاتصال 109 | 110 | - 📩 البريد الإلكتروني: [SeenDevelopment@gmail.com](mailto:SeenDevelopment@gmail.com) 111 | - 🌎 [الموقع الإلكتروني](https://seen-arabic.github.io/) 112 | -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 12 | 13 | 14 | 15 | 16 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /jest.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'ts-jest', 3 | testEnvironment: 'node', 4 | testMatch: ['**/tests/**/*.ts'], 5 | collectCoverage: true, 6 | collectCoverageFrom: ['src/**/*.ts'], 7 | coverageDirectory: 'coverage', 8 | }; 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arabic-services", 3 | "version": "1.0.7", 4 | "description": "Utility functions on Arabic text", 5 | "main": "./dist/index.js", 6 | "types": "./dist/index.d.ts", 7 | "scripts": { 8 | "dev": "ts-node src/index.ts", 9 | "build": "tsc", 10 | "clean": "rimraf dist", 11 | "test": "jest --config jest.config.cjs --coverage", 12 | "prepublishOnly": "npm run build", 13 | "format": "npx prettier --write . --ignore-path .gitignore", 14 | "lint": "eslint \"src/**/*.{ts,tsx}\" --quiet", 15 | "lint:fix": "eslint \"src/**/*.{ts,tsx}\" --fix", 16 | "bundle": "webpack" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/Seen-Arabic/Arabic-Services-JavaScript.git" 21 | }, 22 | "keywords": [ 23 | "arabic", 24 | "arabic-services", 25 | "services", 26 | "old-arabic", 27 | "nlp", 28 | "tashkeel", 29 | "tatweel", 30 | "dotless arabic", 31 | "language" 32 | ], 33 | "author": { 34 | "name": "Seen Arabic", 35 | "email": "SeenDevelopment@gmail.com", 36 | "url": "http://seen-arabic.github.io" 37 | }, 38 | "license": "GPL-3.0", 39 | "bugs": { 40 | "url": "https://github.com/Seen-Arabic/Arabic-Services-JavaScript/issues" 41 | }, 42 | "homepage": "https://github.com/Seen-Arabic/Arabic-Services-JavaScript#readme", 43 | "devDependencies": { 44 | "@types/jest": "^29.5.5", 45 | "@typescript-eslint/eslint-plugin": "^6.7.5", 46 | "@typescript-eslint/parser": "^6.7.5", 47 | "eslint": "^8.51.0", 48 | "eslint-config-prettier": "^9.0.0", 49 | "eslint-plugin-prettier": "^5.0.1", 50 | "jest": "^29.7.0", 51 | "prettier": "^3.0.3", 52 | "ts-jest": "^29.1.1", 53 | "ts-loader": "^9.5.0", 54 | "typescript": "^5.2.2", 55 | "webpack": "^5.89.0", 56 | "webpack-cli": "^5.1.4" 57 | } 58 | } -------------------------------------------------------------------------------- /src/constants/arabic-letters.ts: -------------------------------------------------------------------------------- 1 | export const ARABIC_DOTLESS_DICT: { [key: string]: string } = { 2 | ا: 'ا', 3 | أ: 'ا', 4 | إ: 'ا', 5 | آ: 'ا', 6 | ٱ: 'ا', 7 | ء: '', 8 | ب: '\u066E', // Dotless Beh in all four contextual forms. 9 | پ: '\u066E', 10 | ت: '\u066E', 11 | ث: '\u066E', 12 | ج: 'ح', 13 | چ: 'ح', 14 | خ: 'ح', 15 | ح: 'ح', 16 | د: 'د', 17 | ذ: 'د', 18 | ر: 'ر', 19 | ز: 'ر', 20 | ژ: 'ر', 21 | س: 'س', 22 | ش: 'س', 23 | ص: 'ص', 24 | ض: 'ص', 25 | ط: 'ط', 26 | ظ: 'ط', 27 | ع: 'ع', 28 | غ: 'ع', 29 | ف: 'ڡ', 30 | ڤ: 'ڡ', 31 | ق: 'ٯ', 32 | ك: 'ک', 33 | گ: 'ک', 34 | ل: 'ل', 35 | م: 'م', 36 | ن: '\u06BA', // Dotless Noon in all four contextual forms, however most fonts shows dots in initial and medial forms 37 | ه: 'ه', 38 | و: 'و', 39 | ؤ: 'و', 40 | ة: 'ه', 41 | ى: '\u0649', // Dotless Yeh in all four contextual forms, however some fonts shows final form in all cases 42 | ي: '\u0649', 43 | ئ: '\u0649', 44 | }; 45 | 46 | export const STANDARD_LETTERS: string[] = [ 47 | 'ا', 48 | 'أ', 49 | 'آ', 50 | 'إ', 51 | 'ب', 52 | 'ت', 53 | 'ث', 54 | 'ح', 55 | 'ج', 56 | 'خ', 57 | 'د', 58 | 'ذ', 59 | 'ر', 60 | 'ز', 61 | 'س', 62 | 'ش', 63 | 'ص', 64 | 'ض', 65 | 'ط', 66 | 'ظ', 67 | 'ع', 68 | 'غ', 69 | 'ف', 70 | 'ق', 71 | 'ك', 72 | 'ل', 73 | 'م', 74 | 'ن', 75 | 'ه', 76 | 'و', 77 | 'ؤ', 78 | 'ي', 79 | 'ى', 80 | 'ئ', 81 | ]; 82 | 83 | export const PRONOUNCED_LETTERS: { [key: string]: string } = { 84 | ا: 'ألف', 85 | إ: 'ألف_مكسورة', 86 | أ: 'ألف ', 87 | آ: 'ألف_مد', 88 | ء: 'همزة', // Not in STANDARD_LETTERS[] 89 | ب: 'باء', 90 | ت: 'تاء', 91 | ث: 'ثاء', 92 | ج: 'جيم', 93 | ح: 'حاء', 94 | خ: 'خاء', 95 | د: 'دال', 96 | ذ: 'ذال', 97 | ر: 'راء', 98 | ز: 'زاي', 99 | س: 'سين', 100 | ش: 'شين', 101 | ص: 'صاد', 102 | ض: 'ضاد', 103 | ط: 'طاء', 104 | ظ: 'ظاء', 105 | ع: 'عين', 106 | غ: 'غين', 107 | ف: 'فاء', 108 | ق: 'قاف', 109 | ك: 'كاف', 110 | ل: 'لام', 111 | م: 'ميم', 112 | ن: 'نون', 113 | ه: 'هاء', 114 | و: 'واو', 115 | ؤ: 'همزة_متوسطة_مضمومة', 116 | ى: 'ألف_لينة', 117 | ي: 'ياء', 118 | ئ: 'همزة_متوسطة_مكسورة', 119 | ة: 'تاء_مربوطة', // Not in STANDARD_LETTERS[] 120 | }; 121 | 122 | export const LETTERS_TASHFEER_REPLACEMENT_DICT: { [key: string]: string[] } = { 123 | ا: ['|', '1', '!', 'ן', 'ן', 'ו', 'ⴶ'], 124 | ب: ['ٮ', 'ٻ', 'پ', 'ڀ', 'ٹ', 'ޞ', 'ސ', 'ݐ', 'ݒ', 'ݕ'], 125 | ت: ['ٮ', 'ٹ', 'ٺ', 'ټ', 'ٽ', 'ٿ', 'ސ', 'ڌ', 'ݓ'], 126 | ث: ['ٮ', 'ٹ', 'ٽ', 'ٿ', 'ޝ', 'ސ'], 127 | ح: ['ح', '7'], 128 | ج: ['ڃ', 'ڄ', 'چ', 'ڇ', 'ݘ'], 129 | خ: ['ح', 'ځ', 'ݗ'], 130 | د: ['ڈ', 'ډ', 'ڊ', 'ڍ', 'ݙ', 'ݚ', 'ב', 'כ'], 131 | ذ: ['ڈ', 'ڏ', 'ۮ', 'נ'], 132 | ر: ['ړ', 'ڕ', 'ږ', 'ݛ'], 133 | ز: ['ڑ', 'ڙ', 'ر', 'ژ', 'ږ', 'ۯ', 'ݫ', 'ݬ'], 134 | س: ['ނ', 'ښ', 'ݜ', 'ݭ'], 135 | ش: ['ښ', 'ݜ', 'ݭ', 'שׂ'], 136 | ص: ['صـު'], 137 | ض: ['ص', 'ض'], 138 | ط: ['ط'], 139 | ظ: ['ط', 'ظ'], 140 | ع: ['ݟ', 'ݝ'], 141 | غ: ['ڠ', 'ݝ', 'ݞ', 'ݟ', 'ع'], 142 | ف: ['ڡ', 'ڤ', 'ڦ', 'ڨ', 'ݠ', 'ݡ', 'ڡْ'], 143 | ق: ['ٯ', 'ڨ'], 144 | ك: ['ڬ', 'ڭ', 'ک', 'ڪ', 'ګ', 'گ', 'ڱ', 'ڳ', 'ݤ'], 145 | ل: ['ڵ', 'ݪ'], 146 | م: ['ݥ', 'ݦ', 'ޘ', 'ތ', 'ס', 'ם'], 147 | ن: ['ں', 'ڻ', 'ڼ', 'ڽ', 'ݔ', 'ݖ', 'ݧ', 'ݨ', 'ݩ'], 148 | ه: ['ۀ', 'ہ', 'ۂ', 'ۃ', 'ۿ'], 149 | و: ['ۅ', 'ۆ', 'ۇ', 'ۈ', 'ۏ', 'ۉ', 'ۋ'], 150 | ي: ['ۍ', 'ێ', 'ې', 'ے', 'ی۪'], 151 | }; 152 | 153 | export const ALONE_LETTERS = ['د', 'ذ', 'ر', 'ز', 'و', 'ا', 'أ', 'إ', 'ء', 'ؤ', 'آ']; 154 | 155 | export const ALEF: string[] = ['أ', 'إ', 'آ']; 156 | export const YAA: string[] = ['ى', 'ئ']; 157 | export const WAW: string[] = ['ؤ']; 158 | 159 | /** 160 | * Array of common Arabic prefixes. These prefixes are used in the removeArabicPrefix function 161 | * to identify and remove them from the beginning of Arabic words. 162 | */ 163 | export const ARABIC_PREFIXES = ['أ', 'ا', 'إ', 'ال', 'ي', 'ت', 'ن', 'ب']; 164 | 165 | /** 166 | * Array of common Arabic suffixes. These suffixes might be used in other functions 167 | * to identify and manipulate them at the end of Arabic words. 168 | */ 169 | export const ARABIC_SUFFIXES = ['ة', 'ه', 'ي', 'ى', 'ية', 'ين', 'ون', 'هم']; 170 | -------------------------------------------------------------------------------- /src/constants/banned-words.ts: -------------------------------------------------------------------------------- 1 | export const BANNED_WORDS = [ 2 | 'فلسطين', 3 | 'عرب', 4 | 'هود', 5 | 'صهيون', 6 | 'سرائيل', 7 | 'دول', 8 | 'كيان', 9 | 'حتل', 10 | 'هتلر', 11 | 'خنازير', 12 | 'حي', 13 | 'شيخ', 14 | 'جراح', 15 | 'سقط', 16 | 'قدس', 17 | 'قصى', 18 | 'طبع', 19 | 'قتل', 20 | 'خان', 21 | 'كتائب', 22 | 'عز', 23 | 'دين', 24 | 'قسام', 25 | 'جهاد', 26 | 'جاهد', 27 | 'سلام', 28 | 'خوارزم', 29 | 'لوغاريزم', 30 | 'كتاب', 31 | 'بدون', 32 | 'نقط', 33 | 'مارك', 34 | 'لعن', 35 | 'حقير', 36 | 'موت', 37 | 'قاوم', 38 | 'زوربير', 39 | 'عاصم', 40 | 'حر', 41 | 'رهاب', 42 | 'قرد', 43 | 'دعم', 44 | 'غز', 45 | 'نقذ', 46 | 'نتهك', 47 | 'معايير', 48 | 'صل', 49 | 'بان', 50 | 'دون', 51 | 'جيش', 52 | 'عدو', 53 | 'حماس', 54 | 'كر', 55 | ]; 56 | -------------------------------------------------------------------------------- /src/constants/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | ARABIC_DOTLESS_DICT, 3 | ARABIC_PREFIXES, 4 | ARABIC_SUFFIXES, 5 | PRONOUNCED_LETTERS, 6 | STANDARD_LETTERS, 7 | } from './arabic-letters'; 8 | export { BANNED_WORDS } from './banned-words'; 9 | export { TASHKEEL } from './tashkeel'; 10 | -------------------------------------------------------------------------------- /src/constants/tashkeel.ts: -------------------------------------------------------------------------------- 1 | export const TASHKEEL: string[] = [ 2 | '\u0600', 3 | '\u0601', 4 | '\u0602', 5 | '\u0603', 6 | '\u0604', 7 | '\u0605', 8 | '\u0610', 9 | '\u0611', 10 | '\u0612', 11 | '\u0613', 12 | '\u0614', 13 | '\u0615', 14 | '\u0616', 15 | '\u0617', 16 | '\u0618', 17 | '\u0619', 18 | '\u061A', 19 | '\u064B', 20 | '\u064C', 21 | '\u064D', 22 | '\u064E', 23 | '\u064F', 24 | '\u0650', 25 | '\u0651', 26 | '\u0652', 27 | '\u0653', 28 | '\u0654', 29 | '\u0655', 30 | '\u0656', 31 | '\u0657', 32 | '\u0658', 33 | '\u0659', 34 | '\u065A', 35 | '\u065B', 36 | '\u065C', 37 | '\u065D', 38 | '\u065E', 39 | '\u065F', 40 | '\u0670', 41 | '\u0674', 42 | '\u06D6', 43 | '\u06D7', 44 | '\u06D8', 45 | '\u06D9', 46 | '\u06DA', 47 | '\u06DB', 48 | '\u06DC', 49 | '\u06DF', 50 | '\u06E0', 51 | '\u06E1', 52 | '\u06E2', 53 | '\u06E3', 54 | '\u06E4', 55 | '\u06E5', 56 | '\u06E6', 57 | '\u06E7', 58 | '\u06E8', 59 | '\u06EA', 60 | '\u06EB', 61 | '\u06EC', 62 | '\u06ED', 63 | ]; 64 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as constants from './constants'; 2 | import { OldArabicOptions } from './options'; 3 | import * as script from './scripts'; 4 | import * as utils from './utils'; 5 | 6 | export const ArabicServices = { 7 | constants, 8 | utils, 9 | ...script, 10 | }; 11 | 12 | export type { OldArabicOptions }; 13 | -------------------------------------------------------------------------------- /src/options.ts: -------------------------------------------------------------------------------- 1 | export type OldArabicOptions = { 2 | replaceMidNoonWithBah?: boolean; 3 | replaceMidYahWithBah?: boolean; 4 | }; 5 | 6 | const defaultOldArabicOptions: OldArabicOptions = { 7 | replaceMidNoonWithBah: true, 8 | replaceMidYahWithBah: false, 9 | }; 10 | 11 | export function fillDefaultOptions(options: OldArabicOptions): OldArabicOptions { 12 | return { 13 | ...defaultOldArabicOptions, 14 | ...options, 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /src/scripts/index.ts: -------------------------------------------------------------------------------- 1 | export * from './scripts'; 2 | -------------------------------------------------------------------------------- /src/scripts/scripts.ts: -------------------------------------------------------------------------------- 1 | import { ARABIC_DOTLESS_DICT, BANNED_WORDS, TASHKEEL } from '../constants'; 2 | import { 3 | ALEF, 4 | ALONE_LETTERS, 5 | ARABIC_PREFIXES, 6 | ARABIC_SUFFIXES, 7 | LETTERS_TASHFEER_REPLACEMENT_DICT, 8 | PRONOUNCED_LETTERS, 9 | STANDARD_LETTERS, 10 | WAW, 11 | YAA, 12 | } from '../constants/arabic-letters'; 13 | import { fillDefaultOptions, type OldArabicOptions } from '../options'; 14 | import { setCharAt, similarityScore } from '../utils'; 15 | 16 | /** 17 | * Remove all tashkeel from text 18 | * @param text string to remove tashkeel from 19 | * @returns string without tashkeel 20 | * @example 21 | * Input: "الخَيْلُ وَاللّيْلُ وَالبَيْداءُ تَعرِفُني" 22 | * Output: "الخيل والليل والبيداء تعرفني" 23 | */ 24 | export function removeTashkeel(text: string): string { 25 | return text 26 | .trim() 27 | .replace(new RegExp('[' + TASHKEEL.join('') + ']', 'g'), '') 28 | .replace(/ٱ/g, 'ا'); 29 | } 30 | 31 | /** 32 | * Remove all dots & tashkeel from text 33 | * @param sentence string to convert to old arabic 34 | * @param option 35 | * @returns string in old arabic 36 | * @example 37 | * Input: "الخَيْلُ وَاللّيْلُ وَالبَيْداءُ تَعرِفُني" 38 | * Output: "الحىل واللىل والٮىدا ٮعرڡٮى" 39 | */ 40 | export function toOldArabic(sentence: string, option: OldArabicOptions = {}): string { 41 | const { replaceMidNoonWithBah, replaceMidYahWithBah } = fillDefaultOptions(option); 42 | sentence = removeTashkeel(sentence.trim()); 43 | let newSentence = ''; 44 | for (let letter = 0; letter < sentence.length; letter++) { 45 | // if letter is not Arabic letter => append to newSentence 46 | if (!ARABIC_DOTLESS_DICT.hasOwnProperty(sentence[letter])) { 47 | newSentence += sentence[letter]; 48 | } 49 | // Handle 'ن' Issue: 50 | // if 'ن' is not last character && next character is Arabic letter or 'ـ' 51 | // then replace it with 'ب' corresponding dotless letter => 'ٮ' 52 | else if ( 53 | replaceMidNoonWithBah && 54 | sentence[letter] == 'ن' && 55 | letter + 1 < sentence.length && 56 | (ARABIC_DOTLESS_DICT.hasOwnProperty(sentence[letter + 1]) || sentence[letter + 1] == 'ـ') 57 | ) { 58 | newSentence += ARABIC_DOTLESS_DICT['ب']; 59 | } 60 | // Handle 'ي' Issue 61 | // if 'ي' is not last character && next character is Arabic letter or 'ـ' 62 | // then replace it with 'ب' corresponding dotless letter => 'ٮ' 63 | else if ( 64 | replaceMidYahWithBah && 65 | sentence[letter] == 'ي' && 66 | letter + 1 < sentence.length && 67 | (ARABIC_DOTLESS_DICT.hasOwnProperty(sentence[letter + 1]) || sentence[letter + 1] == 'ـ') 68 | ) { 69 | newSentence += ARABIC_DOTLESS_DICT['ب']; 70 | } else { 71 | // if letter is Arabic letter => append corresponding dotless letter to newSentence 72 | newSentence += ARABIC_DOTLESS_DICT[sentence[letter]]; 73 | } 74 | } 75 | return newSentence; 76 | } 77 | 78 | export function toOldArabicAndTashfeerBannedWords(sentence: string, levelOfTashfeer: number = 2): string { 79 | let new_sentence = ''; 80 | const words = sentence.trim().split(' '); 81 | for (const word of words) { 82 | if (checkIfBannedWord(word)) { 83 | new_sentence += tashfeerHandler(word, levelOfTashfeer) + ' '; 84 | } else { 85 | new_sentence += toOldArabic(word) + ' '; 86 | } 87 | } 88 | return new_sentence.trim(); 89 | } 90 | 91 | /** 92 | * Remove all tatweel from text 93 | * @param text string to remove tatweel from 94 | * @returns string without tatweel 95 | * @example 96 | * Input: "رائـــــــع" 97 | * Output: "رائع" 98 | */ 99 | export function removeTatweel(text: string): string { 100 | return text.trim().replace(/ـ/g, ''); 101 | } 102 | 103 | /** 104 | * Converts a word to its pronounced letter representations based on PRONOUNCED_LETTERS. 105 | * @param {string} word - The word to convert. 106 | * @returns {string} The word with pronounced letters separated by spaces. 107 | */ 108 | export function wordToLetters(word: string): string { 109 | const trimmedWord = word.trim(); 110 | let newWord = ''; 111 | 112 | // Loop through each character in the input word 113 | for (let i = 0; i < trimmedWord.length; i++) { 114 | const letter = trimmedWord[i]; 115 | 116 | // Check if the current letter has a pronunciation in PRONOUNCED_LETTERS 117 | if (PRONOUNCED_LETTERS.hasOwnProperty(letter)) { 118 | newWord += PRONOUNCED_LETTERS[letter]; 119 | 120 | // Add a space after the pronounced letter unless it's the last letter in the word 121 | if (i !== trimmedWord.length - 1) { 122 | newWord += ' '; 123 | } 124 | } else { 125 | // If the letter is not in PRONOUNCED_LETTERS, keep it unchanged 126 | newWord += letter; 127 | } 128 | } 129 | 130 | return newWord.trim(); 131 | } 132 | 133 | /** 134 | * Removes predefined affixes (prefixes and suffixes) from an Arabic word if it starts or ends with those affixes. 135 | * This function is designed specifically for processing Arabic text, where certain affixes might need to be removed 136 | * for linguistic, stylistic, or morphological reasons. 137 | * 138 | * @param {string} word - The Arabic word from which the affixes are to be removed. 139 | * @returns {string} The word after removing any matching affixes. Returns the original word trimmed if no affix matches are found. 140 | */ 141 | function removeArabicAffixesFromWord(word: string): string { 142 | word = word.trim(); 143 | if (ARABIC_PREFIXES.includes(word.substring(0, 2))) { 144 | // For: ALEF & LAM 145 | word = setCharAt(word, 0, ''); 146 | word = setCharAt(word, 0, ''); 147 | } else if (ARABIC_PREFIXES.includes(word.substring(0, 1))) { 148 | word = setCharAt(word, 0, ''); 149 | } 150 | 151 | if (ARABIC_SUFFIXES.includes(word.substring(word.length - 2))) { 152 | word = setCharAt(word, word.length - 1, ''); 153 | word = setCharAt(word, word.length - 1, ''); 154 | } else if (ARABIC_SUFFIXES.includes(word[word.length - 1])) { 155 | word = setCharAt(word, word.length - 1, ''); 156 | } 157 | 158 | return word; 159 | } 160 | 161 | /** 162 | * Removes predefined affixes (prefixes and suffixes) from an Arabic text if words start or end with those affixes. 163 | * This function is designed specifically for processing Arabic text, where certain affixes might need to be removed 164 | * for linguistic, stylistic, or morphological reasons. 165 | * 166 | * @param {string} text - The Arabic text from which the affixes are to be removed. 167 | * @returns {string} The text after removing any matching affixes from each word. Returns the original text trimmed if no affix matches are found. 168 | */ 169 | export function removeArabicAffixes(text: string): string { 170 | let new_sentence = ''; 171 | text = text.trim(); 172 | for (const word of text.split(' ')) { 173 | new_sentence += removeArabicAffixesFromWord(word) + ' '; 174 | } 175 | return new_sentence.trim(); 176 | } 177 | 178 | /** 179 | * Calculates the encryption level based on the input level and word length. 180 | * @param {number} level - The input encryption level. 181 | * @param {number} wordLength - The length of the word to be encrypted. 182 | * @returns {number} The calculated encryption level. 183 | */ 184 | function calculateEncryptionLevel(level: number, wordLength: number): number { 185 | // Check if the word length is less than or equal to 4 186 | if (wordLength <= 4) { 187 | // If so, return the minimum of (1 + level) and the word length 188 | return Math.min(1 + level, wordLength); 189 | } else if (wordLength < 8) { 190 | // If the word length is less than 8 191 | // Return the minimum of (2 + level) and the word length 192 | return Math.min(2 + level, wordLength); 193 | } else { 194 | // If the word length is 8 or greater 195 | // Return the minimum of (3 + level) and the word length 196 | return Math.min(3 + level, wordLength); 197 | } 198 | } 199 | 200 | /** 201 | * Generates a list of random indexes for encryption. 202 | * @param {number} numOfIndexesToNeeded - The number of random indexes to generate. 203 | * @param {number} wordLength - The length of the word. 204 | * @returns {number[]} An array of random indexes. 205 | */ 206 | function getRandomIndexes(numOfIndexesToNeeded: number, wordLength: number): number[] { 207 | // Create a Set to store unique random indexes 208 | const randomIndexes = new Set(); 209 | 210 | // Continue generating random indexes until the desired number is reached 211 | while (randomIndexes.size !== numOfIndexesToNeeded) { 212 | // Generate a random index within the word length 213 | randomIndexes.add(Math.floor(Math.random() * wordLength)); 214 | } 215 | 216 | // Convert the Set to an array and sort the indexes 217 | return Array.from(randomIndexes).sort((a, b) => a - b); 218 | } 219 | 220 | /** 221 | * Processes the word for encryption using random indexes. 222 | * @param {string} word - The word to be encrypted. 223 | * @param {number[]} randomIndexes - The random indexes for encryption. 224 | * @returns {string} The encrypted word. 225 | */ 226 | function tashfeerWord(word: string, randomIndexes: number[]): string { 227 | let outputWord = ''; 228 | 229 | for (let i = 0; i < word.length; i++) { 230 | // Check if the character is a standard Arabic letter and needs to be replaced 231 | // and ignore any other character such as Latin or digits 232 | // Also, check if the current index is in the list of random indexes for replacement 233 | if (STANDARD_LETTERS.includes(word[i]) && randomIndexes.includes(i)) { 234 | // Get the replacement letter for the current character 235 | const letter = tashfeerCharacter(word[i]); 236 | 237 | // Check if the previous character is not an "alone" letter 238 | if (i !== 0 && !ALONE_LETTERS.includes(word[i - 1])) { 239 | // Add a Maddah character for better readability 240 | outputWord += 'ـ'; 241 | } 242 | 243 | // Add the replacement letter to the encrypted word 244 | outputWord += letter; 245 | } else { 246 | // If the character doesn't need to be replaced, add it as it is 247 | outputWord += word[i]; 248 | } 249 | } 250 | 251 | return outputWord; 252 | } 253 | 254 | /** 255 | * Returns a randomly selected replacement character for the input character based on the tashfeer rules. 256 | * @param {string} character - The input character to be replaced. 257 | * @returns {string} The randomly selected replacement character. 258 | */ 259 | function tashfeerCharacter(character: string): string { 260 | if (ALEF.includes(character)) { 261 | character = 'ا'; 262 | } 263 | if (WAW.includes(character)) { 264 | character = 'و'; 265 | } 266 | if (YAA.includes(character)) { 267 | character = 'ي'; 268 | } 269 | 270 | // Get the list of possible replacement characters for the input character 271 | const REPLACEMENT_CHAR_LIST = LETTERS_TASHFEER_REPLACEMENT_DICT[character]; 272 | // Generate a random index to select a replacement character 273 | const randomIndex = Math.floor(Math.random() * REPLACEMENT_CHAR_LIST.length); 274 | // Get the randomly selected replacement character 275 | const replacementCharacter = REPLACEMENT_CHAR_LIST[randomIndex]; 276 | return replacementCharacter; 277 | } 278 | 279 | /** 280 | * Performs tashfeer encryption on a given word. 281 | * @param {string} word - The input word to be encrypted. 282 | * @param {number} [level=0] - The encryption level (default is 0). 283 | * @returns {string} The encrypted word. 284 | */ 285 | function tashfeerHandler(word: string, level: number = 0): string { 286 | const wordLength = word.length; 287 | // Calculate the encryption level based on the input level and word length 288 | const n = calculateEncryptionLevel(level, wordLength); 289 | // Generate a list of random indexes for encryption 290 | const randomIndexes = getRandomIndexes(n, wordLength); 291 | // Process the word for encryption using random indexes 292 | const outputWord = tashfeerWord(word, randomIndexes); 293 | return outputWord; 294 | } 295 | 296 | /** 297 | * Performs tashfeer encryption on a given sentence. 298 | * @param {string} sentence - The input sentence to be encrypted. 299 | * @returns {string} The encrypted sentence. 300 | */ 301 | export function tashfeer(sentence: string, levelOfTashfeer: number = 1): string { 302 | sentence = sentence.trim(); 303 | let new_sentence = ''; 304 | for (const word of sentence.split(' ')) { 305 | new_sentence += tashfeerHandler(word, levelOfTashfeer) + ' '; 306 | } 307 | return new_sentence.trim(); 308 | } 309 | 310 | /** 311 | * Calculates a ratio that likely represents the degree of similarity of a given string to elements in a 'banned' array. 312 | * 313 | * @param {string} string - The string to be compared against the elements in the 'banned' array. 314 | * @returns {number} The highest similarity ratio found between the string and elements in 'banned'. 315 | */ 316 | function bannedSimilarityRatio(string: string): number { 317 | let maximumSimilarity = -1; 318 | for (const i in BANNED_WORDS) { 319 | const calculatedSimilarity = similarityScore(string, BANNED_WORDS[i]); 320 | if (calculatedSimilarity > maximumSimilarity) { 321 | maximumSimilarity = calculatedSimilarity; 322 | } 323 | } 324 | return maximumSimilarity * 100; 325 | } 326 | 327 | /** 328 | * Checks if a string is similar to any 'banned' words based on a predefined similarity ratio. 329 | * 330 | * @param {string} string - The string to be checked. 331 | * @returns {boolean} True if the string is similar to any 'banned' word, false otherwise. 332 | */ 333 | function checkIfBannedWord(string: string): boolean { 334 | const std_ratio = 70; 335 | return bannedSimilarityRatio(removeArabicAffixes(string)) >= std_ratio; 336 | } 337 | 338 | /** 339 | * Performs tashfeer encryption on a given sentence, but only for words that are considered "banned" words. 340 | * Banned words are determined based on a predefined similarity ratio. 341 | * 342 | * @param {string} sentence - The input sentence to be encrypted. 343 | * @param {number} [levelOfTashfeer=2] - The encryption level (default is 2). 344 | * @returns {string} The encrypted sentence with tashfeer applied to banned words. 345 | */ 346 | export function tashfeerBannedWords(sentence: string, levelOfTashfeer: number = 2): string { 347 | let new_sentence = ''; 348 | sentence = sentence.trim(); 349 | for (const word of sentence.split(' ')) { 350 | if (checkIfBannedWord(word)) { 351 | new_sentence += tashfeerHandler(word, levelOfTashfeer) + ' '; 352 | } else { 353 | new_sentence += word + ' '; 354 | } 355 | } 356 | return new_sentence.trim(); 357 | } 358 | -------------------------------------------------------------------------------- /src/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from './string.util'; 2 | -------------------------------------------------------------------------------- /src/utils/string.util.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Sets the character at a specified index in a string. 3 | * 4 | * @param {string} str - The input string. 5 | * @param {number} index - The index at which to set the character. 6 | * @param {string} chr - The character to set at the specified index. 7 | * @returns {string} A new string with the character set at the specified index. 8 | */ 9 | export function setCharAt(str: string, index: number, chr: string): string { 10 | if (index > str.length - 1) return str; 11 | return str.substring(0, index) + chr + str.substring(index + 1); 12 | } 13 | 14 | /** 15 | * Calculates a similarity score between two strings, potentially based on their edit distance. 16 | * 17 | * @param {string} s1 - The first string to compare. 18 | * @param {string} s2 - The second string to compare. 19 | * @returns {number} A similarity score representing how similar the two strings are. The score is between 0 and 1. 20 | */ 21 | export function similarityScore(s1: string, s2: string): number { 22 | let longer = s1; 23 | let shorter = s2; 24 | // swap them if s1 is bigger than s2 25 | if (s1.length < s2.length) { 26 | longer = s2; 27 | shorter = s1; 28 | } 29 | const longerLength = longer.length; 30 | // if both are empty strings return 1 (100% similarity) 31 | if (longerLength === 0) { 32 | return 1.0; 33 | } 34 | // calculate the similarity score 35 | return (longerLength - editDistance(longer, shorter)) / (longerLength * 1.0); 36 | } 37 | 38 | /** 39 | * Calculates the edit distance (Levenshtein distance) between two strings. 40 | * The edit distance is the minimum number of operations (insertions, deletions, or substitutions) 41 | * required to change one string into the other. 42 | * 43 | * @param {string} s1 - The first string to compare. 44 | * @param {string} s2 - The second string to compare. 45 | * @returns {number} The edit distance between the two strings. 46 | */ 47 | function editDistance(s1: string, s2: string): number { 48 | s1 = s1.toLowerCase(); 49 | s2 = s2.toLowerCase(); 50 | 51 | const costs = new Array(); 52 | for (let i = 0; i <= s1.length; i++) { 53 | let lastValue = i; 54 | for (let j = 0; j <= s2.length; j++) { 55 | if (i == 0) costs[j] = j; 56 | else if (j > 0) { 57 | let newValue = costs[j - 1]; 58 | if (s1.charAt(i - 1) != s2.charAt(j - 1)) 59 | newValue = Math.min(Math.min(newValue, lastValue), costs[j]) + 1; 60 | costs[j - 1] = lastValue; 61 | lastValue = newValue; 62 | } 63 | } 64 | if (i > 0) costs[s2.length] = lastValue; 65 | } 66 | return costs[s2.length]; 67 | } 68 | -------------------------------------------------------------------------------- /tests/constants.test.ts: -------------------------------------------------------------------------------- 1 | import { ArabicServices } from '../dist'; 2 | 3 | describe('STANDARD_LETTERS', () => { 4 | it('should have array length of 34', () => { 5 | expect(Object.keys(ArabicServices.constants.STANDARD_LETTERS).length).toBe(34); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /tests/scripts.test.ts: -------------------------------------------------------------------------------- 1 | import { ArabicServices } from '../dist'; 2 | 3 | describe('#removeTashkeel()', () => { 4 | describe('Test with Poetry Text', () => { 5 | it('should remove all tashkeel from Poetry text', () => { 6 | const text = `الخَيْـلُ وَاللّيْـلُ وَالبَيْـداءُ تَعرِفُني وَالسّيفُ وَالرّمحُ والقرْطاسُ وَالقَلَـمُ`; 7 | const actual = ArabicServices.removeTashkeel(text); 8 | const expected = `الخيـل والليـل والبيـداء تعرفني والسيف والرمح والقرطاس والقلـم`; 9 | expect(actual).toBe(expected); 10 | }); 11 | }); 12 | 13 | describe('Test with Quran Text', () => { 14 | it('should remove all tashkeel from Quran text', () => { 15 | const text = `وَقَالُواْ ٱلۡحَمۡدُ لِلَّهِ ٱلَّذِيٓ أَذۡهَبَ عَنَّا ٱلۡحَزَنَۖ إِنَّ رَبَّنَا لَغَفُورٞ شَكُورٌ`; 16 | const actual = ArabicServices.removeTashkeel(text); 17 | const expected = `وقالوا الحمد لله الذي أذهب عنا الحزن إن ربنا لغفور شكور`; 18 | expect(actual).toBe(expected); 19 | }); 20 | }); 21 | }); 22 | 23 | describe('#toOldArabic()', () => { 24 | describe('Test ن letter', () => { 25 | it('should convert ن to ں last letter, else convert it to ٮ', () => { 26 | const text = `ننن`; 27 | const actual = ArabicServices.toOldArabic(text); 28 | const expected = `ٮٮں`; 29 | expect(actual).toBe(expected); 30 | }); 31 | it('should convert ن to ں in all case', () => { 32 | const text = `ننن`; 33 | const actual = ArabicServices.toOldArabic(text, { replaceMidNoonWithBah: false }); 34 | const expected = `ںںں`; 35 | const expectedUnicode = '\u06BA\u06BA\u06BA'; 36 | expect(actual).toBe(expected); 37 | expect(actual).toBe(expectedUnicode); 38 | }); 39 | }); 40 | 41 | describe('Test Tatweel with ن letter', () => { 42 | it('should convert ن to ں last letter, else convert it to ٮ', () => { 43 | const text = `نــنــن`; 44 | const actual = ArabicServices.toOldArabic(text); 45 | const expected = `ٮــٮــں`; 46 | expect(actual).toBe(expected); 47 | }); 48 | it('should convert ن to ں last letter in all cases', () => { 49 | const text = `نــنــن`; 50 | const actual = ArabicServices.toOldArabic(text, { replaceMidNoonWithBah: false }); 51 | const expected = `ںــںــں`; 52 | const expectedUnicode = '\u06BA\u0640\u0640\u06BA\u0640\u0640\u06BA'; 53 | expect(actual).toBe(expected); 54 | expect(actual).toBe(expectedUnicode); 55 | }); 56 | }); 57 | 58 | describe('Test ي letter', () => { 59 | it('should convert ي to ى last letter, else convert it to ٮ', () => { 60 | const text = `ييي`; 61 | const actual = ArabicServices.toOldArabic(text, { replaceMidYahWithBah: true }); 62 | const expected = `ٮٮى`; 63 | const expectedUnicode = '\u066E\u066E\u0649'; 64 | expect(actual).toBe(expected); 65 | expect(actual).toBe(expectedUnicode); 66 | }); 67 | it('should convert ي to ى in all case (default)', () => { 68 | const text = `ييي`; 69 | const actual = ArabicServices.toOldArabic(text, { replaceMidNoonWithBah: false }); 70 | const expected = `ىىى`; 71 | const expectedUnicode = '\u0649\u0649\u0649'; 72 | expect(actual).toBe(expected); 73 | expect(actual).toBe(expectedUnicode); 74 | }); 75 | }); 76 | 77 | describe('Test Tatweel with ي letter', () => { 78 | it('should convert ي to ى last letter, else convert it to ٮ', () => { 79 | const text = `يــيــي`; 80 | const actual = ArabicServices.toOldArabic(text, { replaceMidYahWithBah: true }); 81 | const expected = `ٮــٮــى`; 82 | const expectedUnicode = '\u066E\u0640\u0640\u066E\u0640\u0640\u0649'; 83 | expect(actual).toBe(expected); 84 | expect(actual).toBe(expectedUnicode); 85 | }); 86 | it('should convert ي to ں last letter in all cases (default)', () => { 87 | const text = `يــيــي`; 88 | const actual = ArabicServices.toOldArabic(text); 89 | const expected = `ىــىــى`; 90 | const expectedUnicode = '\u0649\u0640\u0640\u0649\u0640\u0640\u0649'; 91 | expect(actual).toBe(expected); 92 | expect(actual).toBe(expectedUnicode); 93 | }); 94 | }); 95 | 96 | describe('Test with Poetry Text', () => { 97 | it('should remove all dots & tashkeel from Poetry text', () => { 98 | const text = `الخَيْـلُ وَاللّيْـلُ وَالبَيْـداءُ تَعرِفُني وَالسّيفُ وَالرّمحُ والقرْطاسُ وَالقَلَـمُ`; 99 | const actual = ArabicServices.toOldArabic(text); 100 | const expected = `الحىـل واللىـل والٮىـدا ٮعرڡٮى والسىڡ والرمح والٯرطاس والٯلـم`; 101 | expect(actual).toBe(expected); 102 | }); 103 | it('should remove all dots & tashkeel from Poetry text, with option replace Yeh with dotless Bah', () => { 104 | const text = `الخَيْـلُ وَاللّيْـلُ وَالبَيْـداءُ تَعرِفُني وَالسّيفُ وَالرّمحُ والقرْطاسُ وَالقَلَـمُ`; 105 | const actual = ArabicServices.toOldArabic(text, { replaceMidYahWithBah: true }); 106 | const expected = `الحٮـل واللٮـل والٮٮـدا ٮعرڡٮى والسٮڡ والرمح والٯرطاس والٯلـم`; 107 | expect(actual).toBe(expected); 108 | }); 109 | }); 110 | 111 | describe('Test with Quran Text', () => { 112 | it('should remove all dots & tashkeel from Quran text', () => { 113 | const text = `وَقَالُواْ ٱلۡحَمۡدُ لِلَّهِ ٱلَّذِيٓ أَذۡهَبَ عَنَّا ٱلۡحَزَنَۖ إِنَّ رَبَّنَا لَغَفُورٞ شَكُورٌ`; 114 | const actual = ArabicServices.toOldArabic(text); 115 | const expected = `وٯالوا الحمد لله الدى ادهٮ عٮا الحرں اں رٮٮا لعڡور سکور`; 116 | expect(actual).toBe(expected); 117 | }); 118 | it('should remove all dots & tashkeel from Quran text', () => { 119 | const text = `وَقَالُواْ ٱلۡحَمۡدُ لِلَّهِ ٱلَّذِيٓ أَذۡهَبَ عَنَّا ٱلۡحَزَنَۖ إِنَّ رَبَّنَا لَغَفُورٞ شَكُورٌ`; 120 | const actual = ArabicServices.toOldArabic(text, { replaceMidNoonWithBah: false }); 121 | const expected = `وٯالوا الحمد لله الدى ادهٮ عںا الحرں اں رٮںا لعڡور سکور`; 122 | expect(actual).toBe(expected); 123 | }); 124 | }); 125 | }); 126 | 127 | describe('#toOldArabicAndTashfeerBannedWords()', () => { 128 | it('should perform tashfeer encryption on banned words only and convert the rest to old arabic script', () => { 129 | const sentence = 'جيش العدو يقتل الأطفال'; 130 | const result = ArabicServices.toOldArabicAndTashfeerBannedWords(sentence); 131 | expect(result).not.toEqual(sentence); 132 | expect(result).toMatch(/الاطڡال/); 133 | expect(result).not.toMatch(/جيش/); 134 | expect(result).not.toMatch(/العدو/); 135 | expect(result).not.toMatch(/يقتل/); 136 | }); 137 | }); 138 | 139 | describe('#removeTatweel()', () => { 140 | it("should remove all tatweel 'ـ' from text", () => { 141 | const text = 'رائـــــــع'; 142 | const actual = ArabicServices.removeTatweel(text); 143 | const expected = 'رائع'; 144 | expect(actual).toBe(expected); 145 | }); 146 | }); 147 | 148 | describe('#tashfeer', () => { 149 | it('should return a string with tashfeer-ed characters', () => { 150 | const inputWord = 'هذه الجملة مشفرة'; 151 | const result = ArabicServices.tashfeer(inputWord); 152 | expect(result).toEqual(expect.any(String)); 153 | expect(result).not.toEqual(inputWord); 154 | }); 155 | }); 156 | 157 | describe('#wordToLetters', () => { 158 | it('should return a string with pronounced Arabic letters', () => { 159 | const inputWord = 'هذه جملة عربية'; 160 | const result = ArabicServices.wordToLetters(inputWord); 161 | expect(result).toEqual(expect.any(String)); 162 | expect(result).not.toEqual(inputWord); 163 | }); 164 | 165 | it('should handle empty input', () => { 166 | const inputWord = ''; 167 | const result = ArabicServices.wordToLetters(inputWord); 168 | expect(result).toEqual(''); 169 | }); 170 | 171 | it('should handle input with no pronounced Arabic letters', () => { 172 | const inputWord = '12345 not in Arabic letters'; 173 | const result = ArabicServices.wordToLetters(inputWord); 174 | expect(result).toEqual(inputWord); 175 | }); 176 | 177 | it('should handle input with spaces', () => { 178 | const inputWord = 'هذه جملة اخرى'; 179 | const result = ArabicServices.wordToLetters(inputWord); 180 | expect(result).toEqual('هاء ذال هاء جيم ميم لام تاء_مربوطة ألف خاء راء ألف_لينة'); 181 | }); 182 | }); 183 | 184 | describe('#removeArabicAffixes', () => { 185 | it('should remove "أ" prefix from a word', () => { 186 | const word = 'أمل'; 187 | const result = ArabicServices.removeArabicAffixes(word); 188 | expect(result).toEqual('مل'); 189 | }); 190 | 191 | it('should remove "ا" prefix & suffix "ة" from a word', () => { 192 | const word = 'امرأة'; 193 | const result = ArabicServices.removeArabicAffixes(word); 194 | expect(result).toEqual('مرأ'); 195 | }); 196 | 197 | it('should remove "إ" prefix from a word', () => { 198 | const word = 'إنسان'; 199 | const result = ArabicServices.removeArabicAffixes(word); 200 | expect(result).toEqual('نسان'); 201 | }); 202 | 203 | it('should remove "ال" prefix from a word', () => { 204 | const word = 'الكتاب'; 205 | const result = ArabicServices.removeArabicAffixes(word); 206 | expect(result).toEqual('كتاب'); 207 | }); 208 | 209 | it('should remove "ي" prefix from a word', () => { 210 | const word = 'يوم'; 211 | const result = ArabicServices.removeArabicAffixes(word); 212 | expect(result).toEqual('وم'); 213 | }); 214 | 215 | it('should remove "ت" prefix from a word', () => { 216 | const word = 'تفاح'; 217 | const result = ArabicServices.removeArabicAffixes(word); 218 | expect(result).toEqual('فاح'); 219 | }); 220 | 221 | it('should remove "ن" prefix from a word', () => { 222 | const word = 'نجم'; 223 | const result = ArabicServices.removeArabicAffixes(word); 224 | expect(result).toEqual('جم'); 225 | }); 226 | 227 | it('should remove "ب" prefix from a word', () => { 228 | const word = 'بيت'; 229 | const result = ArabicServices.removeArabicAffixes(word); 230 | expect(result).toEqual('يت'); 231 | }); 232 | 233 | it('should remove "ة" suffix from a word', () => { 234 | const word = 'كتابة'; 235 | const result = ArabicServices.removeArabicAffixes(word); 236 | expect(result).toEqual('كتاب'); 237 | }); 238 | 239 | it('should remove "ه" suffix from a word', () => { 240 | const word = 'جديه'; 241 | const result = ArabicServices.removeArabicAffixes(word); 242 | expect(result).toEqual('جدي'); 243 | }); 244 | 245 | it('should remove "ي" suffix from a word', () => { 246 | const word = 'ذهبي'; 247 | const result = ArabicServices.removeArabicAffixes(word); 248 | expect(result).toEqual('ذهب'); 249 | }); 250 | 251 | it('should remove "ى" suffix from a word', () => { 252 | const word = 'منزلي'; 253 | const result = ArabicServices.removeArabicAffixes(word); 254 | expect(result).toEqual('منزل'); 255 | }); 256 | 257 | it('should remove "ية" suffix from a word', () => { 258 | const word = 'علمية'; 259 | const result = ArabicServices.removeArabicAffixes(word); 260 | expect(result).toEqual('علم'); 261 | }); 262 | 263 | it('should remove "ين" suffix from a word', () => { 264 | const word = 'موظفين'; 265 | const result = ArabicServices.removeArabicAffixes(word); 266 | expect(result).toEqual('موظف'); 267 | }); 268 | 269 | it('should remove "ون" suffix from a word', () => { 270 | const word = 'موظفون'; 271 | const result = ArabicServices.removeArabicAffixes(word); 272 | expect(result).toEqual('موظف'); 273 | }); 274 | 275 | it('should remove "هم" suffix from a word', () => { 276 | const word = 'طلابهم'; 277 | const result = ArabicServices.removeArabicAffixes(word); 278 | expect(result).toEqual('طلاب'); 279 | }); 280 | 281 | it('should remove prefix & suffix from a sentence', () => { 282 | const word = 'المدرسون يحبون طلابهم'; 283 | const result = ArabicServices.removeArabicAffixes(word); 284 | expect(result).toEqual('مدرس حب طلاب'); 285 | }); 286 | }); 287 | 288 | describe('#similarityScore', () => { 289 | it('should return 1 for identical strings', () => { 290 | const s1 = 'مرحبا'; 291 | const s2 = 'مرحبا'; 292 | const result = ArabicServices.utils.similarityScore(s1, s2); 293 | expect(result).toEqual(1.0); 294 | }); 295 | 296 | it('should return 0 for completely different strings', () => { 297 | const s1 = 'شجرة'; 298 | const s2 = 'طفل'; 299 | const result = ArabicServices.utils.similarityScore(s1, s2); 300 | expect(result).toEqual(0.0); 301 | }); 302 | 303 | it('should return a value between 0 and 1 for similar strings', () => { 304 | const s1 = 'مرحبا'; 305 | const s2 = 'مرحب'; 306 | const result = ArabicServices.utils.similarityScore(s1, s2); 307 | expect(result).toBeGreaterThan(0.0); 308 | expect(result).toBeLessThan(1.0); 309 | }); 310 | 311 | it('should handle empty strings', () => { 312 | const s1 = ''; 313 | const s2 = ''; 314 | const result = ArabicServices.utils.similarityScore(s1, s2); 315 | expect(result).toEqual(1.0); 316 | }); 317 | 318 | it('should handle one empty string', () => { 319 | const s1 = 'مرحبا'; 320 | const s2 = ''; 321 | const result = ArabicServices.utils.similarityScore(s1, s2); 322 | expect(result).toEqual(0.0); 323 | }); 324 | }); 325 | 326 | describe('#tashfeerBannedWords', () => { 327 | it('should perform tashfeer encryption on banned words only', () => { 328 | const sentence = 'جيش العدو يقتل الأطفال'; 329 | const result = ArabicServices.tashfeerBannedWords(sentence); 330 | expect(result).not.toEqual(sentence); 331 | expect(result).toMatch(/الأطفال/); 332 | expect(result).not.toMatch(/جيش/); 333 | expect(result).not.toMatch(/العدو/); 334 | expect(result).not.toMatch(/يقتل/); 335 | }); 336 | 337 | it('should not perform tashfeer encryption on non-banned words', () => { 338 | const sentence = 'هذه جملة غير مشفرة'; 339 | const result = ArabicServices.tashfeerBannedWords(sentence); 340 | expect(result).toEqual(sentence); 341 | }); 342 | 343 | it('should handle empty input', () => { 344 | const sentence = ''; 345 | const result = ArabicServices.tashfeerBannedWords(sentence); 346 | expect(result).toEqual(''); 347 | }); 348 | }); 349 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "module": "CommonJS", 5 | "strict": true, 6 | "declaration": true, 7 | "outDir": "./dist", 8 | "esModuleInterop": true 9 | }, 10 | "include": ["src/**/*.ts"], 11 | "exclude": ["node_modules", "**/tests/*"] 12 | } 13 | -------------------------------------------------------------------------------- /webpack.config.cjs: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line @typescript-eslint/no-var-requires 2 | const path = require('path'); 3 | 4 | module.exports = [ 5 | { 6 | // Configuration for UMD bundle 7 | entry: './src/index.ts', 8 | mode: 'production', 9 | module: { 10 | rules: [ 11 | { 12 | test: /\.tsx?$/, 13 | use: 'ts-loader', 14 | exclude: /node_modules/, 15 | }, 16 | ], 17 | }, 18 | resolve: { 19 | extensions: ['.tsx', '.ts', '.js'], 20 | }, 21 | output: { 22 | filename: 'arabic-services.umd.js', 23 | path: path.resolve(__dirname, 'dist/umd'), 24 | library: 'ArabicServices', 25 | libraryTarget: 'umd', 26 | globalObject: 'this', 27 | libraryExport: 'ArabicServices', 28 | }, 29 | }, 30 | { 31 | // Configuration for ESM bundle 32 | entry: './src/index.ts', 33 | mode: 'production', 34 | module: { 35 | rules: [ 36 | { 37 | test: /\.tsx?$/, 38 | use: 'ts-loader', 39 | exclude: /node_modules/, 40 | }, 41 | ], 42 | }, 43 | resolve: { 44 | extensions: ['.tsx', '.ts', '.js'], 45 | }, 46 | output: { 47 | filename: 'arabic-services.esm.js', 48 | path: path.resolve(__dirname, 'dist/esm'), 49 | libraryTarget: 'module', 50 | libraryExport: 'ArabicServices', 51 | }, 52 | experiments: { 53 | outputModule: true, 54 | }, 55 | }, 56 | ]; 57 | --------------------------------------------------------------------------------