{"id":15972064,"url":"https://github.com/darkghosthunter/rututils","last_synced_at":"2025-03-17T15:30:47.849Z","repository":{"id":52413484,"uuid":"162664192","full_name":"DarkGhostHunter/RutUtils","owner":"DarkGhostHunter","description":"A complete library for creating, manipulating and generating chilean RUTs or RUNs.","archived":false,"fork":false,"pushed_at":"2024-10-07T09:21:24.000Z","size":99,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-08T20:41:43.037Z","etag":null,"topics":["chile","chilean","chilean-id","chilean-rut","chilean-rut-utils","composer","php","run","rut","user-id","user-identification","user-identity"],"latest_commit_sha":null,"homepage":null,"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/DarkGhostHunter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"ko_fi":"DarkGhostHunter","custom":["https://paypal.me/darkghosthunter"]}},"created_at":"2018-12-21T04:07:12.000Z","updated_at":"2021-10-20T23:07:59.000Z","dependencies_parsed_at":"2022-08-21T05:40:19.436Z","dependency_job_id":null,"html_url":"https://github.com/DarkGhostHunter/RutUtils","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkGhostHunter%2FRutUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkGhostHunter%2FRutUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkGhostHunter%2FRutUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DarkGhostHunter%2FRutUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DarkGhostHunter","download_url":"https://codeload.github.com/DarkGhostHunter/RutUtils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221695205,"owners_count":16865163,"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":["chile","chilean","chilean-id","chilean-rut","chilean-rut-utils","composer","php","run","rut","user-id","user-identification","user-identity"],"created_at":"2024-10-07T20:41:44.521Z","updated_at":"2024-10-27T15:09:26.295Z","avatar_url":"https://github.com/DarkGhostHunter.png","language":"PHP","funding_links":["https://ko-fi.com/DarkGhostHunter","https://paypal.me/darkghosthunter"],"categories":[],"sub_categories":[],"readme":"![Pablo García Saldaña - Unsplash (UL) #Y-MGVIkpyFw](https://images.unsplash.com/photo-1441484295955-db07de1fdbad?ixlib=rb-1.2.1\u0026auto=format\u0026fit=crop\u0026w=1280\u0026h=400\u0026q=80)\n\n[![Latest Stable Version](https://poser.pugx.org/darkghosthunter/rut-utils/v/stable)](https://packagist.org/packages/darkghosthunter/rut-utils) [![License](https://poser.pugx.org/darkghosthunter/rut-utils/license)](https://packagist.org/packages/darkghosthunter/rut-utils)\n![](https://img.shields.io/packagist/php-v/darkghosthunter/rut-utils.svg) [![Coverage Status](https://coveralls.io/repos/github/DarkGhostHunter/RutUtils/badge.svg?branch=master)](https://coveralls.io/github/DarkGhostHunter/RutUtils?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/7142cecb93e555cd7028/maintainability)](https://codeclimate.com/github/DarkGhostHunter/RutUtils/maintainability)\n\n# RUT Utilities\n \nA complete library for creating, manipulating and generating chilean RUTs or RUNs.\n\nThis package allows you to:\n\n- **Create** a RUT object to conveniently hold the RUT information.\n- **Validate**, clean and rectify RUTs.\n- **Generate** random RUTs in a flexible manner.\n\nWhile this package works as a fire-and-forget utility for your project, ensure you read the documentation so you don't repeat yourself.\n\n## Requirements\n\nThis package only needs PHP 7.3 and later.\n\nIt may work on older versions, but it will only support active PHP releases. \n\n\u003e Optional: Know what *el weón weón weón* means.  \n\n## Installation\n\nJust fire Composer and require it into your project:\n\n```bash\ncomposer require darkghosthunter/rut-utils\n```\n\nIf you don't have Composer in your project, ~~you should be ashamed~~ just [install it](https://getcomposer.org/download/) .\n\n## Usage\n\n* [What is a RUT or RUN?](#what-is-a-rut-or-run)\n* [Creating a RUT](#creating-a-rut)\n* [Retrieving a RUT](#retrieving-a-rut)\n* [Generating RUTs](#generating-ruts)\n* [Helpers](#helpers)\n* [Make Callbacks](#make-callbacks)\n* [Serialization](#serialization)\n* [Global helper](#global-helper)\n\n### What is a RUT or RUN?\n\nA RUT (or RUN for people) is a string of numbers which identify a person or company. They're unique for each one, and they're never re-assigned to an individual, so the registry of RUTs is always growing.\n\nThe RUT its comprised of a random Number, like `18.765.432`, and a Verification Digit, which is the result of a mathematical algorithm [(Modulo 11)](https://www.google.com/search?q=modulo+11+algorithm) over that number. This Verification Digit vary between `0` and `9`, or a `K`. In the end. you get this:\n\n```\n18.765.432-1\n```\n\nThis identification information is a safe bet for chilean companies. It allows to attach one account to one individual (person or company), and can be cross-referenced with other data the user may have available through other services.\n\n\u003e What's the difference between RUTs and RUNs? RUT are meant for identifying a person or company taxes, RUNs are to identify single persons. For both cases, **they're practically the same**.\n\n### Creating a RUT\n\nThere are two ways to create a RUT: manual instancing, which is strict, and using the `make()` static helper.\n\n#### Manual instancing\n\nUsing manual instantiation allows you to create a RUT by the given number and verification digit quickly. For example, with data coming from a Database or any other trustful source.\n\n```php\n\u003c?php \n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n// Create a RUT using its numbers and verification digit separately.\n$rutA = new Rut('14328145', 0); \n\n// ...even if the RUT is malformed \n$rutB = new Rut(10000, 'foo'); \n```\n\nWhile this is a very good way to have a rut when knowing it's valid, you may want to use the `make()` static helper to create a Rut instance.\n\n```php\n\u003c?php \n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n// Create a RUT using its numbers and verification digit separately.\n$rutA = Rut::make('14328145', 0);\n\n// You can also use a whole string.\n$rutB = Rut::make('14.328.145-0');\n\n// And even malformed ones with invalid characters\n$rutC = Rut::make('asdwdasd14.32.814.5-0');\n```\n\nThe static helper will automatically clean the string and parse the number and verification digit for you, so you don't have to.\n\nIf the resulting Rut is malformed or invalid, `null` will be returned instead of a Rut instance, which you can use to quickly set flow control in your code.\n\n```php\n\u003c?php \n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n$malformed = Rut::make('not-a-rut');\n\nif (!$malformed) {\n    echo 'This RUT is bad!';\n}\n```\n\nThe `make()` method accepts a value or callable that will be returned when the RUT is malformed or invalid.\n\n```php\n\u003c?php \n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n$validA = Rut::make('14328145', 0, 'this is valid');\necho $validA; // \"14.328.145-0\"\n\n$validB = Rut::make('14.328.145-0', function () {\n    return 'also valid'; \n});\necho $validB; // \"14.328.145-0\"\n\n$invalid = Rut::make('18.765.432-1', null, 'this is invalid');\necho $invalid; // \"this is invalid\"\n```\n\nAlternatively, you may want to use the `makeOrThrow()` to throw an exception when trying to make a malformed or invalid RUT.\n\n```php\n\u003c?php \n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n$validA = Rut::makeOrThrow('18.765.432', 1);\n\n// [!] [InvalidRutException]\n```\n\n#### Creating multiple RUTs\n\nIt can be cumbersome to do a `foreach` or `for` loop to make multiple RUTs. Instead of that, use the `many()` static method. The method will automatically filter malformed RUTs from the final array.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n// Create multiple RUTs\n$rutsA = Rut::many('14.328.145-0', '14.328.145-0');\n\n// Or issue an array of multiple RUTs\n$rutsB = Rut::many([\n    '14.328.145-0',\n    '7976228-8',\n    ['14.328.145', 0]\n]);\n```\n\nYou can use the `manyOrThrow()` to return an exception in case a malformed or invalid RUT is detected.\n\n### Retrieving a RUT\n\nSince there is no way to know how your application works with RUTs, you can treat the `Rut` object as an array, object or string for your convenience.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n// Let's create first the RUT:\n$rut = Rut::make(14328145, 0);\n\n// Return the RUT as a string\necho $rut; // 14.328.145-0\n\n// You can get number or verification digit as an array\necho $rut['num']; // 14328145\necho $rut['vd']; // 0\n\n// ...or as an object\necho $rut-\u003enum; // 14328145\necho $rut-\u003evd; // 0\n``` \n\n\u003e For safety reasons, you cannot set the `num` and `vd` in the instance. \n\n#### Lowercase or Uppercase `K`\n\nA RUT can have the `K` character as verification *digit*. The Rut object doesn't discerns between lowercase `k` or uppercase `K` when creating one, but **it always stores uppercase as default**.\n\nYou can change this behaviour for all Rut instances using the `allUppercase()` or `allLowercase()` methods:\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\nRut::allLowercase();\n\necho Rut::make('12343580', 'K')-\u003evd; // \"k\"\n\nRut::allUppercase();\n\necho Rut::make('12343580', 'K')-\u003evd; // \"K\"\n```\n\nAdditionally, you can change this configuration for a single instance by using `uppercase()` and `lowercase()`.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n$rut = Rut::make('12343580', 'K');\n\n$rut-\u003elowercase();\n\necho $rut-\u003evd; // \"K\"\n\n$rut-\u003euppercase();\n\necho $rut-\u003evd; // \"k\"\n```\n\nThis may come in handy when your source of truth manages lowercase `k` and you need strict comparison for storing, or normalize it.\n\n### Generating RUTs\n\nSometimes it's handy to create a RUT on the fly, usually for testing purposes when seeding and mocking.\n\nYou can do that using the `RutGenerator` class and use the methods to build how you want to generate your RUTs. The methods are fluent, meaning, you can chain them until you use the `generate()` method.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutGenerator;\n\n$rut = RutGenerator::make()-\u003egenerate();\n\necho $rut; // \"7.976.228-8\" \n```\n\nThe default mode makes a RUT for normal people, which are bound between 1.000.000 and 50.000.000. You can use the `forCompany()` method, which will vary the result randomly between 50.000.000 and 100.000.000.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutGenerator;\n\necho $rut = RutGenerator::make()-\u003easPerson()-\u003egenerate();\n// \"15.846.327-K\"\n\necho $company = RutGenerator::make()-\u003easCompany()-\u003egenerate();\n// \"54.029.467-4\"\n```\n\nOf course one may be not enough. You can add a parameter to these methods with the number of RUTs you want to make. The result will be returned as an `array`.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutGenerator;\n\n$peopleRuts = RutGenerator::make()-\u003easPerson()-\u003egenerate(10);\n$companyRuts = RutGenerator::make()-\u003easCompany()-\u003egenerate(35);\n```\n\nIf for some reason you need them as raw strings instead of Rut instances, which is very good when generating thousands of them on strict memory usage, use the `asBasic()` and `asRaw()` method.\n\nThis will output the random strings like `22605071K`.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutGenerator;\n\n$raw = RutGenerator::make()-\u003easRaw()-\u003egenerate(10);\n$basic = RutGenerator::make()-\u003easBasic()-\u003egenerate(20);\n$strict = RutGenerator::make()-\u003easStrict()-\u003egenerate(30);\n```\n\n#### Generating random unique RUTs\n\nIf you need to create more than thousands of RUTs without the risk of having them duplicated, use the `withoutDuplicates()` method.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutGenerator;\n\n$ruts = RutGenerator::make()-\u003ewithoutDuplicates()-\u003egenerate(100000);\n```\n\n##### Unique results between calls\n\nYou may have a custom seeder in your application that may call `generate()` every single time, increasing risk of collisions with each generation. Fear not! Using the `generateStatic()` you are guaranteed to get unique results during a single application lifecycle.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutGenerator;\n\n$users = [\n    ['name' =\u003e 'John'],\n    ['name' =\u003e 'Clara'],\n    ['name' =\u003e 'Mark'],\n    // ... and other 99.997 records\n];\n\n$seeder = function ($user) {\n    return array_merge($user, [\n        'rut' =\u003e RutGenerator::make()-\u003egenerateStatic()\n    ]);\n};\n\n// Call the seeder\nforeach ($users as $key =\u003e $user) {\n    $users[$key] = $seeder($user);\n}\n\n// Flush the static array for the next seeder call\nRutGenerator::make()-\u003eflushStatic();\n```\n\n### Helpers\n\nYou can manipulate and check strings quickly using the `RutHelper` class, which contains a wide variety of handy static methods you can use.\n\n* [`cleanRut`](#cleanrut)\n* [`separateRut`](#separaterut)\n* [`validate`](#validate)\n* [`validateStrict`](#validatestrict)\n* [`filter`](#filter)\n* [`rectify`](#rectify)\n* [`isPerson`](#isperson)\n* [`isCompany`](#iscompany)\n* [`isEqual`](#isequal)\n* [`getVd`](#getvd)\n\n#### `cleanRut`\n\nClears a RUT string from invalid characters. Additionally, you can set if you want the `K` verification character as uppercase or lowercase.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\necho RutHelper::cleanRut('f@a18765432@@7'); // \"187654327\"\necho RutHelper::cleanRut('18.290.743-K', false); // \"18290743k\"\n```\n\n#### `separateRut`\n\nCleans and separates a string into a number and verification digit array.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\nRutHelper::separateRut('18.290.743-K', false);\n\n// array(2) [\n//    0 =\u003e 18290743,\n//    1 =\u003e 'k',\n// ]\n```\n\n#### `validate`\n\nChecks if the RUTs issued are valid. \n\nIf there are more than one RUT, it will return `true` if all the RUTs are valid, and `false` if at least one is invalid.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\necho RutHelper::validate('14328145-0'); // true\necho RutHelper::validate('14.328.145-0', '12343580-K'); // true\necho RutHelper::validate(143281450); // true\necho RutHelper::validate('not-a-rut'); // false\necho RutHelper::validate(['14.328.145-0', '12343580-K', 'foo']); // false\n```\n\nAlternatively, you can use the `Rut` object itself.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n// Cleans the rut, and validate it \necho Rut::make('14328145-0')-\u003eisValid(); // true\necho Rut::make('94.328.145-0')-\u003eisValid(); // false\necho Rut::make('cleanthis14328145-0-andthistoo')-\u003eisValid(); // true\n```\n\n#### `validateStrict`\n\nYou can strictly validate a RUT. The RUT value being passed must be a string with thousand separator and hyphen preceding the RUT verification digit.\n\nIf there are more than one RUT, it will return `true` if all the RUTs are valid, and `false` if at least one is invalid.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\n// Receive the raw string, and strictly validate it\necho RutHelper::validateStrict('14328145-0'); // false\necho RutHelper::validateStrict('14.328.145-0', '12343580-K'); // false\necho RutHelper::validateStrict(143281450); // false\necho RutHelper::validateStrict('not-a-rut'); // false\necho RutHelper::validateStrict(143281450, 'not-a-rut'); // false\necho RutHelper::validateStrict('14.328.1!45-0'); // false\n```\n\n#### `filter`\n\nFilter an array of RUTs, returning an array of only the valid RUTs.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\n// Filter only the valid ruts, and leave the invalid out of the result.\n$rutsA = RutHelper::filter(\n    '14328145-0', \n    '12343580-K', \n    '94.328.145-0', \n    'not-a-rut'\n);\n\nvar_dump($rutsA);\n\n// array(1) {\n//     [0] =\u003e 14328145-0\n//     [1] =\u003e 12343580-K\n// } \n\n$rutsB = RutHelper::filter([\n    '14328145-0',\n    '12343580-K',\n    '94.328.145-0',\n    'not-a-rut'\n]);\n\nvar_dump($rutsB);\n\n// array(1) {\n//     [0] =\u003e 14328145-0\n//     [1] =\u003e 12343580-K\n// } \n```\n#### `rectify`\n\nReceives only the RUT number and returns a valid `Rut` instance with the corresponding verification digit. \n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\n$rut = RutHelper::rectify('18765432');\n\necho $rut-\u003enum; // \"18765432\"\necho $rut-\u003evd; // \"7\"\n```\n\n\u003e If you pass down a whole RUT, you may get a new RUT with an appended Verification Digit. Ensure you pass down only the RUT number.\n\n#### `isPerson`\n\nChecks if the RUT below 50.000.000, which are usually used for normal people.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\necho RutHelper::isPerson('22605071-k'); // true\n```\n\nYou can also use the `isPerson()` helper inside a Rut instance.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\necho RutHelper::make('22605071-k')-\u003eisPerson(); // true\n```\n\n#### `isCompany`\n\nChecks if the RUT is over or equal 50.000.000, which are usually used for companies.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\necho RutHelper::isCompany('50000000-7'); // true\n```\n\nYou can also use the `isCompany()` helper inside a Rut instance.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\necho RutHelper::make('50000000-7')-\u003eisCompany(); // true\n```\n\n#### `isEqual`\n\nReturns if two or more RUTs are equal, independently of how these are formatted, **even if these are invalid**.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\nuse Application\\Models\\User;\n\n$ruts = RutHelper::isEqual(\n    'thisisARut12343580-K',\n    '12343580-K',\n    User::getRutFromDatabase()\n);\n\necho $ruts; // true\n```\n\nYou can also use the `isEqual()` helper inside a Rut instance.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\nuse Application\\Models\\User;\n\n$rut = Rut::make(User::getRutFromDatabase());\n\necho $rut-\u003eisEqual('thisisARut12343580-K', '12343580-k'); // true\n```\n\n#### `getVd`\n\nReturns the verification digit for a given number.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\n$vd = RutHelper::getVd(12343580);\n\necho $vd; // 'K'\n```\n\n#### `unpack`\n\nTakes an array and, if only one item was issued containing an array, this item contents will be returned to the application.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\n$unpacked = RutHelper::unpack([\n    ['12343580K', '22605071-k', 500000007],\n]);\n\necho count($unpacked); // 3\n```\n\n### Callbacks\n\nFor convenience, you can register callbacks to be executed after you use `many()` and `manyOrThrow()`. For example, you may want to use this to manipulate how the Ruts are handled before these are returned.\n\nYou can register a callback using the `after()` static method. The callable receives the array of RUTs as the come, and **must return** the result.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\nuse DarkGhostHunter\\RutUtils\\RutHelper;\n\nRut::after(function ($ruts) {\n    \n    return array_merge($ruts, [\n        'count' =\u003e count($ruts),\n    ]);\n});\n\n$ruts = Rut::many([\n    // ...\n]);\n\nvar_dump($ruts);\n// array(100) [\n//    // ...\n//    'count' =\u003e 100,\n// ]\n```\n\n\u003e If you register multiple callbacks, these will be executed in the order they were registered.\n\n### Serialization\n\nSometimes you may want to store your Rut instance somewhere, or serialize it to JSON, or a string. With this package you're covered from all angles.\n\n#### Serialize / Unserialize\n\nBy default, a Rut instance is serialized as a raw string, which is latter reconstructed quickly by just dividing the string into the number and verification digit:\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n$rut = Rut::make('22605071-k');\n\necho serialize($rut); // C:28:\"DarkGhostHunter\\RutUtils\\Rut\":9:{106663092}\n``` \n\nThis is pretty much optimized for low storage and quick instancing. The rest will depend on your serialization engine.\n\n#### String  \n\nThere are multiple ways to set the format to use with a Rut instance when is serialized as a string:\n\n* Strict: Default option. Serializes with a thousand separator and hyphen.\n* Basic: No thousand separator, only the hyphen.\n* Raw: No thousand separator nor hyphen.\n\nThese can be set globally using the static methods, and as a per-instance basis using the dynamic calls available in the instance itself.\n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\n$rut = Rut::make('22605071-k');\n\nRut::allFormatStrict(); \n\necho (string)$rut; // \"22.605.071-K\"\n\nRut::allFormatBasic(); \n\necho (string)$rut; // \"22605071-K\"\n\nRut::allFormatRaw(); \n\necho (string)$rut; // \"22605071K\"\n\n// Per instance\necho $rut-\u003etoStrictString(); // \"22.605.071-K\"\necho $rut-\u003etoBasicString(); // \"22605071-K\"\necho $rut-\u003etoRawString(); // \"22605071K\"\n```\n\n#### JSON\n\nBy default, when casting to JSON, the result is a string. You can change this to be an array of the number and verification digit using static methods for all instances, or a per-instance case: \n\n```php\n\u003c?php\n\nuse DarkGhostHunter\\RutUtils\\Rut;\n\nRut::allJsonAsArray();\n\n$rut = Rut::make('22605071-k');\n\necho json_encode($rut); // {\"num\":\"22605071\",\"vd\":\"K\"}\n\nRut::allJsonAsString();\n\necho json_encode($rut); // \"22.605.071-K\"\n\n$rut-\u003ejsonAsArray();\n\necho json_encode($rut); // {\"num\":\"22605071\",\"vd\":\"K\"}\n\n$rut-\u003ejsonAsString();\n\necho json_encode($rut); // \"22.605.071-K\"\n```\n\n## Global helper\n\nIn version 2.0, all helpers have been killed and now you have only one called `rut()`. It works as a proxy for `Rut::make`, but accepts a default in case of invalid ruts. If no parameter is issued, an instance of the Rut Generator is returned.\n\n```php\n\u003c?php\n\n$rut = rut('10.666.309-2');\n\necho $rut; // '10.666.309-2';\n\n$rut = rut('an invalid rut', 'use this!');\n\necho $rut; // 'use this!'\n\n$rut = rut()-\u003egenerate();\n\necho $rut; // '20.750.456-4'\n```\n\n## License\n\nThis package is licenced by the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkghosthunter%2Frututils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkghosthunter%2Frututils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkghosthunter%2Frututils/lists"}