PHPackages                             upward/formatters - 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. upward/formatters

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

upward/formatters
=================

Formatters utils

v1.4.5(1y ago)0157↓84.3%1MITPHPPHP ^8.1

Since Nov 5Pushed 11mo agoCompare

[ Source](https://github.com/upwardphp/formatters)[ Packagist](https://packagist.org/packages/upward/formatters)[ RSS](/packages/upward-formatters/feed)WikiDiscussions 1.x Synced today

READMEChangelog (9)Dependencies (1)Versions (11)Used By (1)

Upward Formatters
=================

[](#upward-formatters)

`Upward Formatters` is a PHP package that provides utilities for formatting, validating, and anonymizing documents such as CPF, CNPJ, numbers, and dates. It implements PSR-4 for autoloading and can be easily integrated into any PHP project.

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

[](#installation)

To install the package, use Composer:

```
composer require upward/formatters
```

Document usage
--------------

[](#document-usage)

- [Overview](docs/documents/OVERVIEW.md)
- [CPF](docs/documents/CPF.md)
- [CNPJ](docs/documents/CNPJ.md)
- [Folder](docs/documents/FOLDER.md)

### Examples

[](#examples)

#### Working with CPF Documents

[](#working-with-cpf-documents)

The CPF (Cadastro de Pessoas Físicas) is the Brazilian individual taxpayer registry identification. Below are examples of how to validate, format, and anonymize CPF numbers:

```
// Creating and validating a CPF Document
use Upward\Formatters\Documents\CpfDocument;
use Upward\Formatters\Document;

// Initialize with a CPF number
$cpf = new CpfDocument(value: '12345678909');
$document = new Document($cpf);

// Validate the CPF (throws exception if invalid)
try {
    $document->validate();
    echo "CPF is valid!";
} catch (\Exception) {
    //
}

// Format the CPF with standard mask
echo $document->format();    // Outputs: 123.456.789-09

// Create an anonymized version for privacy
echo $document->anonymize(); // Outputs: 123.***.***-09
```

#### Working with CNPJ Documents

[](#working-with-cnpj-documents)

The CNPJ (Cadastro Nacional da Pessoa Jurídica) is the Brazilian registry for legal entities. Here's how to work with CNPJ documents:

```
// Creating and working with CNPJ Documents
use Upward\Formatters\Documents\CnpjDocument;
use Upward\Formatters\Document;

// Initialize with a CNPJ number
$cnpj = new CnpjDocument(value: '12345678000195');
$document = new Document($cnpj);

// Validate the CNPJ
try {
    $document->validate();
    echo "CNPJ is valid and can be used!";
} catch (\Exception) {
    //
}

// Apply standard CNPJ formatting
echo $document->format();    // Outputs: 12.345.678/0001-95

// Generate privacy-safe version for displaying
echo $document->anonymize(); // Outputs: 12.***.***/0001-95
```

#### Managing Documents with Folder

[](#managing-documents-with-folder)

The `Folder` class provides a convenient way to manage collections of documents:

```
// Working with multiple documents
use Upward\Formatters\Folder;
use Upward\Formatters\Documents\CpfDocument;
use Upward\Formatters\Documents\CnpjDocument;
use Upward\Formatters\Document;
use Upward\Formatters\Exceptions\Documents\InvalidDocumentException;

// Create a document collection
$folder = new Folder();

// Add different document types
$folder->push(new Document(new CpfDocument('12345678909')));
$folder->push(new Document(new CnpjDocument('12345678000195')));

// Count documents in collection
echo "Total documents: " . count($folder); // Outputs: 2

// Filter for only valid documents
$validDocs = $folder->valid();

// Process each document in the collection
$folder->each(callback: static function (Document $document, string | int $key): void {
    // Perform operations on each document
});

// Validate all documents at once (will throw exception on first invalid document)
try {
    $folder->validate();
    echo "All documents are valid!";
} catch (InvalidDocumentException) {
    //
}
```

For more detailed examples and advanced usage, please refer to the documentation for each document type.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance46

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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 ~27 days

Recently: every ~52 days

Total

10

Last Release

352d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/521875?v=4)[upward](/maintainers/upward)[@upward](https://github.com/upward)

---

Top Contributors

[![victorhbbergamo](https://avatars.githubusercontent.com/u/50025273?v=4)](https://github.com/victorhbbergamo "victorhbbergamo (44 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/upward-formatters/health.svg)

```
[![Health](https://phpackages.com/badges/upward-formatters/health.svg)](https://phpackages.com/packages/upward-formatters)
```

###  Alternatives

[ip2location/ip2location-laravel

Lookup for visitor's IP information, such as country, region, city, coordinates, zip code, time zone, ISP, domain name, connection type, area code, weather, MCC, MNC, mobile brand name, elevation and usage type.

82548.8k1](/packages/ip2location-ip2location-laravel)[michalmanko/php-library-holiday

A library to calculate holidays

2182.4k1](/packages/michalmanko-php-library-holiday)[typo3/cms-introduction

The Official TYPO3 Introduction Package

1882.7k6](/packages/typo3-cms-introduction)[alt-design/alt-sitemap

Alt Sitemap addon, create a sitemap from Statamic entries

1223.5k](/packages/alt-design-alt-sitemap)

PHPackages © 2026

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