https://github.com/ahamed/jsphp
A php library for implementing Array, Object, String methods in JavaScript way.
https://github.com/ahamed/jsphp
composer composer-package hacktoberfest hacktoberfest2021 php phpcs phpunit unit-testing utility-library
Last synced: about 2 months ago
JSON representation
A php library for implementing Array, Object, String methods in JavaScript way.
- Host: GitHub
- URL: https://github.com/ahamed/jsphp
- Owner: ahamed
- License: mit
- Created: 2020-06-10T11:03:22.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-03T11:21:42.000Z (almost 2 years ago)
- Last Synced: 2025-03-17T23:57:46.985Z (3 months ago)
- Topics: composer, composer-package, hacktoberfest, hacktoberfest2021, php, phpcs, phpunit, unit-testing, utility-library
- Language: PHP
- Homepage:
- Size: 242 KB
- Stars: 33
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README

               
  
### Why this library?
While using ***php*** **Array** methods it feels troublesome because of their unstructured patterns.For example, you are using the `array_map` and the `array_filter` methods of *php*. At the time of using, you may notice that for the `array_map` method, the `$callback` comes as the first parameter of the method, then the `$array` but for the `array_filter` method, the `$array` comes first then the `$callback`. And this mixed structure exists everywhere.
Then I've discovered that the **JavaScript** uses a good pattern for these cases and I am also a big fan of JavaScript. That's why I've decided to build this library. I can say that the JavaScript lovers can get the pure feelings of JavaScript by using this and the JavaScript non-lovers also get the advantage of the good structure of **array** manipulations.
### Future Journey
Currently I've covered only the `array` methods. In near future I will add the `object` and `string` methods.### Installation
`composer` is needed for installing the package. If you have composer installed then run the command.```console
composer require ahamed/jsphp
```### Usage
After successful installation, include the library into your project.```php
require_once __DIR__ . '/vendor/autoload.php';use Ahamed\JsPhp\JsArray;
$data = [1, 2, 3, 4, 5];
$array = new JsArray($data);$square = $array->map(
function ($item) {
return $item * $item;
}
);print_r($square);
```
# Documentation
> For writing this documentation I've followed the [MDN](https://developer.mozilla.org/en-US/) a lot. Thanks to **MDN**, this site helps me to learn a lot of JS.Follow the wiki pages for the details documentation.
+ [JsArray](https://github.com/ahamed/JsPhp/wiki/JsArray)
+ [JsObject](https://github.com/ahamed/JsPhp/wiki/JsObject)### Testing
You can run `PHPUnit` testing and `PHP_CodeSniffer`.
- For running unit test
```console
composer run-script test
```
- For running phpcs test
```console
composer run-script phpcs
```