ahamed/jsphp

A php library for implementing Array, Object, String methods in JavaScript way.

v0.6 2023-08-03 08:59 UTC

This package is auto-updated.

Last update: 2024-04-03 12:48:21 UTC


README

BannerWithImageAndText

Packagist PHP Version Support GitHub GitHub Workflow Status (branch) GitHub issues GitHub closed issues GitHub pull requests GitHub closed pull requests GitHub language count GitHub top language GitHub repo size GitHub All Releases GitHub contributors GitHub last commit GitHub Release Date GitHub release (latest by date including pre-releases) GitHub tag (latest by date)

Packagist Version Packagist Downloads Packagist Stars

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.

composer require ahamed/jsphp

Usage

After successful installation, include the library into your project.

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 a lot. Thanks to MDN, this site helps me to learn a lot of JS.

Follow the wiki pages for the details documentation.

Testing

You can run PHPUnit testing and PHP_CodeSniffer.

  • For running unit test
    composer run-script test
  • For running phpcs test
    composer run-script phpcs