PHPackages                             elrayes/data-normalizer - 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. elrayes/data-normalizer

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

elrayes/data-normalizer
=======================

Data Normalizer: recursively normalize data and access it via array, object, and dot-notation (with escaped dots).

v1.1.0(3mo ago)067↓90.6%MITPHPPHP &gt;=8.3

Since Aug 14Pushed 3mo agoCompare

[ Source](https://github.com/Ahmed-Elrayes/data-normalizer)[ Packagist](https://packagist.org/packages/elrayes/data-normalizer)[ RSS](/packages/elrayes-data-normalizer/feed)WikiDiscussions master Synced today

READMEChangelog (9)Dependencies (4)Versions (11)Used By (0)

Data Normalizer
===============

[](#data-normalizer)

Recursively normalize values and access them like arrays, objects, or using dot notation (with support for keys that contain dots).

- Converts null, empty strings and common "n/a" variants (e.g., `n/a`, `N A`, `n-a`, `n.a`) to `null`.
- Recursively normalizes arrays and Illuminate Collections while preserving keys.
- Wraps arrays/collections in a NormalizedData object that supports:
    - `$data->key` (object-style)
    - `$data['key']` (array-style)
    - `$data['a.b.c']` (dot notation)
    - Keys with dots using exact-key precedence or escaping: `$data['date.upload']` or `$data['date\.upload']`.

Install
-------

[](#install)

### Packagist (recommended)

[](#packagist-recommended)

```
composer require elrayes/data-normalizer

```

This package supports Laravel package auto-discovery, so the Service Provider and the `Normalizer` facade alias are registered automatically.

Usage
-----

[](#usage)

### Facade

[](#facade)

```
use Elrayes\Normalizer\Facades\Normalizer;

$data = Normalizer::normalize([
    'item' => '  ',
    'date.upload' => '2024-01-01',
    'nested' => ['x' => 'n/a', 'y' => 'value'],
]);

// Object-style
$value = $data->item; // null

// Array-style
$upload = $data['date.upload']; // '2024-01-01' (exact key precedence)

// Dot-notation for nested
$y = $data['nested.y']; // 'value'

// Escaping dot when the key contains a dot
$upload2 = $data['date\.upload']; // '2024-01-01'

// Convert back to JSON
$json = $data->toJson();
$prettyJson = $data->toPrettyJson();
```

### Class

[](#class)

```
use Elrayes\Normalizer\Support\Normalizer;

$normalizer = new Normalizer();
$data = $normalizer->normalize([
    'item' => '  ',
    'date.upload' => '2024-01-01',
    'nested' => ['x' => 'n/a', 'y' => 'value'],
]);

// ... same as facade
```

Configuration
-------------

[](#configuration)

Publish the config and customize behavior:

```
php artisan vendor:publish --tag=normalizer-config

```

The config/normalizer.php file supports:

- treat\_empty\_string\_as\_null: bool (default: true)
- treat\_whitespace\_as\_empty: bool (default: true)
- na\_match\_mode: 'compressed' | 'exact' (default: 'compressed')
    - compressed: removes non-alphanumeric characters before comparing
    - exact: compares exact trimmed lowercase strings
- na\_values: array of strings (default includes common N/A variants: \["na", "n/a", "n a", "n-a", "n.a", "none", "null", "-"\])

API
---

[](#api)

### Normalizer

[](#normalizer)

- `Normalizer::normalize(mixed $value): NormalizedData|mixed`
- `Normalizer::normalizeArray(array|Collection $input): array`
- `Normalizer::normalizeCollection(Collection $input): Collection`

### NormalizedData

[](#normalizeddata)

- `$data->toArray(): array` - Recursively convert to plain array.
- `$data->toObject(): object` - Recursively convert to nested `stdClass` objects.
- `$data->toJson(int $options = 0): string` - Convert to JSON string.
- `$data->toPrettyJson(): string` - Convert to pretty-printed JSON string.
- `$data->all(): array` - Get the underlying items (one level).
- `$data->map(callable $callback): NormalizedData` - Recursively map over the data.
- `$data->mapInto(string $class): static` - Map the items into a new class instance.
- `$data->mapWithKeys(callable $callback): static` - Run a dictionary map over the items.
- `$data->mapToGroups(callable $callback): static` - Run a grouping map over the items.
- `$data->mapSpread(callable $callback): static` - Run a map over each nested chunk of items.
- `$data->mapToDictionary(callable $callback): static` - Run a dictionary map over the items (similar to mapToGroups).
- `$data->chunk(int $size, bool $preserveKeys = false): static` - Chunk the items into multiple, smaller collections of a given size.
- `$data->chunkByKey(callable|string $callback): static` - Chunk the collection into smaller collections by a given key or callback.
- `$data->pluck(string $key): NormalizedData` - Get the values of a given key.
- `$data->unique(string|callable|null $key = null): NormalizedData` - Return only unique items.
- `$data->sum(string|callable|null $key = null): mixed` - Sum the values of a given key.
- `$data->avg(string|callable|null $key = null): mixed` - Get the average value of a given key.
- `$data->average(string|callable|null $key = null): mixed` - Alias for avg.
- `$data->max(string|callable|null $key = null): mixed` - Get the max value of a given key.
- `$data->min(string|callable|null $key = null): mixed` - Get the min value of a given key.
- `$data->count(?string $key = null, mixed $operator = null, mixed $value = null): int` - Number of items in the top level or matching criteria.
- `$data->when($value, callable $callback, ?callable $default = null): mixed` - Apply callback if value is true.
- `$data->unless($value, callable $callback, ?callable $default = null): mixed` - Apply callback if value is false.
- `$data->filter(?callable $callback = null): static` - Filter items by callback.
- `$data->reject($callback = true): static` - Create a new collection by filtering items using the given callback.
- `$data->where(string $key, mixed $operator = null, mixed $value = null): static` - Filter items by key/value pair.
- `$data->first(?callable $callback = null, mixed $default = null): mixed` - Get first item passing truth test.
- `$data->firstWhere(string $key, mixed $operator = null, mixed $value = null): mixed` - Get first item matching criteria.
- `$data->last(?callable $callback = null, mixed $default = null): mixed` - Get the last item from the collection.
- `$data->each(callable $callback): self` - Run an associative iteration over each of the items.
- `$data->every($key, $operator = null, $value = null): bool` - Determine if all items pass the given test.
- `$data->contains($key, $operator = null, $value = null): bool` - Determine if an item exists in the collection.
- `$data->except($keys): static` - Create a new collection by excluding the given keys.
- `$data->only($keys): static` - Create a new collection containing only the specified keys.
- `$data->flatMap(callable $callback): static` - Map a collection and flatten the result by a single level.
- `$data->collapse(): static` - Collapse the collection of items into a single array.
- `$data->forget($keys): self` - Remove an item from the collection by key.
- `$data->groupBy($groupBy, bool $preserveKeys = false): static` - Group an associative array by a field or using a callback.
- `$data->isEmpty(): bool` - Determine if the collection is empty.
- `$data->isNotEmpty(): bool` - Determine if the collection is not empty.
- `$data->keyBy($keyBy): static` - Key an associative array by a field or using a callback.
- `$data->keys(): static` - Get the keys of the collection items.
- `$data->merge($items): static` - Merge the collection with the given items.
- `$data->reduce(callable $callback, mixed $initial = null): mixed` - Reduce the collection to a single value.
- `$data->sort(?callable $callback = null): static` - Sort through each item with a callback.
- `$data->sortBy($callback, int $options = SORT_REGULAR, bool $descending = false): static` - Sort the collection using the given callback.
- `$data->sortByDesc($callback, int $options = SORT_REGULAR): static` - Sort the collection in descending order using the given callback.
- `$data->tap(callable $callback): self` - Pass the collection to the given callback and then return it.
- `$data->values(): static` - Reset the keys on the underlying array.

Author
------

[](#author)

- Ahmed Elrayes

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance79

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~26 days

Recently: every ~19 days

Total

9

Last Release

108d ago

PHP version history (2 changes)v1.0.0PHP &gt;=8.1

v1.1.0PHP &gt;=8.3

### Community

Maintainers

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

---

Top Contributors

[![Ahmed-Elrayes](https://avatars.githubusercontent.com/u/30704271?v=4)](https://github.com/Ahmed-Elrayes "Ahmed-Elrayes (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elrayes-data-normalizer/health.svg)

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M10](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M375](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

244.6M136](/packages/illuminate-cookie)

PHPackages © 2026

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