UNPKG

qd-arabic-words

Version:

A package for generating random Arabic words that belongs to the Quantum Developers server in discord.

108 lines (78 loc) 3.02 kB
# Qd-Arabic-Words - Arabic Words Generator A robust npm library for generating random Arabic words with various customization options. ## Installation ```bash npm install qd-arabic-words ``` ## Usage ```javascript const { QGenerate } = require('qd-arabic-words'); // Basic usage QGenerate().then(word => console.log(word)); // Random Arabic word // With async/await async function getWords() { const singleWord = await QGenerate(); const multipleWords = await QGenerate(3); console.log(singleWord, multipleWords); } ``` ## API ### `QGenerate(options)` - `options` (Number|Object): Optional configuration - As Number: Number of words to return (returns array) - As Object: Configuration options (see below) Returns: `Promise<string|Array<string>>` #### Options Object | Option | Type | Description | |------------|---------|-----------------------------------------------------------------------------| | `num` | Number | Number of words to generate | | `minLength`| Number | Minimum word length (in characters) | | `maxLength`| Number | Maximum word length (in characters) | | `join` | String | Joiner string when returning multiple words (only works with `num` option) | ## Examples ### Basic Examples ```javascript // Single random word QGenerate().then(console.log); // Output: "كتاب" // Multiple words QGenerate(3).then(console.log); // Output: ["شمس", "بحر", "جبل"] // Word with length constraints QGenerate({ minLength: 4 }).then(console.log); // Output: "مدرسة" QGenerate({ maxLength: 3 }).then(console.log); // Output: "حب" QGenerate({ minLength: 3, maxLength: 5 }).then(console.log); // Output: "تفاح" ``` ### Advanced Examples ```javascript // Multiple words with length constraints QGenerate({ num: 3, minLength: 4 }).then(console.log); // Output: ["سيارة", "طائرة", "نافذة"] // Joined words QGenerate({ num: 3, join: ' - ' }).then(console.log); // Output: "شمس - بحر - جبل" // Combined options QGenerate({ num: 4, minLength: 3, maxLength: 6, join: ', ' }).then(console.log); // Output: "شجرة, قلم, مدرسة, تفاح" ``` ## Error Handling The library throws specific errors you can catch: ```javascript try { const words = await QGenerate({ num: 1000 }); // Too many words } catch (err) { console.error(err.message); // "Cannot request more than 100 words" } try { const word = await QGenerate({ minLength: 10 }); // No matching words } catch (err) { console.error(err.message); // "No words found matching length criteria: minLength=10" } ``` ## License Distributed under the MIT License. See `LICENSE` for more information. ## Our Community To inquire about the package and get help with every part of it, you can visit [our server](https://discord.gg/qVyPy42uHg) on Discord.