{"id":13828376,"url":"https://github.com/mtownsend5512/read-time","last_synced_at":"2025-04-12T18:51:02.579Z","repository":{"id":55090549,"uuid":"164679428","full_name":"mtownsend5512/read-time","owner":"mtownsend5512","description":"A PHP package to show users how long it takes to read content.","archived":false,"fork":false,"pushed_at":"2021-01-11T13:47:41.000Z","size":34,"stargazers_count":283,"open_issues_count":5,"forks_count":28,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-24T16:36:19.528Z","etag":null,"topics":["read-time","readtime","time-to-read","words-per-minute"],"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/mtownsend5512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-08T15:35:56.000Z","updated_at":"2024-02-18T10:46:24.000Z","dependencies_parsed_at":"2022-08-14T11:40:37.862Z","dependency_job_id":null,"html_url":"https://github.com/mtownsend5512/read-time","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fread-time","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fread-time/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fread-time/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fread-time/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtownsend5512","download_url":"https://codeload.github.com/mtownsend5512/read-time/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618223,"owners_count":21134199,"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":["read-time","readtime","time-to-read","words-per-minute"],"created_at":"2024-08-04T09:02:43.643Z","updated_at":"2025-04-12T18:51:02.545Z","avatar_url":"https://github.com/mtownsend5512.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"A PHP package to show users how long it takes to read content.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://i.imgur.com/41dLat4.png\"\u003e\n\u003c/p\u003e\n\n## Installation\n\nInstall via composer:\n\n\n```\ncomposer require mtownsend/read-time\n```\n\n\n*This package is designed to work with any PHP 7.0+ application but has special support for Laravel.*\n\n### Registering the service provider (Laravel)\n\nFor Laravel 5.4 and lower, add the following line to your ``config/app.php``:\n\n```php\n/*\n * Package Service Providers...\n */\nMtownsend\\ReadTime\\Providers\\ReadTimeServiceProvider::class,\n```\n\nFor Laravel 5.5 and greater, the package will auto register the provider for you.\n\n### Using Lumen\n\nTo register the service provider, add the following line to ``app/bootstrap/app.php``:\n\n```php\n$app-\u003eregister(Mtownsend\\ReadTime\\Providers\\ReadTimeServiceProvider::class);\n```\n\n### Publishing the config file (Laravel)\n\nReadTime has special configuration support for Laravel applications. You can publish a single config file and customize how you want your read time text to be displayed.\n\n````\nphp artisan vendor:publish --provider=\"Mtownsend\\ReadTime\\Providers\\ReadTimeServiceProvider\" --tag=\"read-time-config\"\n````\n\nThese are the contents of the ``read-time.php`` config file:\n\n```php\nreturn [\n\n    /*\n     * Whether or not minute/second should be abbreviated as min/sec\n     */\n    'abbreviate_time_measurements' =\u003e false,\n\n    /*\n     * Omit seconds from being displayed in the read time estimate\n     */\n    'omit_seconds' =\u003e true,\n\n    /*\n     * Whether or not only the time should be displayed\n     */\n    'time_only' =\u003e false,\n\n    /*\n     * The average words per minute reading time\n     */\n    'words_per_minute' =\u003e 230,\n];\n```\n\n### Publishing the translation files (Laravel)\n\nReadTime supports localization with Laravel. If you are using Laravel you'll likely want to use the premade translations.\n\n````\nphp artisan vendor:publish --provider=\"Mtownsend\\ReadTime\\Providers\\ReadTimeServiceProvider\" --tag=\"read-time-language-files\"\n````\n\n## Quick start\n\n### Using the class\n\nHere is an example of the most basic usage:\n\n```php\nuse Mtownsend\\ReadTime\\ReadTime;\n\n$readTime = (new ReadTime($content))-\u003eget();\n```\n\nYou may also pass several arguments to the constructor if you wish to change settings on the fly:\n\n```php\nuse Mtownsend\\ReadTime\\ReadTime;\n\n$readTime = (new ReadTime($content, $omitSeconds = true, $abbreviated = false, $wordsPerMinute = 230))-\u003eget();\n// or\n$readTime = (new ReadTime($content))\n\t\t\t\t-\u003eomitSeconds()\n\t\t\t\t-\u003eabbreviated()\n\t\t\t\t-\u003ewpm($wordsPerMinute)\n\t\t\t\t-\u003eget();\n```\n\nThe ReadTime class is able to accept a string of content or a flat array of multiple pieces of content. This may come in handy if you are attempting to display the total read time of body content along with sidebar content. For example:\n\n```php\nuse Mtownsend\\ReadTime\\ReadTime;\n\n$readTime = (new ReadTime([$content, $moreContent, $evenMoreContent]))-\u003eget();\n```\n\n## Methods, and arguments\n\n**Method**\n\n``-\u003eabbreviated(bool $abbreviated = true)``\n\nAbbreviate the words 'minute' and 'second' to 'min' and 'sec'.\n\n``-\u003eget()``\n\nRetrieve the read time. *Note: you may also invoke the class as a function or cast it as a string to retrieve the same result as ``get()``.*\n\n``-\u003egetTranslation($key = null)``\n\nYou may return the current translation array the class is using by omitting any argument from this method or get a specific translation key by passing it as an argument.\n\n``-\u003eltr(bool $ltr = true)``\n\nSet the text direction of the read time result to left (default) with true, and ``right`` with ``false``. Alternatively, you may simply call the ``-\u003ertl()`` method without any argument.\n\n``-\u003eomitSeconds(bool $omitSeconds = true)``\n\nHave the read time display omit seconds. Pass ``false`` to include seconds.\n\n``-\u003ertl(bool $rtl = true)``\n\nSet the text direction of the read time result to right (default) with true, and ``left`` with ``false``. Alternatively, you may simply call the ``-\u003eltr()`` method without any argument.\n\n``-\u003esetTranslation(array $translations)``\n\nManually set the translation text for the class to use. If no key is passed it will default to the English counterpart. A complete translation array will contain the following:\n\n```php\n[\n    'reads_left_to_right' =\u003e true,\n    'min' =\u003e 'min',\n    'minute' =\u003e 'minute',\n    'sec' =\u003e 'sec',\n    'second' =\u003e 'second',\n    'read' =\u003e 'read'\n]\n```\n\n``-\u003etimeOnly(bool $timeOnly = true)``\n\nOmit any words from the read time result. Pass ``false`` to include words.\n\n``-\u003etoArray()``\n\nGet the contents and settings of the class as an array.\n\n``-\u003etoJson()``\n\nGet the contents and settings of the class as a json string.\n\n``-\u003ewpm(int $wordsPerMinute)``\n\nSet the average pace of words read per minute.\n\n### Using the global helper (Laravel)\n\nIf you are using Laravel, this package provides a convenient helper function which is globally accessible.\n\n```php\nread_time($content);\n```\n\nThe global helper is exceptionally useful in your Laravel application. It can be used in views (remember, it outputs the read time if invoked or cast as a string, which Blade's double curly braces does):\n\n````\n\u003ch1\u003eSome blog title\u003c/h1\u003e\n\u003csmall\u003e{{ read_time($content) }}\u003c/small\u003e\n\u003chr\u003e\n````\n\nThe global helper will also attempt to intelligently detect the information you are passing it. For example, if you pass it a **non-associative array** it will assume you are passing an array of content.\n\n````\n\u003ch1\u003eSome blog title\u003c/h1\u003e\n\u003csmall\u003e{{ read_time([$content, $moreContent]) }}\u003c/small\u003e\n\u003chr\u003e\n````\n\nBut you are still free to customize the ReadTime class settings on the fly using the global helper. Simply pass an associative array of settings:\n\n````\n{{ read_time([\n    'content' =\u003e $content,\n    // or\n    // 'content' =\u003e [$content, $moreContent],\n    'omit_seconds' =\u003e true,\n    'time_only' =\u003e false,\n    'abbreviated' =\u003e true,\n    'words_per_minute' =\u003e 230,\n    'ltr' =\u003e true,\n    'translation' =\u003e [\n        'reads_left_to_right' =\u003e true,\n        'min' =\u003e 'min',\n        'minute' =\u003e 'minute',\n        'sec' =\u003e 'sec',\n        'second' =\u003e 'second',\n        'read' =\u003e 'read'\n    ]\n]) }}\n````\n\n## Purpose\n\nSites like Medium.com have popularized the concept of giving users an estimate for the amount of time it will take them to read the content. With this convenience in mind, ReadTime gives PHP developers the same tool for their readable content. It's a simple feature that will give a nice touch to your PHP application.\n\n## Contributing translations\n\nPull requests for translations are encouraged. Please be sure to follow the existing format.\n\n## Credits\n\n- Mark Townsend\n- [All Contributors](../../contributors)\n\n## Testing\n\nYou can run the tests with:\n\n```bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fread-time","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtownsend5512%2Fread-time","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fread-time/lists"}