{"id":21961839,"url":"https://github.com/trapcodeio/readable-setimeout","last_synced_at":"2025-03-22T20:27:36.341Z","repository":{"id":57348632,"uuid":"323214020","full_name":"trapcodeio/readable-setimeout","owner":"trapcodeio","description":"Readable setTimeout functions for humans. :)","archived":false,"fork":false,"pushed_at":"2020-12-21T03:18:47.000Z","size":36,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T13:28:04.109Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trapcodeio.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-21T02:49:14.000Z","updated_at":"2023-01-14T13:05:31.000Z","dependencies_parsed_at":"2022-09-01T13:31:29.354Z","dependency_job_id":null,"html_url":"https://github.com/trapcodeio/readable-setimeout","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Freadable-setimeout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Freadable-setimeout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Freadable-setimeout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trapcodeio%2Freadable-setimeout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trapcodeio","download_url":"https://codeload.github.com/trapcodeio/readable-setimeout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245017410,"owners_count":20547799,"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":[],"created_at":"2024-11-29T10:18:45.818Z","updated_at":"2025-03-22T20:27:36.318Z","avatar_url":"https://github.com/trapcodeio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Javascript Readable SetTimeout\n\nCreate setTimeouts using readable timeout strings.\n\nImagine we could declare timeouts like this\n\n```javascript\nsetTimeout(() =\u003e false, \"next 10 seconds\");\n// or\nsetTimeout(() =\u003e false, \"30 seconds from now\");\n//\nsetTimeout(() =\u003e false, \"in 1 hour 30 minutes from now\");\n```\n\nWell, thanks to [chrono-node](https://npmjs.org/package/chrono-node) and some **magic lines of voodoo** this package is\nable to achieve that but of course not with same default `setTimeout` function.\n\n## Installation\n\n```shell\nnpm i readable-timeout\n# OR\nyarn add readable-timeout\n```\n\n## Usage\n\n```javascript\nconst Timeout = require('readable-timeout');\n\nTimeout.define(() =\u003e false, \"next 30 seconds\");\n// is equivalent to\nTimeout.run(() =\u003e false, \"next 30 seconds\"); // allias of define\n// is equivalent to\nsetTimeout(() =\u003e false, 30000) // 3000±1\n// is equivalent to\nTimeout.run(() =\u003e false, 30000) \n// milliseconds can also be used but defeats the purpose of this package\n```\n\n**Note:** All setTimeouts returns the timeout as the default `setTimeout` would.\n\n### .in\n\nThe `.in` method gives you the freedom of declaring timeouts first if you find it easier to read.\n\n```javascript\nconst Timeout = require('readable-timeout');\n\nTimeout.in(\"30 seconds\", () =\u003e false);\n```\n\n## Utils\n\nThe class also includes functions that converts strings to milliseconds\n\n### .ms\n\nThis function converts a string to milliseconds or throws an error if it can't.\n\n```javascript\nconst Timeout = require('readable-timeout');\n\nTimeout.ms(\"next 5 seconds\"); // 5000±1000\n```\n\n### .msIn\n\nSame as `ms` but used in `.in`, Adds `from now` to the end of your text. This is because `chrono-node` needs it to\nunderstand simple non-sentence strings like \"30 seconds\"\n\n```javascript\nconst Timeout = require('readable-timeout');\n\nTimeout.msIn(\"5 seconds\"); // 5000±1000\n// is transformed to\nTimeout.ms(\"5 seconds from now\");\n```\n\n## Performance\n\nIf you are **extremely** Performance conscious then you should use the default `setTimeout` because it would take a **very tiny\nmillisecond** to understand your string and convert to milliseconds.\n\n\n## Accuracy\n\nReturned milliseconds is not exactly the number you are expecting, most times maybe ±1000ms. You can Run tests to see\nwhat we mean. E.g.\n\n```javascript\nconst Timeout = require('readable-timeout');\n\n// you would expect this to return 10000\nTimeout.msIn(\"10 seconds\");\n// what maybe returned\n// Between [9000-11000]\n```\n\nThis only means a lot when you want the exact `seconds`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrapcodeio%2Freadable-setimeout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrapcodeio%2Freadable-setimeout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrapcodeio%2Freadable-setimeout/lists"}