PHPackages                             joskolenberg/cardinal - 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. joskolenberg/cardinal

ActiveLibrary

joskolenberg/cardinal
=====================

Small wrapper for cardinal directions

v1.0.0(6y ago)032MITPHPPHP ^7.0

Since Sep 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/joskolenberg/cardinal)[ Packagist](https://packagist.org/packages/joskolenberg/cardinal)[ RSS](/packages/joskolenberg-cardinal/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/4cbeda6e532cec34eee99d5ee45d33f64a5c77f33d8962a8ce932081dfbb8a46/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f736b6f6c656e626572672f63617264696e616c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/joskolenberg/cardinal/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/e01220b1fc7db98fd01f2bbd358a16600e01f3c704ca403eb4287df5d7b53e49/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f736b6f6c656e626572672f63617264696e616c2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/joskolenberg/cardinal/?branch=master)[![Build Status](https://camo.githubusercontent.com/c4f4570d0e48daabc16e3516be1d872930c25266a570ca6a88b1f6a445a0374b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a6f736b6f6c656e626572672f63617264696e616c2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/joskolenberg/cardinal/build-status/master)[![Total Downloads](https://camo.githubusercontent.com/64c3c94103e3fa0ac2a632a5196cfda295622015934bd38e46a50a7196afffde/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736b6f6c656e626572672f63617264696e616c2f646f776e6c6f616473)](https://packagist.org/packages/joskolenberg/cardinal)[![Latest Stable Version](https://camo.githubusercontent.com/61a7bde0a83f23ff94a4ba2cf7a2f029838358aefec327adad634e869bd19bc8/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736b6f6c656e626572672f63617264696e616c2f762f737461626c65)](https://packagist.org/packages/joskolenberg/cardinal)[![License](https://camo.githubusercontent.com/70b9478485718c9d81217baae1a5e2e84c0be100a894c7e3be2cf4439874083a/68747470733a2f2f706f7365722e707567782e6f72672f6a6f736b6f6c656e626572672f63617264696e616c2f6c6963656e7365)](https://packagist.org/packages/joskolenberg/cardinal)

Cardinal
========

[](#cardinal)

Little wrapper object to handle cardinal/compass directions.

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

[](#installation)

```
composer require joskolenberg/cardinal

```

Examples
--------

[](#examples)

Create object with degrees (0 to 359.999) and format into string.

```
Cardinal::make(45)->format() // => 'NE'
```

Use precision parameter to be more or less precise.

```
Cardinal::make(66)->format(1) // => 'E'
Cardinal::make(66)->format(2) // => 'NE'
Cardinal::make(66)->format(3) // => 'ENE'
```

Use second and third parameter to switch to fully written directions with divider.

```
Cardinal::make(250)->format(3, true, '-') // => 'WEST-SOUTH-WEST'
```

Create object from string (with or without any divider) and return degrees.

```
Cardinal::make('NNW')->degrees // => 337.5
Cardinal::make('South-West')->degrees // => 225
Cardinal::make('West NorthWest')->degrees // => 292.5
```

Use `formatLocalized()` to get localized string.

```
Cardinal::make(250)->formatLocalized(3, true, '-') // => 'West-South-West'
```

Override `lang()` to create your own localization.

```
use JosKolenberg\Cardinal\Cardinal;

class DutchCardinal extends Cardinal
{
    protected function lang(): array
    {
        return [
            'N' => 'N',
            'E' => 'O',
            'S' => 'Z',
            'W' => 'W',
            'NORTH' => 'Noord',
            'EAST' => 'Oost',
            'SOUTH' => 'Zuid',
            'WEST' => 'West',
        ];
    }
}
```

```
Cardinal::make(157.5)->formatLocalized(3, true, '-') // => 'Zuid-Zuid-Oost'
```

Or integrate with localization in your framework. E.g. Laravel:

```
use JosKolenberg\Cardinal\Cardinal;

class LocalizedCardinal extends Cardinal
{
    protected function lang(): array
    {
        return [
            'N' => __('app.cardinal.n'),
            'E' => __('app.cardinal.e'),
            'S' => __('app.cardinal.s'),
            'W' => __('app.cardinal.w'),
            'NORTH' => __('app.cardinal.north'),
            'EAST' => __('app.cardinal.east'),
            'SOUTH' => __('app.cardinal.south'),
            'WEST' => __('app.cardinal.west'),
        ];
    }
}
```

That's it! Any suggestions or issues? Please contact me!

Happy coding!

Jos Kolenberg

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2437d ago

### Community

Maintainers

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

---

Tags

directionscompasscardinalEastwestnorthsouth

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joskolenberg-cardinal/health.svg)

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

###  Alternatives

[wapmorgan/morphos

A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time.

8351.3M7](/packages/wapmorgan-morphos)[nizsheanez/yii2-asset-converter

Less, Sass, Scss and Phamlp converter for Yii2. No system requires. yii2-composer support, Less autoupdate, customizing of output directory

64167.5k6](/packages/nizsheanez-yii2-asset-converter)

PHPackages © 2026

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