Skip to content

Commit b91e1a7

Browse files
committed
first commit
0 parents  commit b91e1a7

File tree

7 files changed

+174
-0
lines changed

7 files changed

+174
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
build
2+
composer.lock
3+
docs
4+
vendor
5+
coverage
6+
.phpunit.result.cache
7+
.idea

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) :vendor_name <author@domain.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Laravel Helpers
2+
3+
Collection of helper functions for laravel.
4+
5+
## Installation
6+
7+
You can install the package via composer:
8+
9+
```bash
10+
composer require yudhatp/laravel-helpers
11+
```
12+
13+
## Usage
14+
15+
```php
16+
use Yudhatp\Helpers\Helpers;
17+
Helpers::terbilang(2000); //Dua Ribu
18+
Helpers::indonesianMonthName("2022-11-28"); //28 November 2022
19+
Helpers::indonesianShortMonthName("2022-11-28"); //28 Nov 2022
20+
```
21+
22+
## Changelog
23+
24+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
25+
26+
27+
## License
28+
29+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "yudhatp/laravel-helpers",
3+
"description": "Collection of helper functions for laravel",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "Yudha T. Putra",
8+
"email": "yudhatp@gmail.com",
9+
"homepage": "https://yudhatp.com",
10+
"role": "Developer"
11+
}
12+
],
13+
"homepage": "https://github.com/yudhatp/laravel-helpers",
14+
"keywords": ["Laravel", "Helpers", "Function"],
15+
"require": {
16+
"php": "^7.3|^8.0",
17+
"laravel/framework": "^6.0|^7.0|^8.0|^9.0"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^9.3",
21+
"symfony/var-dumper": "^5.0"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"Yudhatp\\Helpers\\": "src"
26+
}
27+
},
28+
"autoload-dev": {
29+
"psr-4": {
30+
"Yudhatp\\Helpers\\Tests\\": "tests"
31+
}
32+
},
33+
"scripts": {
34+
"test": "vendor/bin/phpunit",
35+
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
36+
},
37+
"config": {
38+
"sort-packages": true
39+
},
40+
"extra": {
41+
"laravel": {
42+
"providers": [
43+
"Yudhatp\\Helpers\\HelpersServiceProvider"
44+
],
45+
"aliases": {
46+
"Helpers": "Yudhatp\\Helpers\\Facades\\Helpers"
47+
}
48+
}
49+
}
50+
}

src/Helpers.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Yudhatp\Helpers;
4+
5+
class Helpers
6+
{
7+
public static function indonesianMonthName($date) {
8+
$date = date_create($date);
9+
$month = date_format($date,"n");
10+
$day = date_format($date,"d");
11+
$year = date_format($date,"Y");
12+
$name = array (1 => 'Januari','Februari','Maret','April','Mei','Juni','Juli','Agustus','September','Oktober','November','Desember');
13+
return $day.' '.$name[$month].' '.$year;
14+
}
15+
16+
public static function indonesianShortMonthName($date) {
17+
$date = date_create($date);
18+
$month = date_format($date,"n");
19+
$day = date_format($date,"d");
20+
$year = date_format($date,"y");
21+
$name = array (1 => 'Jan','Feb','Mar','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Des');
22+
return $day.' '.$name[$month].' '.$year;
23+
}
24+
25+
public function terbilang($nilai) {
26+
$nilai = abs($nilai);
27+
$huruf = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan", "Sembilan", "Sepuluh", "Sebelas");
28+
$temp = "";
29+
if ($nilai < 12) {
30+
$temp = " ". $huruf[$nilai];
31+
} else if ($nilai <20) {
32+
$temp = $this->terbilang($nilai - 10). " Belas";
33+
} else if ($nilai < 100) {
34+
$temp = $this->terbilang($nilai/10)." Puluh". $this->terbilang($nilai % 10);
35+
} else if ($nilai < 200) {
36+
$temp = " Seratus" . $this->terbilang($nilai - 100);
37+
} else if ($nilai < 1000) {
38+
$temp = $this->terbilang($nilai/100) . " Ratus" . $this->terbilang($nilai % 100);
39+
} else if ($nilai < 2000) {
40+
$temp = " Seribu" . $this->terbilang($nilai - 1000);
41+
} else if ($nilai < 1000000) {
42+
$temp = $this->terbilang($nilai/1000) . " Ribu" . $this->terbilang($nilai % 1000);
43+
} else if ($nilai < 1000000000) {
44+
$temp = $this->terbilang($nilai/1000000) . " Juta" . $this->terbilang($nilai % 1000000);
45+
} else if ($nilai < 1000000000000) {
46+
$temp = $this->terbilang($nilai/1000000000) . " Milyar" . $this->terbilang(fmod($nilai,1000000000));
47+
} else if ($nilai < 1000000000000000) {
48+
$temp = $this->terbilang($nilai/1000000000000) . " Trilyun" . $this->terbilang(fmod($nilai,1000000000000));
49+
}
50+
return $temp;
51+
}
52+
}

src/HelpersServiceProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Yudhatp\Helpers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class HelpersServiceProvider extends ServiceProvider
8+
{
9+
10+
public function boot()
11+
{
12+
//
13+
}
14+
}

0 commit comments

Comments
 (0)