Download the PHP package rinimisini/php-utilities without Composer
On this page you can find all versions of the php package rinimisini/php-utilities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rinimisini/php-utilities
More information about rinimisini/php-utilities
Files in rinimisini/php-utilities
Package php-utilities
Short Description PHP implementation of different JavaScript built-in classes
License MIT
Informations about the package php-utilities
PHP Utilities
PHP Utilities is a PHP library that provides implementations of various JavaScript built-in classes like Set
, Map
, and others. This library allows PHP developers to work with similar functionality found in JavaScript, but adapted for PHP environments.
Features
- Set Class: A PHP implementation of JavaScript's
Set
class, providing methods for adding unique elements, deleting elements, performing set operations (union, intersection, and difference), and more. - Future updates will include more classes such as:
- Map
- WeakSet
- WeakMap
Requirements
- PHP: ^8.0
Installation
You can install this package via Composer:
Usage
Set Class
The Set class behaves similarly to JavaScript's Set. It allows storing unique elements and provides methods to perform common set operations.
Creating a Set
Adding Elements to the Set
Checking if an Element Exists
Deleting an Element
Clearing the Set
Getting the Set Size
Set Operations
The Set class supports common set operations like union, intersection, and difference.
Union
Intersection
Difference
Iterating Over the Set
Serialization
Map Class
The Map class behaves similarly to JavaScript's Map. It allows storing key-value pairs where keys can be of any type, including objects.
Creating a Map
Setting Key-Value Pairs
Retrieving Values
Checking if a Key Exists
Deleting an Entry
Iterating Over the Map
Using forEach
Retrieving Keys and Values
Clearing the Map
WeakSet Class
The WeakSet class allows storing objects weakly, meaning they will be garbage collected when no other references exist.
Creating a WeakSet
Adding Objects to the WeakSet
Checking if an Object Exists
Removing an Object
Clearing the WeakSet
Iterating Over the WeakSet
Future Plans
The current release includes JavaScript-inspired classes such as:
- Map: A collection of key-value pairs with unique keys.
- WeakSet: A collection that stores objects weakly, allowing them to be garbage collected if no other references exist.
Future releases may include additional JavaScript-inspired classes such as:
- WeakMap: A collection of key-value pairs where the keys are objects and references are weak.
Contributing
Contributions are welcome! If you'd like to contribute, feel free to open a pull request or submit issues for features and bug reports.
Steps to Contribute
- Fork this repository.
- Create a new feature branch:
git checkout -b feature/my-feature
. - Commit your changes:
git commit -m 'Add some feature'
. - Push the branch:
git push origin feature/my-feature
. - Open a Pull Request.
License
This project is licensed under the MIT License. See the LICENSE file for more details.