PHPackages                             cook/data-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cook/data-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cook/data-utils
===============

A utility module for handling collections, arrays, and string manipulations efficiently.

00PHPCI passing

Since Mar 1Pushed 1y agoCompare

[ Source](https://github.com/CookAPI/DataUtils)[ Packagist](https://packagist.org/packages/cook/data-utils)[ RSS](/packages/cook-data-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Cook Data Utils
===============

[](#cook-data-utils)

Cook Data Utils is a PHP library providing utility functions for handling collections, arrays, strings, numbers, and dates.
The module is designed with performance, modularity, and lazy evaluation in mind.

Features
--------

[](#features)

- Collection Handling (map, filter, reduce, lazy evaluation)
- Array Manipulations (grouping, transformation)
- String Formatting (camelCase, snake\_case conversion)
- Number Formatting (rounding, precision formatting)
- Date Utilities (formatting, differences)

Installation
------------

[](#installation)

Install the package using Composer:

```
composer require cook/data-utils
```

Usage examples
--------------

[](#usage-examples)

### Collection

[](#collection)

```
use Cook\DataUtils\Collection;

$collection = new Collection([1, 2, 3, 4, 5]);

// Map: Multiply each number by 2
$doubled = $collection->map(fn(int $n) => $n * 2);
print_r(iterator_to_array($doubled)); // [2, 4, 6, 8, 10]

// Filter: Keep only even numbers
$filtered = $collection->filter(fn(int $n) => $n % 2 === 0);
print_r(iterator_to_array($filtered)); // [2, 4]

// Reduce: Sum all numbers
$sum = $collection->reduce(fn(int $acc, int $n) => $acc + $n, 0);
echo "Sum: $sum\n"; // Sum: 15
```

### Array Utilities

[](#array-utilities)

```
use Cook\DataUtils\ArrayHelper;

$data = [
    ['id' => 1, 'category' => 'A'],
    ['id' => 2, 'category' => 'B'],
    ['id' => 3, 'category' => 'A'],
];

// Group by category
$grouped = ArrayHelper::groupBy($data, 'category');
print_r($grouped);
```

### String Formatting

[](#string-formatting)

```
use Cook\DataUtils\StringFormatter;

echo StringFormatter::toCamelCase('hello_world'); // helloWorld
echo StringFormatter::toSnakeCase('HelloWorld');  // hello_world
```

### Number Formatting

[](#number-formatting)

```
use Cook\DataUtils\NumberFormatter;

echo NumberFormatter::format(123.456, 2); // 123.46
echo NumberFormatter::roundUp(123.456, 0); // 124
echo NumberFormatter::roundDown(123.999, 0); // 123
```

### Date Utilities

[](#date-utilities)

```
use Cook\DataUtils\DateHelper;

echo DateHelper::now(); // 2024-03-01 12:34:56
echo DateHelper::format('2024-03-01 12:34:56', 'Y-m-d'); // 2024-03-01
echo DateHelper::diffInDays('2024-03-01', '2024-03-06'); // 5
```

Development &amp; Testing
-------------------------

[](#development--testing)

Run tests using PHPUnit:

```
vendor/bin/phpunit
```

Check code style using PHP CodeSniffer:

```
vendor/bin/phpcs --standard=PSR12 src/
```

Run static analysis using PHPStan:

```
vendor/bin/phpstan analyse --level=8 src/
```

License
-------

[](#license)

This package is licensed under the MIT License.

Contributing
------------

[](#contributing)

Contributions are welcome. Fork the repository, open issues, or submit pull requests.

Links
-----

[](#links)

```
GitHub: https://github.com/CookApi/DataUtils
Packagist: https://packagist.org/packages/cook/data-utils

```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity17

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc929689022cd317431f6d9888d0851925265c390170f38522df18b851e9d134?d=identicon)[coreapi](/maintainers/coreapi)

---

Top Contributors

[![PixeleeCode](https://avatars.githubusercontent.com/u/56721751?v=4)](https://github.com/PixeleeCode "PixeleeCode (9 commits)")

### Embed Badge

![Health badge](/badges/cook-data-utils/health.svg)

```
[![Health](https://phpackages.com/badges/cook-data-utils/health.svg)](https://phpackages.com/packages/cook-data-utils)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
