From b85e97988f4b56735bea19d87e998f2cffadf4ae Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Thu, 16 Jun 2022 03:59:47 +0200 Subject: [PATCH 01/11] Update README.md --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3b4b09a..b69d15a 100644 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ -# functionality.php \ No newline at end of file +#

Functionality.php (beta) 🔥

+ +

+ + + + +

+ +## About ✍️ + +- This Is A JavaScript Library To Make Your Work Easier/Faster,
+ You Can See Functionalty.js Website From Here +- Project Created In 15 / 6 / 2022 From 91ddc7fa0ae1d813bcbfc501e9d10483649465de Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Thu, 16 Jun 2022 04:02:42 +0200 Subject: [PATCH 02/11] adding badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b69d15a..3dee6ef 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@

- + - +

## About ✍️ From 8e643311e16cddaac666b109a568076b3ae4eb1c Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Thu, 16 Jun 2022 04:06:19 +0200 Subject: [PATCH 03/11] adding badge styling --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3dee6ef..0431b77 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@

- + - +

## About ✍️ From 5b1c5205af46d91f3aa96be6266bb99482facc93 Mon Sep 17 00:00:00 2001 From: Omar Khaled Date: Thu, 16 Jun 2022 15:58:23 +0200 Subject: [PATCH 04/11] Converted The whole library from js to php --- composer.json | 3 +- src/Functionality.php | 5 +- src/Functions/Arrays.php | 104 ++++++++++++++++++++++++++++++++++++++ src/Functions/Numbers.php | 70 +++++++++++++++++++++++++ src/Functions/Randoms.php | 92 ++++++++++++++++++++++++++++++++- src/Functions/Strings.php | 41 +++++++++++++++ tests/ArraysTest.php | 29 +++++++++++ tests/NumbersTest.php | 23 +++++++++ tests/RandomBoolTest.php | 12 ----- tests/RandomsTest.php | 24 +++++++++ tests/StringsTest.php | 20 ++++++++ 11 files changed, 407 insertions(+), 16 deletions(-) create mode 100644 src/Functions/Arrays.php create mode 100644 src/Functions/Numbers.php create mode 100644 src/Functions/Strings.php create mode 100644 tests/ArraysTest.php create mode 100644 tests/NumbersTest.php delete mode 100644 tests/RandomBoolTest.php create mode 100644 tests/RandomsTest.php create mode 100644 tests/StringsTest.php diff --git a/composer.json b/composer.json index 8ef8aa4..a7edc61 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ } }, "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")); + } +} From aed65122e3984664d9e2cd99020d1aed9891d0d9 Mon Sep 17 00:00:00 2001 From: Omar Khaled Date: Thu, 16 Jun 2022 16:30:52 +0200 Subject: [PATCH 05/11] Added documentation for the library --- README.md | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-- composer.json | 7 ++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0431b77..90987f6 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,73 @@ ## About ✍️ -- This Is A JavaScript Library To Make Your Work Easier/Faster,
- You Can See Functionalty.js Website From Here +- 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 a7edc61..cdca3da 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { - "name": "functionality/functionality.php", + "name": "functionality-library/functionality.php", + "description": "This Is A Php Library To Make Your Work Easier/Faster", + "version": "1.0.0", "type": "library", "license": "MIT", + "scripts": { + "test": "phpunit --verbose tests" + }, "autoload": { "psr-4": { "Functionality\\FunctionalityPhp\\": "src/" From 38e5147374c0654e9e583bf24fe260db7aed8035 Mon Sep 17 00:00:00 2001 From: Omar Khaled Date: Thu, 16 Jun 2022 16:38:24 +0200 Subject: [PATCH 06/11] Changed version from 1.0.0 to 1.0.1 in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cdca3da..1cb6436 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "functionality-library/functionality.php", "description": "This Is A Php Library To Make Your Work Easier/Faster", - "version": "1.0.0", + "version": "1.0.1", "type": "library", "license": "MIT", "scripts": { From 5412d0e354b7f4ee0a9c2830ecf4a2afb6640789 Mon Sep 17 00:00:00 2001 From: Omar Khaled Date: Thu, 16 Jun 2022 16:40:26 +0200 Subject: [PATCH 07/11] Changed version from 1.0.1 to 1.1.0 in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1cb6436..03d7f19 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "functionality-library/functionality.php", "description": "This Is A Php Library To Make Your Work Easier/Faster", - "version": "1.0.1", + "version": "1.1.0", "type": "library", "license": "MIT", "scripts": { From dcf08426ddf6fd02e472dee2d72aaa2f2a283975 Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Thu, 16 Jun 2022 19:32:45 +0200 Subject: [PATCH 08/11] Create FUNDING.yml --- .github/FUNDING.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..102c87c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: alieldeba # Replace with a single Patreon username +open_collective: # 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'] From 6c5dba395c00168940feb67b9c509ad1e113ba16 Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Thu, 16 Jun 2022 19:36:10 +0200 Subject: [PATCH 09/11] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 102c87c..d1aa81e 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,6 +1,6 @@ # These are supported funding model platforms -github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +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: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username From 43e5faec207e51547677bba6564e2210188f0898 Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Thu, 16 Jun 2022 19:40:02 +0200 Subject: [PATCH 10/11] Update FUNDING.yml --- .github/FUNDING.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index d1aa81e..463c94b 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,13 +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] +# 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: # 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'] +# open_collective: # 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'] From 705a1d1d2e695c8ae467f0d7630694bf32b14a73 Mon Sep 17 00:00:00 2001 From: Ali-Eldeba Date: Mon, 20 Jun 2022 01:12:04 +0200 Subject: [PATCH 11/11] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 463c94b..50d2895 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -2,7 +2,7 @@ # 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: # Replace with a single Open Collective 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 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy