Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create initial Number utility package #1

Merged
merged 16 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* text=auto eol=lf

tests/ export-ignore
.github/ export-ignore
composer.lock export-ignore
phpunit.xml export-ignore
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
caendesilva marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: PHP Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
run-tests:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: vendor/bin/pest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,6 @@

# Embedded web-server pid file
/.web-server-pid

# PhpStorm
/.idea
caendesilva marked this conversation as resolved.
Show resolved Hide resolved
66 changes: 66 additions & 0 deletions README.md
caendesilva marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# PHP Number Utility

This library provides a set of utility functions for working with numbers in PHP, including formatting as currency, percentages, ordinals, and more.

## Installation

```bash
composer require friendsofphp/number
```

## Usage

### Basic usage

```php
use FOP\Number\Number;

// Format a number
$formattedNumber = Number::format(1234567.89);

// Spell out a number
$spelledNumber = Number::spell(1234);

// Get the ordinal form of a number
$ordinalNumber = Number::ordinal(42);

// Format a number as a percentage
$percentage = Number::percentage(0.75);

// Format a number as currency
$currency = Number::currency(1234.56, 'EUR');

// Format file size
$fileSize = Number::fileSize(1024);

// Get a human-readable representation of a number
$humanReadable = Number::forHumans(1234567.89);
```

### Advanced usage

```php
use FOP\Number\Number;

// Set a custom locale
Number::useLocale('fr');

// Use the custom locale for formatting
$formattedNumber = Number::format(1234.56);

// Change the precision when formatting
$preciseNumber = Number::format(1234.56789, 2);

// Use a custom locale for currency formatting
$currencyFormatted = Number::currency(1234.56, 'GBP', 'fr');
```

## Information

### License

This package is open-sourced software licensed under the [MIT License](LICENSE).

### Attributions

The Number utility is ported from Laravel, licensed under the MIT Licence.
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "friendsofphp/number",
caendesilva marked this conversation as resolved.
Show resolved Hide resolved
"description": "Adds a Number utility class",
caendesilva marked this conversation as resolved.
Show resolved Hide resolved
"license": "MIT",
"autoload": {
"psr-4": {
"FOP\\Number\\": "src/"
}
},
"authors": [
{
"name": "Caen De Silva",
"email": "caen@desilva.se"
}
],
"require": {
"php": "^8.0",
caendesilva marked this conversation as resolved.
Show resolved Hide resolved
"ext-intl": "*"
},
"require-dev": {
"pestphp/pest": "^2.24"
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
}
}
Loading