diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..50d2895
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,13 @@
+# These are supported funding model platforms
+
+# github: [Ali-Eldeba, OmarWebDev] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
+patreon: alieldeba # Replace with a single Patreon username
+open_collective: alieldeba # Replace with a single Open Collective username
+# ko_fi: # Replace with a single Ko-fi username
+# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
+# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
+# liberapay: # Replace with a single Liberapay username
+# issuehunt: # Replace with a single IssueHunt username
+# otechie: # Replace with a single Otechie username
+# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
+# custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
diff --git a/README.md b/README.md
index 3b4b09a..90987f6 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,81 @@
-# functionality.php
\ No newline at end of file
+#
Functionality.php (beta) 🔥
+
+
+
+
+
+
+
+
+## About ✍️
+
+- This Is A Php Library To Make Your Work Easier/Faster,
+ You Can See Functionalty.php Website From Here
+- Project Created In 15 / 6 / 2022
+
+## Installation 📦
+
+ - Using Composer
+ ```bash
+ composer require functionality-library/functionality.php
+ ```
+ - Now You Can Use Functionality.php Library In Your Project
+ - Example
+ ```php
+ require_once 'vendor/autoload.php';
+ use Functionality\FunctionalityPhp\Functionality;
+
+ echo Functionality::randomColor(); // Random Color
+ ```
+## Usage 📚
+- Randoms functions
+ - `Functionality::randomColor()` - Generate Random Color
+ - `Functionality::randomBoolean()` - Generate Random Boolean
+ - `Functionality::randomNumber()` - Generate Random Number
+ - `Functionality::randomString()` - Generate Random String
+ - `Functionality::randomHsl()` - Generate Random Hsl Color
+ - `Functionality::randomHexColor()` - Generate Random Hex Color
+- Numbers functions
+ - `Functionality::getAvg(float $a, float $b)` - Get Average butween two numbers
+ - `Functionality::isEven(float $number)` - Check If Number Is Even
+ - `Functionality::isOdd(float $number)` - Check If Number Is Odd
+ - `Functionality::isPrime(int $number)` - Check If Number Is Prime
+ - `Functionality::reverseNumber(float $number)` - Reverse a number (e.g. 12345 -> 54321)
+- Strings functions
+ - `Functionality::isPalindrome(string $string)` - Check If String Is Palindrome
+ - `Functionality::capitalize(string $string)` - Capitalize First Letter Of Words In String
+ - `Functionality::reverseString(string $string)` - Reverse a string (e.g. abcdef -> fedcba)
+- Arrays functions
+ - `Functionality::filter(array $array, callable $callable)` - Filter Array By Callable
+ - `Functionality::getFactors(int $number)` - Get Factors Of Number
+ - `Functionality::maxArray(array $array)` - Get Max Value Of Array
+ - `Functionality::minArray(array $array)` - Get Min Value Of Array
+ - `Functionality::sumArray(array $array)` - Get Sum Of Array
+ - `Functionality::randomElementFromArray(array $array)` - Get Random Element From Array
+ - `Functionality::removeDuplicatesFromArray(array $array)` - Remove Duplicates From Array
+ - `Functionality::shuffle(array $array)` - Sort Array Randomly
+
+## To Get Started Contributing ☕
+
+- First Clone The Repository
+
+ ```bash
+ git clone https://github.com/functionality-library/functionality.php.git
+ ```
+
+- Then Install Packages
+
+ ```bash
+ composer install
+ ```
+
+- Run Tests using `phpunit`
+
+ ```bash
+ composer run-script test
+ ```
+
+- Feel Free To Add What You Want!
+- If there is any issue, please open an issue on GitHub
+- If you have any suggestion, please open an issue on GitHub
+- If you have any question, please open an issue on GitHub
diff --git a/composer.json b/composer.json
index 8ef8aa4..03d7f19 100644
--- a/composer.json
+++ b/composer.json
@@ -1,14 +1,20 @@
{
- "name": "functionality/functionality.php",
+ "name": "functionality-library/functionality.php",
+ "description": "This Is A Php Library To Make Your Work Easier/Faster",
+ "version": "1.1.0",
"type": "library",
"license": "MIT",
+ "scripts": {
+ "test": "phpunit --verbose tests"
+ },
"autoload": {
"psr-4": {
"Functionality\\FunctionalityPhp\\": "src/"
}
},
"require": {
- "php": ">=8.0.0"
+ "php": ">=8.0.0",
+ "ext-mbstring": "*"
},
"authors": [
{
diff --git a/src/Functionality.php b/src/Functionality.php
index f100b56..7f33d26 100644
--- a/src/Functionality.php
+++ b/src/Functionality.php
@@ -3,9 +3,12 @@
namespace Functionality\FunctionalityPhp;
+use Functionality\FunctionalityPhp\Functions\Arrays;
+use Functionality\FunctionalityPhp\Functions\Numbers;
use Functionality\FunctionalityPhp\Functions\Randoms;
+use Functionality\FunctionalityPhp\Functions\Strings;
class Functionality
{
- use Randoms;
+ use Randoms, Numbers, Strings, Arrays;
}
\ No newline at end of file
diff --git a/src/Functions/Arrays.php b/src/Functions/Arrays.php
new file mode 100644
index 0000000..38f58b6
--- /dev/null
+++ b/src/Functions/Arrays.php
@@ -0,0 +1,104 @@
+ 54321).
+ *
+ * @param float $number
+ * @return float
+ */
+ public static function reverseNumber(float $number): float
+ {
+ return $number > 0 ? +strrev((string) $number) : -str_replace('-', '', strrev((string) $number));
+ }
+}
\ No newline at end of file
diff --git a/src/Functions/Randoms.php b/src/Functions/Randoms.php
index f15a17b..334ead5 100644
--- a/src/Functions/Randoms.php
+++ b/src/Functions/Randoms.php
@@ -6,8 +6,96 @@
trait Randoms
{
- public static function randomBool(): bool
+ /**
+ * Generates a random boolean.
+ *
+ * @return bool
+ */
+ public static function randomBoolean(): bool
{
- return (bool) rand(0, 1);
+ return (bool)rand(0, 1);
}
+
+ public static function randomColor(): string
+ {
+ $CSS_COLOR_NAMES = [
+ 'AliceBlue', 'AntiqueWhite', 'Aqua', 'Aquamarine', 'Azure',
+ 'Beige', 'Bisque', 'Black', 'BlanchedAlmond', 'Blue',
+ 'BlueViolet', 'Brown', 'BurlyWood', 'CadetBlue', 'Chartreuse',
+ 'Chocolate', 'Coral', 'CornflowerBlue', 'Cornsilk', 'Crimson',
+ 'Cyan', 'DarkBlue', 'DarkCyan', 'DarkGoldenRod', 'DarkGray',
+ 'DarkGrey', 'DarkGreen', 'DarkKhaki', 'DarkMagenta', 'DarkOliveGreen',
+ 'DarkOrange', 'DarkOrchid', 'DarkRed', 'DarkSalmon', 'DarkSeaGreen',
+ 'DarkSlateBlue', 'DarkSlateGray', 'DarkSlateGrey', 'DarkTurquoise',
+ 'DarkViolet', 'DeepPink', 'DeepSkyBlue', 'DimGray', 'DimGrey',
+ 'DodgerBlue', 'FireBrick', 'FloralWhite', 'ForestGreen', 'Fuchsia',
+ 'Gainsboro', 'GhostWhite', 'Gold', 'GoldenRod', 'Gray',
+ 'Grey', 'Green', 'GreenYellow', 'HoneyDew', 'HotPink',
+ 'IndianRed', 'Indigo', 'Ivory', 'Khaki', 'Lavender',
+ 'LavenderBlush', 'LawnGreen', 'LemonChiffon', 'LightBlue',
+ 'LightCoral', 'LightCyan', 'LightGoldenRodYellow', 'LightGray',
+ 'LightGrey', 'LightGreen', 'LightPink', 'LightSalmon',
+ 'LightSeaGreen', 'LightSkyBlue', 'LightSlateGray', 'LightSlateGrey',
+ 'LightSteelBlue', 'LightYellow', 'Lime', 'LimeGreen', 'Linen',
+ 'Magenta', 'Maroon', 'MediumAquaMarine', 'MediumBlue',
+ 'MediumOrchid', 'MediumPurple', 'MediumSeaGreen', 'MediumSlateBlue',
+ 'MediumSpringGreen', 'MediumTurquoise', 'MediumVioletRed',
+ ];
+ return $CSS_COLOR_NAMES[array_rand($CSS_COLOR_NAMES)];
+ }
+
+ /**
+ * Generates a random color in HEX format.
+ *
+ * @return string
+ */
+ public static function randomHexColor(): string
+ {
+ return sprintf('#%06X', mt_rand(0, 0xFFFFFF));
+ }
+
+ /**
+ * Generates a random HSL color.
+ *
+ * @return string
+ */
+ public static function randomHsl(): string
+ {
+ $h = rand(0, 360);
+ $s = rand(0, 100);
+ $l = rand(0, 100);
+ return "hsl($h, $s%, $l%)";
+ }
+
+ /**
+ * Generates a random integer.
+ *
+ * @param int $min
+ * @param int $max
+ * @return int
+ */
+ public static function randomNumber($min = 0, $max = 100): int
+ {
+ return rand($min, $max);
+ }
+
+ /**
+ * Generates a random string.
+ *
+ * @param int $length
+ * @return string
+ */
+ public static function randomString($length = 8): string
+ {
+ $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
+ $count = mb_strlen($chars);
+
+ for ($i = 0, $result = ''; $i < $length; $i++) {
+ $index = rand(0, $count - 1);
+ $result .= mb_substr($chars, $index, 1);
+ }
+
+ return $result;
+ }
+
}
\ No newline at end of file
diff --git a/src/Functions/Strings.php b/src/Functions/Strings.php
new file mode 100644
index 0000000..cedd42c
--- /dev/null
+++ b/src/Functions/Strings.php
@@ -0,0 +1,41 @@
+assertEquals([3,4,5,6], Functionality::filter([1,3,4,5,6,0], function ($value) {
+ return $value > 2;
+ }));
+ // max test
+ $this->assertEquals(10, Functionality::maxArray([1,2,3,4,5,6,7,8,9,10]));
+ // min test
+ $this->assertEquals(1, Functionality::minArray([1,2,3,4,5,6,7,8,9,10]));
+ // random element from array test
+ $this->assertIsInt(Functionality::randomElementFromArray([1,2,3,4,5,6,7,8,9,10]));
+ // remove duplicates from array test
+ $this->assertEquals([1,2,3,4,5,6,7,8,9,10], Functionality::removeDuplicatesFromArray([1,1,2,2,3,3,3,3,4,5,6,7,8,9,10]));
+ // shuffle test
+ $this->assertIsArray(Functionality::shuffle([1,2,3,4,5,6,7,8,9,10]));
+ // sum test
+ $this->assertEquals(55, Functionality::sumArray([1,2,3,4,5,6,7,8,9,10]));
+
+ }
+}
diff --git a/tests/NumbersTest.php b/tests/NumbersTest.php
new file mode 100644
index 0000000..e8059d6
--- /dev/null
+++ b/tests/NumbersTest.php
@@ -0,0 +1,23 @@
+assertIsFloat(Functionality::getAvg(1.5, 2.8));
+ // is even test
+ $this->assertTrue(Functionality::isEven(2));
+ $this->assertFalse(Functionality::isEven(3));
+ // is odd test
+ $this->assertTrue(Functionality::isOdd(3));
+ $this->assertFalse(Functionality::isOdd(2));
+ // reverse number test
+ $this->assertEquals(54.321, Functionality::reverseNumber(123.45));
+ $this->assertEquals(-54.321, Functionality::reverseNumber(-123.45));
+ }
+}
diff --git a/tests/RandomBoolTest.php b/tests/RandomBoolTest.php
deleted file mode 100644
index 52f09fb..0000000
--- a/tests/RandomBoolTest.php
+++ /dev/null
@@ -1,12 +0,0 @@
-assertIsBool(Functionality::randomBool());
- }
-}
\ No newline at end of file
diff --git a/tests/RandomsTest.php b/tests/RandomsTest.php
new file mode 100644
index 0000000..f99de56
--- /dev/null
+++ b/tests/RandomsTest.php
@@ -0,0 +1,24 @@
+assertIsBool(Functionality::randomBoolean());
+ // test random color
+ $this->assertMatchesRegularExpression("/[a-z]/i",Functionality::randomColor());
+ // test random hex color
+ $this->assertMatchesRegularExpression("/^#[0-9a-f]{6}$/i",Functionality::randomHexColor());
+ // test random hsl
+ $this->assertMatchesRegularExpression("/^hsl\([0-9]{1,3}, [0-9]{1,3}%, [0-9]{1,3}%\)$/i",Functionality::randomHsl());
+ // test random number
+ $this->assertIsInt(Functionality::randomNumber());
+ // test random password
+ $this->assertIsString(Functionality::randomString());
+ }
+}
diff --git a/tests/StringsTest.php b/tests/StringsTest.php
new file mode 100644
index 0000000..ade624b
--- /dev/null
+++ b/tests/StringsTest.php
@@ -0,0 +1,20 @@
+assertTrue(Functionality::isPalindrome("racecar"));
+ $this->assertFalse(Functionality::isPalindrome("racecarod"));
+ // capitalize test
+ $this->assertEquals("Racecar", Functionality::capitalize("racecar"));
+ $this->assertEquals("Racecar In Race", Functionality::capitalize("Racecar in race"));
+ // reverse string test
+ $this->assertEquals("abcd", Functionality::reverseString("dcba"));
+ }
+}