{"id":24016363,"url":"https://github.com/decodelabs/dictum","last_synced_at":"2025-04-15T14:07:31.084Z","repository":{"id":56964549,"uuid":"357624547","full_name":"decodelabs/dictum","owner":"decodelabs","description":"Text formatting tools for PHP","archived":false,"fork":false,"pushed_at":"2025-04-14T08:44:42.000Z","size":158,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-14T09:45:02.339Z","etag":null,"topics":["date","formatting","number","php","text-formatting"],"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/decodelabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-04-13T16:45:14.000Z","updated_at":"2025-04-14T08:44:46.000Z","dependencies_parsed_at":"2024-04-24T15:00:28.481Z","dependency_job_id":null,"html_url":"https://github.com/decodelabs/dictum","commit_stats":{"total_commits":90,"total_committers":1,"mean_commits":90.0,"dds":0.0,"last_synced_commit":"18c4c6d1a1bfe897d315b4a670f1e9ea5a5bd98a"},"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fdictum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fdictum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fdictum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decodelabs%2Fdictum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decodelabs","download_url":"https://codeload.github.com/decodelabs/dictum/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248859918,"owners_count":21173339,"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":["date","formatting","number","php","text-formatting"],"created_at":"2025-01-08T08:49:05.530Z","updated_at":"2025-04-15T14:07:31.074Z","avatar_url":"https://github.com/decodelabs.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dictum\n\n[![PHP from Packagist](https://img.shields.io/packagist/php-v/decodelabs/dictum?style=flat)](https://packagist.org/packages/decodelabs/dictum)\n[![Latest Version](https://img.shields.io/packagist/v/decodelabs/dictum.svg?style=flat)](https://packagist.org/packages/decodelabs/dictum)\n[![Total Downloads](https://img.shields.io/packagist/dt/decodelabs/dictum.svg?style=flat)](https://packagist.org/packages/decodelabs/dictum)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/decodelabs/dictum/integrate.yml?branch=develop)](https://github.com/decodelabs/dictum/actions/workflows/integrate.yml)\n[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true\u0026style=flat)](https://github.com/phpstan/phpstan)\n[![License](https://img.shields.io/packagist/l/decodelabs/dictum?style=flat)](https://packagist.org/packages/decodelabs/dictum)\n\n### Text formatting tools for PHP\n\nDictum provides a collection of commonly required text parsing and processing features.\n\n---\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require decodelabs/dictum\n```\n\n## Usage\n\n### Importing\n\nDictum uses [Veneer](https://github.com/decodelabs/veneer) to provide a unified frontage under \u003ccode\u003eDecodeLabs\\Dictum\u003c/code\u003e.\nYou can access all the primary functionality via this static frontage without compromising testing and dependency injection.\n\n### Formatters\n\nThe main Veneer frontage of Dictum exposes a set of predictable text / key formatters which can be used to quickly prepare strings for specific actions.\n\n```php\nuse DecodeLabs\\Dictum;\n\necho Dictum::name('geoff-randomName');\n// Geoff Random Name\n\necho Dictum::firstName('geoff-randomName');\n// Geoff\n\necho Dictum::initials('geoff-randomName');\n// GRN\n\necho Dictum::initialsAndSurname('geoff-randomName');\n// GR Name\n\necho Dictum::initialMiddleNames('geoff-randomName');\n// Geoff R Name\n\n\necho Dictum::consonants('here\\'s a Random-string of text');\n// hr's  Rndm-strng f txt\n\necho Dictum::label('here\\'s a Random-string of text');\n// Here's a random string of text\n\necho Dictum::id('here\\'s a Random-string of text');\n// HeresARandomStringOfText\n\necho Dictum::camel('here\\'s a Random-string of text');\n// heresARandomStringOfText\n\necho Dictum::constant('here\\'s a Random-string of text');\n// HERE_S_A_RANDOM_STRING_OF_TEXT\n\n\necho Dictum::slug('here\\'s a Random-string of text / other stuff');\n// heres-a-random-string-of-text-other-stuff\n\necho Dictum::pathSlug('here\\'s a Random-string of text / other stuff');\n// heres-a-random-string-of-text/other-stuff\n\necho Dictum::actionSlug('here\\'s a Random-string of text / other stuff');\n// here's-a-random-string-of-text-/-other-stuff\n\necho Dictum::fileName('here\\'s a Random-string of text / other stuff');\n// here's-a-Random-string-of-text-_-other-stuff\n\necho Dictum::shorten('here\\'s a Random-string of text / other stuff', 10);\n// here's a…\n\n\necho Dictum::numericToAlpha(23345452);\n// aybfra\n\necho Dictum::alphaToNumeric('aybfra')\n// 23345452\n\necho Dictum::toBoolean('yes') ? 'true' : 'false';\n// true\n```\n\n\n### Text\n\nThe formatters above predominantly use the \u003ccode\u003eText\u003c/code\u003e class to process the strings provided. This class exposes a full suite of multibyte aware string manipulation functionality in an immutable collection format.\n\nFor example, the above \u003ccode\u003eid()\u003c/code\u003e method is defined as:\n\n```php\necho (new Text($id))\n    -\u003etoUtf8()\n    -\u003etoAscii()\n    -\u003eregexReplace('([^ ])([A-Z])', '\\\\1 \\\\2')\n    -\u003ereplace(['-', '.', '+'], ' ')\n    -\u003eregexReplace('[^a-zA-Z0-9_ ]', '')\n    -\u003etoTitleCase()\n    -\u003ereplace(' ', '')\n    -\u003e__toString();\n```\n\nNote, regexes are based off the mb_ereg functions and as such do not use delimiters in their patterns.\n\n\n## Plugins\n\nDictum provides generic interfaces for defining locale-aware formatter plugins that can be implemented by different output generators.\n\nCurrently, Time and Number are available, defining predictable methods for formatting dates and various forms of number.\n\nDictum offers a plain text version of these interfaces:\n\n```php\nuse DecodeLabs\\Dictum;\n\n// Custom format\nDictum::$time-\u003eformat('now', 'd/m/Y', 'Europe/London');\n\n// Locale format\n// When timezone is true it is fetched from Cosmos::$timezone\nDictum::$time-\u003elocale('now', 'long', 'long', true);\n\n// Locale shortcuts\nDictum::$time-\u003edateTime('tomorrow'); // medium\nDictum::$time-\u003elongTime('yesterday');\nDictum::$time-\u003eshortDate('yesterday');\n// ...etc\n\n\n// Intervals\nDictum::$time-\u003esince('yesterday'); // 1 day ago\nDictum::$time-\u003euntil('tomorrow'); // 1 day from now\nDictum::$time-\u003esinceAbs('yesterday'); // 1 day\nDictum::$time-\u003euntilAbs('yesterday'); // -1 day\nDictum::$time-\u003ebetween('yesterday', 'tomorrow'); // 1 day\n\n\n\n// Numbers\nDictum::$number-\u003eformat(16.5, 'px'); // 16.5 px\nDictum::$number-\u003eformat(16.5, 'px', 'de'); // 16,5 px\nDictum::$number-\u003edecimal(16.534643, 2); // 16.53\nDictum::$number-\u003ecurrency(16.534643, 'GBP'); // £16.53\nDictum::$number-\u003epercent(16.534643, 50, 2); // 33.07%\nDictum::$number-\u003escientific(16.534643); // 1.6534643E1\nDictum::$number-\u003espellout(16.534643); // sixteen point five three four six four three\nDictum::$number-\u003eordinal(16.534643); // 17th\nDictum::$number-\u003ediff(16.534643); // ⬆ 16.535\nDictum::$number-\u003efileSize(16534643); // 15.77 MiB\nDictum::$number-\u003efileSizeDec(16534643); // 16.53 MB\n```\n\nSee [Tagged](https://github.com/decodelabs/tagged) for equivalent HTML implementations of these interfaces.\n\n## Licensing\nDictum is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecodelabs%2Fdictum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecodelabs%2Fdictum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecodelabs%2Fdictum/lists"}