{"id":26292393,"url":"https://github.com/cuongdinhngo/jutility","last_synced_at":"2025-10-26T12:12:10.983Z","repository":{"id":56960261,"uuid":"379805853","full_name":"cuongdinhngo/jutility","owner":"cuongdinhngo","description":"Laravel Japanese Utility: CSV, Japanese Localization, Japan Post Code","archived":false,"fork":false,"pushed_at":"2021-07-05T08:02:57.000Z","size":3234,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-08T05:44:50.479Z","etag":null,"topics":["japan-post","japan-post-code","japan-zip-code","japanese-localization","laravel","module-pattern","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cuongdinhngo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-24T04:45:46.000Z","updated_at":"2023-04-18T03:32:25.000Z","dependencies_parsed_at":"2022-08-21T09:50:57.801Z","dependency_job_id":null,"html_url":"https://github.com/cuongdinhngo/jutility","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuongdinhngo%2Fjutility","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuongdinhngo%2Fjutility/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuongdinhngo%2Fjutility/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cuongdinhngo%2Fjutility/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cuongdinhngo","download_url":"https://codeload.github.com/cuongdinhngo/jutility/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253009843,"owners_count":21839713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["japan-post","japan-post-code","japan-zip-code","japanese-localization","laravel","module-pattern","php"],"created_at":"2025-03-15T01:35:38.278Z","updated_at":"2025-10-26T12:12:10.897Z","avatar_url":"https://github.com/cuongdinhngo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Japanese Utility\n\nThis package provides a convenient way to retrieve Japanese Utility such as Japanese Postal Code, Japanese Localization, CSV\n\n## Installation\n\n1-Install `cuongnd88/jutility` using Composer.\n\n```php\n$ composer require cuongnd88/jutility\n```\n\n2-You can modify the configuration by copying it to your local config directory:\n\n```php\nphp artisan vendor:publish --provider=\"Cuongnd88\\Jutility\\JutilityServiceProvider\"\n```\n\nYou select the utility by adding `--tag` option:\n\n```php\nphp artisan vendor:publish --provider=\"Cuongnd88\\Jutility\\JutilityServiceProvider\" --tag=public\n```\n\nThere are 3 options:\n\n_`--tag=public` is to publish the JPostal Utility via javascript._\n\n_`--tag=config` is to publish the JPostal Utility via php/laravel._\n\n_`--tag=lang` is to publish the Japanese Localization Utility._\n\n\n## Sample Usage\n\n### JPostal Utility via Javascript\n\nWith the JPostal utility, you can achieve Japanese postal data by postal code. You just need implementing like below \n\n`resources/views/user/jpostal.blade.php`\n\n```php\n. . . .\n\n    \u003cdiv class=\"form-group row\"\u003e\n        \u003clabel for=\"email\" class=\"col-md-4 col-form-label text-md-right\"\u003e{{ __('Post code') }}\u003c/label\u003e\n\n        \u003cdiv class=\"col-md-6\"\u003e\n            \u003cinput id=\"zip\" type=\"text\" class=\"form-control\" name=\"email\" value=\"\" onkeyup=\"JPostal.capture('#zip', ['#info'])\"\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\n    \u003cdiv class=\"form-group row\"\u003e\n        \u003clabel for=\"password\" class=\"col-md-4 col-form-label text-md-right\"\u003e{{ __('Info') }}\u003c/label\u003e\n\n        \u003cdiv class=\"col-md-6\"\u003e\n            \u003cinput id=\"info\" type=\"text\" class=\"form-control\" name=\"info\"\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\n. . . .\n\u003cscript type=\"text/javascript\" src=\"{{ asset('js/jpostal/jpostal.js') }}\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n    JPostal.init();\n\u003c/script\u003e\n```\n\n`JPostal.capture(zip, response)`:\n\n_`zip` : is a string value that you can assign a value contains id or class sign in identifing zip code. For example: `.zip` or `#zip`._\n\n_`response` is a array or function that you get the data (prefecture, city, area and street). If the array only has one item, it resturns data with comma sign. The array has 4 elements, so it returns seperated data corresponding to prefecture, city, area and street. If the resposne is a function, it will callback ._\n\n_`MEMO` you can use id and class signs for zip and response parameters. You can enter both postal code formats (NNN-NNNN or NNNNNNN)._\n\n```php\n\t\u003cdiv class=\"col-md-6\"\u003e\n\t    \u003cinput id=\"zip\" type=\"text\" class=\"form-control\" name=\"email\" value=\"\" onkeyup=\"JPostal.capture('#zip', ['.prefecture', '.city', '.area', '.street'])\"\u003e\n\t\u003c/div\u003e\n```\n\n```php\n\u003cscript type=\"text/javascript\"\u003e\n    JPostal.init();\n\n    $( \"#zip\" ).keyup(function() {\n        JPostal.capture('#zip', function(data){\n            console.log(data);\n        });\n    });\n\u003c/script\u003e\n```\n\nThe JPostal provides functions to select a city correspond to a prefecture\n\n_`JPostal.innerPrefecturesHtml(callback)` ._\n\n_`JPostal.nnerCityHtmlByPref(prefTag, callback)` ._\n\n\n```php\n. . . .\n    \u003cdiv class=\"form-group row\"\u003e\n        \u003clabel class=\"col-md-4 col-form-label text-md-right\"\u003e{{ __('Prefecture') }}\u003c/label\u003e\n\n        \u003cdiv class=\"col-md-6\"\u003e\n            \u003cselect class=\"form-control selectPrefecture\" id=\"selectPrefecture\"\u003e\n            \u003c/select\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n\n    \u003cdiv class=\"form-group row\"\u003e\n        \u003clabel class=\"col-md-4 col-form-label text-md-right\"\u003e{{ __('City') }}\u003c/label\u003e\n\n        \u003cdiv class=\"col-md-6\"\u003e\n            \u003cselect class=\"form-control selectCity\" id=\"selectCity\"\u003e\n            \u003c/select\u003e\n        \u003c/div\u003e\n    \u003c/div\u003e\n. . . .\n\n\u003cscript type=\"text/javascript\" src=\"{{ asset('js/jpostal/jpostal.js') }}\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\"\u003e\n    JPostal.init();\n\n    JPostal.innerPrefecturesHtml(function(prefectures){\n        let selectTag = '\u003coption value=\"\"\u003ePrefecture\u003c/option\u003e';\n        for (const [key, value] of Object.entries(prefectures)) {\n            selectTag += `\u003coption value=\"${key}\"\u003e${value}\u003c/option\u003e`;\n        }\n        $('#selectPrefecture').append(selectTag);\n    });\n\n    $(\"#selectPrefecture\").change(function(){\n        JPostal.innerCityHtmlByPref('#selectPrefecture', function(cities){\n            let selectTag = '\u003coption value=\"\"\u003eCity\u003c/option\u003e';\n            for (const item in cities) {\n                const {id, name} = cities[item];\n                selectTag += `\u003coption value=\"${id}\"\u003e${name}\u003c/option\u003e`;\n            }\n            $('#selectCity').append(selectTag);\n        });\n    });\n\u003c/script\u003e\n```\n\n### JPostal Utility via PHP/Laravel\n\nThere are several functions to assist you get Japanese postal code:\n\n_`jpostal_pref($code = null)`: Get Japanese prefectures by code ._\n\n```php\ndump(jpostal_pref(47));\n```\n\n_`jpostal_pref_city($prefCode, $city = null)`: Get Japanese city by prefecture code ._\n\n```php\ndump(jpostal_pref_city(47));\ndump(jpostal_pref_city(1, '01101));\n```\n\n_`jpostal_code($code)`: Get Japanese postal data by code ._\n\n```php\n    dump(jpostal_code('1200000'));\n    dump(jpostal_code('120-0000'));\n```\n\n_`jlang($key)`: Use translation strings as keys are stored as JSON files in the resources/lang/{$currentLocale}/ directory ._\n\n```php\n    dump(jlang('Add Team Member'));\n```\n\n### Japanese Localization Utility\n\nThe `cuongnd88/jutility` package provides a convenient way to retrieve strings in Japanese languages. The default language for your application is stored in the `config/app.php` configuration file. You may modify this value to suit the needs of your application.\n\n```php\n. . . .\n    'locale' =\u003e 'ja',\n. . . .\n```\n\nLanguage strings are stored in files within the resources/lang directory.\n\n```php\n/resources\n    /lang\n        /en\n            messages.php\n        /ja\n            messages.php\n```\n\n### CSV\n\nThe CSV utility support to read, validate and get the CSV file. You have to set the valitor in `config/csv.php`. Please refer to the defaut:\n\n```php\nreturn [\n    /*\n    |--------------------------------------------------------------------------\n    | UTF-8 Bom\n    |--------------------------------------------------------------------------\n    |\n    | The UTF-8 BOM is a sequence of bytes at the start of a text stream (0xEF, 0xBB, 0xBF)\n    | that allows the reader to more reliably guess a file as being encoded in UTF-8.\n    | Suitable for exporting Japanese data\n    |\n    */\n    'utf-8-bom' =\u003e false,\n\n    /*\n    |--------------------------------------------------------------------------\n    | Validator Support\n    |--------------------------------------------------------------------------\n    |\n    | This is a sample defines how to validate CSV data:\n    | - `user.header` is to identify the format of CSV file, that compare the standard header to the CSV header.\n    | The \"Invalid Header\" message of Exception is threw if there is an error\n    |\n    | - `user.validator` is based on Laravel Validator. If you have multiple user tables or models you may configure multiple\n    |       + `user.validator.rules`: set the Laravel validation rules\n    |       + `user.validator.messages`: customize the Laravel default error messages\n    |       + `user.validator.attributes`: customize the validation attributes\n    */\n    'user' =\u003e [\n        'header' =\u003e [\n            'fname' =\u003e 'First Name',\n            'lname' =\u003e 'Last Name',\n            'email' =\u003e 'Email',\n        ],\n        'validator' =\u003e [\n            'rules' =\u003e [\n                'fname' =\u003e 'required',\n                'lname' =\u003e 'required',\n                'email' =\u003e 'required|email',\n            ],\n            'messages' =\u003e [],\n            'attributes' =\u003e [],\n        ],\n    ],\n];\n```\n\nThe `CSV` is a facade that provides access to an object from the container. You just need to import the `CSV` facade near the top of the file.\n\n```php\n. . . .\nuse Cuongnd88\\Jutility\\Facades\\CSV;\n\nclass UserController extends Controller\n{\n    . . . .\n    public function postCSV(Request $request)\n    {\n        $csv = CSV::read(\n                    $request-\u003ecsv,\n                    config('csv.user.header'),\n                    config('csv.user.validator')\n                )-\u003efilter();\n        dump($csv);\n    }\n}\n. . . .\n```\n\n_`read($file, array $standardHeader = [], $validatorConfig = null)`: read CSV file, return CSV object ._\n\n_`filter()`: filter CSV data, return an array `['validated' =\u003e [...], 'error' =\u003e [...]]`._\n\n\n_`get()`: get CSV data (including validated and error data) except CSV header line, return an array._\n\n_`validatorErrors()`: get validated errors, return an array ._\n\n\n```php\n    public function postCSV(Request $request)\n    {\n        $csv = CSV::read(\n                    $request-\u003ecsv,\n                    config('csv.user.header'),\n                    config('csv.user.validator')\n                );\n        $data = $csv-\u003eget();\n        dump($data);\n        $errorList = $csv-\u003evalidatorErrors();\n        dump($errorList);\n    }\n```\n\n_`MEMO`: the CSV returns an array data (or error list), the index array is line number of CSV file._\n\n\n_`save(string $fileName, array $data, $header = null)`: export data to CSV file ._\n\n\n```php\n    public function downloadCSV()\n    {\n        $data = User::all()-\u003etoArray();\n        $header = ['ID','Fullname','Email','Mobile number', 'Email verified data time', 'Created date time', 'Updated date time'];\n        CSV::save('user-data', $data, $header);\n    }\n```\n\n## Demo\n\nThis is demo soure code.\n\n[JPostal Utility](https://github.com/cuongnd88/lara-colab/blob/master/alpha/resources/views/user/jpostal.blade.php)\n\n[CSV Utility](https://github.com/cuongnd88/lara-colab/blob/master/alpha/app/Http/Controllers/User/UserController.php)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuongdinhngo%2Fjutility","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuongdinhngo%2Fjutility","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuongdinhngo%2Fjutility/lists"}