Coder Social home page Coder Social logo

laravel-num's Introduction

Laravel Num

Latest Version on Packagist Laravel 8.x Laravel 9.x Laravel 10.x GitHub Tests Action Status Total Downloads

To convert the unicode digit to another unicode digit.

Supported languages

By default, You can convert english, myanmar and thai numbers. If you would like to add more, you can add zero unicode characters at config/num.php. You can see more zero unicode character at zero-unicode.md.

Installation

You can install this package via composer using this command:

composer require ageekdev/laravel-num

The package will automatically register itself.

Publish configuration and asset files

php artisan vendor:publish --provider="AgeekDev\Num\NumServiceProvider"

Usage

Using the facade

Direct convert from the english number to the myanmar number

Num::convert('1234๑๒๓๔','mm','en'); 
// ၁၂၃၄๑๒๓๔

Convert to the myanmar number

Num::toMyanmar('1234๑๒๓๔'); 
// ၁၂၃၄၁၂၃၄

Convert to the thai number

Num::toThai('1234'); 
// ๑๒๓๔

Convert to the english number

Num::toEnglish('၁၂၃၄'); 
// 1234

Using with Helpers

Convert to the myanmar number

num_to_mm('1234'); 
// ၁၂၃၄

Convert to the thai number

num_to_th('1234');
// ๑๒๓๔

Convert to the english number

num_to_eng('၁၂၃၄');
// 1234

Macro

The Laravel Num allows you to define "macros", which can serve as a fluent, expressive mechanism to configure string, to language and from language when interacting with services throughout your application. To get started, you may define the macro within the boot method of your application's App\Providers\AppServiceProvider class:

use AgeekDev\Num\Facades\Num;
 
/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Num::macro('toMyanmarShan', function (int|string $string, string $from = null) {
        return Num::convert($string, 'shan', $from);
    });
}

Once your macro has been configured, you may invoke it from anywhere in your application to convert numbers with the specified configuration:

$numbers = Num::toMyanmarShan('1234567890');

// ႑႒႓႔႕႖႗႘႙႐

Note If convert language don't have in num.php, you may configure this language in your num configuration file.

'zeros' => [
    'en' => 0,
    'mm' => '',
    'th' => '',
    'shan' => ''
],

Testing

You can run the tests with:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

laravel-num's People

Contributors

tintnaingwinn avatar dependabot[bot] avatar tintnaingwin-genie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.