├── LICENSE.md ├── composer.json ├── config └── num.php └── src ├── Facades └── Num.php ├── Num.php ├── NumServiceProvider.php └── helpers.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) AgeekDev 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 NON-INFRINGEMENT. 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. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ageekdev/laravel-num", 3 | "description": "To convert the unicode digit to another unicode digit.", 4 | "keywords": [ 5 | "laravel", 6 | "number", 7 | "unicode", 8 | "english", 9 | "myanmar", 10 | "thai" 11 | ], 12 | "type": "library", 13 | "license": "MIT", 14 | "authors": [ 15 | { 16 | "name": "Tint Naing Win", 17 | "email": "amigo.k8@gmail.com" 18 | } 19 | ], 20 | "require": { 21 | "php": "^8.1", 22 | "illuminate/support": "^9.0|^10.0|^11.0|^12.0" 23 | }, 24 | "require-dev": { 25 | "laravel/pint": "^1.5", 26 | "phpstan/extension-installer": "^1.1|^2.0", 27 | "phpstan/phpstan-deprecation-rules": "^1.0|^2.0", 28 | "phpstan/phpstan-phpunit": "^1.0|^2.0", 29 | "larastan/larastan": "^2.0|^3.0", 30 | "orchestra/testbench": "^7.31|^8.11|^9.0|^10.0", 31 | "pestphp/pest": "^1.21|^2.0|^3.0", 32 | "pestphp/pest-plugin-laravel": "^1.4|^2.0|^3.0", 33 | "roave/security-advisories": "dev-latest" 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "AgeekDev\\Num\\": "src/" 38 | }, 39 | "files": [ 40 | "src/helpers.php" 41 | ] 42 | }, 43 | "autoload-dev": { 44 | "psr-4": { 45 | "AgeekDev\\Num\\Tests\\": "tests" 46 | } 47 | }, 48 | "scripts": { 49 | "analyse": "vendor/bin/phpstan analyse", 50 | "analyse-clear": "vendor/bin/phpstan clear-result-cache", 51 | "test": "vendor/bin/pest", 52 | "test-coverage": "vendor/bin/pest --coverage", 53 | "format": "vendor/bin/pint" 54 | }, 55 | "config": { 56 | "sort-packages": true, 57 | "allow-plugins": { 58 | "pestphp/pest-plugin": false, 59 | "phpstan/extension-installer": false 60 | } 61 | }, 62 | "extra": { 63 | "laravel": { 64 | "providers": [ 65 | "AgeekDev\\Num\\NumServiceProvider" 66 | ], 67 | "aliases": { 68 | "Num": "AgeekDev\\Num\\Facades\\Num" 69 | } 70 | } 71 | }, 72 | "minimum-stability": "dev", 73 | "prefer-stable": true 74 | } 75 | -------------------------------------------------------------------------------- /config/num.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'en' => 0, 6 | 'mm' => '၀', 7 | 'th' => '๐', 8 | ], 9 | ]; 10 | -------------------------------------------------------------------------------- /src/Facades/Num.php: -------------------------------------------------------------------------------- 1 | replaceNumber((string) $string, $zeros[$from], $toNumber); 49 | } 50 | 51 | $result = (string) $string; 52 | foreach (Arr::except($zeros, $to) as $zero) { 53 | $result = $this->replaceNumber($result, $zero, $toNumber); 54 | } 55 | 56 | return $result; 57 | } 58 | 59 | /** 60 | * Replace numbers between number systems. 61 | * 62 | * @param string $string Input string or number 63 | * @param string $fromZero Source zero character 64 | * @param array $toNumber Target number array 65 | */ 66 | private function replaceNumber(string $string, string $fromZero, array $toNumber): string 67 | { 68 | return str_replace(num_range($fromZero), $toNumber, $string); 69 | } 70 | 71 | /** 72 | * Convert to Myanmar number. 73 | */ 74 | public function toMyanmar(int|string|null $string): ?string 75 | { 76 | return $this->convert($string, self::LANG_MM); 77 | } 78 | 79 | /** 80 | * Convert to Thai number. 81 | */ 82 | public function toThai(int|string|null $string): ?string 83 | { 84 | return $this->convert($string, self::LANG_TH); 85 | } 86 | 87 | /** 88 | * Convert to English number. 89 | */ 90 | public function toEnglish(int|string|null $string): ?string 91 | { 92 | return $this->convert($string, self::LANG_EN); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/NumServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 12 | __DIR__.'/../config/num.php' => config_path('num.php'), 13 | ], 'config'); 14 | } 15 | 16 | public function register(): void 17 | { 18 | $this->mergeConfigFrom(__DIR__.'/../config/num.php', 'num'); 19 | 20 | $this->app->singleton('num', function ($app) { 21 | return new Num; 22 | }); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 |