Skip to content

Commit

Permalink
Add project
Browse files Browse the repository at this point in the history
  • Loading branch information
relliv committed Apr 22, 2022
1 parent b6a94ed commit c4916bf
Show file tree
Hide file tree
Showing 31 changed files with 1,796 additions and 0 deletions.
1 change: 1 addition & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: off
766 changes: 766 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
* text=auto

.github/ export-ignore
tests/ export-ignore

.codecov.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.styleci.yml export-ignore

phpunit.xml export-ignore
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.idea/

build/
node_modules/
vendor/

*.bak
*.cache
*.clover
*.orig

*.lock

mix-manifest.json

resources/apps/
.vscode/settings.json
67 changes: 67 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
preset: psr12

risky: true

enabled:
- align_double_arrow
- align_equals
- align_phpdoc
- alpha_ordered_imports
- binary_operator_spaces
- blank_line_before_continue
- blank_line_before_declare
- blank_line_before_return
- blank_line_before_throw
- blank_line_before_try
- cast_spaces
- combine_consecutive_issets
- const_separation
- dir_constant
- fully_qualified_strict_types
- logical_operators
- method_separation
- no_alias_functions
- no_blank_lines_after_phpdoc
- no_blank_lines_between_traits
- no_empty_comment
- no_empty_phpdoc
- no_extra_block_blank_lines
- no_extra_consecutive_blank_lines
- no_short_bool_cast
- no_trailing_comma_in_singleline_array
- no_unneeded_control_parentheses
- no_unused_imports
- ordered_class_elements
- php_unit_construct
- php_unit_fqcn_annotation
- phpdoc_indent
- phpdoc_inline_tag
- phpdoc_link_to_see
- phpdoc_no_access
- phpdoc_no_empty_return
- phpdoc_no_package
- phpdoc_no_useless_inheritdoc
- phpdoc_order
- phpdoc_property
- phpdoc_return_self_reference
- phpdoc_scalar
- phpdoc_separation
- phpdoc_summary
- phpdoc_to_comment
- phpdoc_trim
- phpdoc_type_to_var
- phpdoc_types
- phpdoc_types_order
- phpdoc_var_without_name
- property_separation
- self_accessor
- short_array_syntax
- short_list_syntax
- single_line_class_definition
- single_line_throw
- single_quote
- space_after_semicolon
- standardize_not_equals
- ternary_to_null_coalescing
- trailing_comma_in_multiline_array
- trim_array_spaces
95 changes: 95 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Readable Numbers

[![EgoistDeveloper Readable Numbers](https://preview.dragon-code.pro/EgoistDeveloper/Readable-Numbers.svg?brand=laravel)](https://github.com/laravel-ready/readable-numbers)

[![Stable Version][badge_stable]][link_packagist]
[![Unstable Version][badge_unstable]][link_packagist]
[![Total Downloads][badge_downloads]][link_packagist]
[![License][badge_license]][link_license]

Human readable numbers for Laravel. In some cases, you may need to format numbers in a way that is easier to read. Especially when you are dealing with numbers that are very large, for example we want to show page views and we have `100000000` views. So we can show it in the `100M` format.

## Installation

```bash
composer require laravel-ready/readable-numbers
```

## Thresholds

| Threshold | Suffix | Result |
| ------------------ | ----------- | ------ |
| 900 | | 900 |
| 900.000 | k | 0.9 K |
| 900.000.000 | m | 0.9 M |
| 900.000.000.000 | b | 9 T |
| 90.000.000.000.000 | t | 900 T |

## Usages

`make` method takes 3 aguments: `make(float $value, int $decimals = 1, $lang = null)`


### Service Example

```php

use LaravelReady\ReadableNumbers\Services\ReadableNumbers;

...

$readableNumber = ReadableNumbers::make(123456789); // 123.5 M
$readableNumber = ReadableNumbers::make(-123456789); // -123.5 M

// with more decimals
$readableNumber = ReadableNumbers::make(123456789, 2); // 123.46 M

// with target language (default is english)
$readableNumber = ReadableNumbers::make(123456789, 2, 'tr'); // 123.46 Mn
$readableNumber = ReadableNumbers::make(123456789, 3, 'ja'); // 123.457 億
$readableNumber = ReadableNumbers::make(123456789, 4, 'de'); // 123.4568 Mio.

```

### Directive Example

There is only one directive: `@readableNumber()`, again takes three arguments: `@readableNumber(float $value, int $decimals = 1, $lang = null)` and all arguments are required. If you use a multi-language system, you should remember to directives are cached. So, you should pass decimal count and language.


```html

...

<span>
@readableNumber(123456789, 1, app()->getLocale())
</span>

...

<span class="view-counter">
<i class="icon icon-eye"></i>

Viewed @readableNumber($blogPost->views, 1, app()->getLocale()) times
</span>

```

## Languages

Supported languages are listed [here](lang/) and reference are used in [unicode.org](https://www.unicode.org/cldr/cldr-aux/charts/28/verify/numbers/). If you want to add your own language and send PR.

Don't forget to these shortings are depends on a mathematical view.


[badge_downloads]: https://img.shields.io/packagist/dt/laravel-ready/readable-numbers.svg?style=flat-square

[badge_license]: https://img.shields.io/packagist/l/laravel-ready/readable-numbers.svg?style=flat-square

[badge_stable]: https://img.shields.io/github/v/release/laravel-ready/readable-numbers?label=stable&style=flat-square

[badge_unstable]: https://img.shields.io/badge/unstable-dev--main-orange?style=flat-square

[link_license]: LICENSE

[link_packagist]: https://packagist.org/packages/laravel-ready/readable-numbers

57 changes: 57 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "laravel-ready/readable-numbers",
"description": "Human readable numbers for Laravel",
"type": "library",
"license": "MIT",
"version": "1.0.0",
"keywords": [
"laravel",
"readable numbers",
"human readable numbers"
],
"authors": [
{
"name": "EgoistDeveloper",
"email": "[email protected]"
}
],
"support": {
"issues": "https://github.com/laravel-ready/theme-store/issues",
"source": "https://github.com/laravel-ready/theme-store"
},
"require": {
"php": "^8.0.2",
"illuminate/support": "^9.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"orchestra/testbench": "^7.0.0",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"LaravelReady\\ReadableNumbers\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests"
}
},
"config": {
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"LaravelReady\\ReadableNumbers\\ReadableNumbersServiceProvider"
],
"aliases": {
"ReadableNumbers": "LaravelReady\\ReadableNumbers\\Facades\\ReadableNumbers"
}
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
60 changes: 60 additions & 0 deletions database/migrations/2022_01_01_100000_create_ts_themes_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTsThemesTable extends Migration
{
public function __construct()
{
$this->prefix = Config::get('theme-store.default_table_prefix', 'ts_');

$this->table = "{$this->prefix}_themes";
}

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable($this->table)) {
Schema::create($this->table, function (Blueprint $table) {
$table->bigIncrements('id');

$table->string('name', 50);
$table->string('slug', 50)->unique();
$table->text('description');
$table->string('vendor', 50);
$table->string('group', 50);
$table->boolean('status')->default(true);
$table->string('cover', 50)->nullable();
$table->boolean('featured')->default(false);

$table->unique(['slug', 'vendor', 'group']);

$table->softDeletes();
$table->timestamps();
});
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable($this->table)) {
Schema::table($this->table, function (Blueprint $table) {
$table->dropUnique(['slug', 'vendor', 'group']);

$table->dropIfExists();
});
}
}
}
55 changes: 55 additions & 0 deletions database/migrations/2022_01_01_100001_create_ts_authors_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTsAuthorsTable extends Migration
{
public function __construct()
{
$this->prefix = Config::get('theme-store.default_table_prefix', 'ts_');

$this->table = "{$this->prefix}_authors";
}

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable($this->table)) {
Schema::create($this->table, function (Blueprint $table) {
$table->bigIncrements('id');

$table->string('name', 50);
$table->string('slug', 50);
$table->string('contact', 50);
$table->string('avatar', 50)->nullable();
$table->boolean('featured')->default(false);

$table->softDeletes();
$table->timestamps();

$table->unique(['name', 'contact']);
});
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (Schema::hasTable($this->table)) {
Schema::table($this->table, function (Blueprint $table) {
$table->dropIfExists();
});
}
}
}
Loading

0 comments on commit c4916bf

Please sign in to comment.