PHPackages                             t-labs-co/formatter - 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. t-labs-co/formatter

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

t-labs-co/formatter
===================

The Laravel Formatter package

1.0.2(1y ago)12[4 PRs](https://github.com/T-Labs-Co/formatter/pulls)MITPHPPHP ^8.4||^8.3||^8.2CI passing

Since Mar 21Pushed 1mo agoCompare

[ Source](https://github.com/T-Labs-Co/formatter)[ Packagist](https://packagist.org/packages/t-labs-co/formatter)[ Docs](https://github.com/T-Labs-Co/formatter)[ GitHub Sponsors](https://github.com/ty-huynh)[ RSS](/packages/t-labs-co-formatter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (13)Versions (6)Used By (0)

The PHP Formatter package
=========================

[](#the-php-formatter-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/358b280dd7617e564f9cfe18966bea820ff11b1446c58a6c7f5309b525c195fd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f742d6c6162732d636f2f666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/t-labs-co/formatter)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c015d62a716fd381132558e813fd658a33643bcdf5cf43e679a4e0e2796dddc5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f742d6c6162732d636f2f666f726d61747465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/t-labs-co/formatter/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/00d2f8ed20b8aeff714c2ecdf264fd072d89140bbadbc65ea93eda8bf1c40401/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f742d6c6162732d636f2f666f726d61747465722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/t-labs-co/formatter/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/0ef0f11237dc7c3bc40918c4d104e897a191af1702350006240cc77f1419ea97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f742d6c6162732d636f2f666f726d61747465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/t-labs-co/formatter)

This package helps you format your PHP strings. You can use it for one string or many, and it's as simple as using Laravel validation.

Work with us
------------

[](#work-with-us)

We're PHP and Laravel whizzes, and we'd love to work with you! We can:

- Design the perfect fit solution for your app.
- Make your code cleaner and faster.
- Refactoring and Optimize performance.
- Ensure Laravel best practices are followed.
- Provide expert Laravel support.
- Review code and Quality Assurance.
- Offer team and project leadership.
- Delivery Manager

Features
--------

[](#features)

- Simple and intuitive syntax for defining formatting rules.
- Support for multiple built-in formatting rules (e.g., trim, replace, limit, date\_format).
- Ability to create custom formatting rules.
- Integration with Laravel models and validation.
- Comprehensive unit tests for ensuring reliability.

PHP and Laravel Version Support
-------------------------------

[](#php-and-laravel-version-support)

This package supports the following versions of PHP:

- PHP: `^8.2`

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

[](#installation)

You can install the package via composer:

```
composer require t-labs-co/formatter
```

Usage
-----

[](#usage)

```
use TLabsCo\Formatter\Formatter;

$formatterRules = [
    'title' => 'trim|replace:Local Composer Dependencies,[Local Composer Dependencies]|replace:[Local Composer Dependencies],[Composer Dependencies]|limit:150',
    'publish_date' => 'date_format:Y-m-d',
];

$data = [
    'title' => '  How to resolve missing Local Composer Dependencies on CentOS 8?  ',
    'publish_date' => '2024/05/02 13:00'
];

$formatted = Formatter::make($data, $formatterRules)->format()->formatted();

/*
Output:
$formatted = [
    'title' => 'How to resolve missing [Composer Dependencies] on CentOS 8?',
    'publish_date' => '2024-05-02'
];
*/
```

Use custom format rule

```
use TLabsCo\Formatter\Rules\FormatterRule;

class Max100FormatRule extends FormatterRule
{
    public function format($attribute, $value)
    {
        if (strlen($value) > 100) {
            return substr($value, 0, 100);
        }

        return $value;
    }
}
// Using with custom rule
use TLabsCo\Formatter\Formatter;

$formatterRules = [
    'title' => 'trim|replace:Local Composer Dependencies,[Local Composer Dependencies]|replace:[Local Composer Dependencies],[Composer Dependencies]|limit:150',
    'publish_date' => 'date_format:Y-m-d',
    'short_description' => ['trim', new Max100FormatRule()],
];

$data = [
    'title' => '  How to resolve missing Local Composer Dependencies on CentOS 8?  ',
    'publish_date' => '2024/05/02 13:00',
    'short_description' => 'Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description Very long description '
];

$formatted = Formatter::make($data, $formatterRules)->format()->formatted();

/*
Output:
$formatted = [
    'title' => 'How to resolve missing [Composer Dependencies] on CentOS 8?',
    'publish_date' => '2024-05-02',
    'short_description' => 'Very long description Very long description Very long description Very long description Very long de'
];
*/
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [T.](https://github.com/ty-huynh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance76

Regular maintenance activity

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76% 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 ~1 days

Total

2

Last Release

413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8096712a46f142a708061822c0644b806cd1000cb5499e408c6b11b12f6a899?d=identicon)[t-labs-co](/maintainers/t-labs-co)

---

Top Contributors

[![ty-huynh](https://avatars.githubusercontent.com/u/1597540?v=4)](https://github.com/ty-huynh "ty-huynh (19 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

formatterhelperslaravelpackagephpstring-formattert-labs-coformatterlaravelstring-helperT.Labs Co.string formatterT.Labs and Co.

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/t-labs-co-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/t-labs-co-formatter/health.svg)](https://phpackages.com/packages/t-labs-co-formatter)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M626](/packages/spatie-laravel-data)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

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