{"id":17218532,"url":"https://github.com/jwulf/typed-duration","last_synced_at":"2025-10-14T15:45:24.486Z","repository":{"id":43980955,"uuid":"245606512","full_name":"jwulf/typed-duration","owner":"jwulf","description":"Zero-dependency typed duration library for JavaScript","archived":false,"fork":false,"pushed_at":"2024-06-16T10:51:24.000Z","size":448,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-02T17:53:17.230Z","etag":null,"topics":["duration","typed","typed-js","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/typed-duration","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/jwulf.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-07T09:48:14.000Z","updated_at":"2024-06-05T14:38:15.000Z","dependencies_parsed_at":"2024-06-19T00:09:29.733Z","dependency_job_id":"99a8f92f-c7b4-4bb3-8085-bce2037241f2","html_url":"https://github.com/jwulf/typed-duration","commit_stats":{"total_commits":42,"total_committers":4,"mean_commits":10.5,"dds":0.5,"last_synced_commit":"92efcea546b9e7595a5cd720361e8d9673e44831"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jwulf/typed-duration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwulf%2Ftyped-duration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwulf%2Ftyped-duration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwulf%2Ftyped-duration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwulf%2Ftyped-duration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwulf","download_url":"https://codeload.github.com/jwulf/typed-duration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwulf%2Ftyped-duration/sbom","scorecard":{"id":545501,"data":{"date":"2025-08-11","repo":{"name":"github.com/jwulf/typed-duration","commit":"92efcea546b9e7595a5cd720361e8d9673e44831"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.8,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/7 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Warn: no topLevel permission defined: .github/workflows/tag-and-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/jwulf/typed-duration/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/jwulf/typed-duration/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tag-and-publish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/jwulf/typed-duration/tag-and-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/tag-and-publish.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/jwulf/typed-duration/tag-and-publish.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   2 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 23 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":5,"reason":"5 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T09:23:35.127Z","repository_id":43980955,"created_at":"2025-08-20T09:23:35.127Z","updated_at":"2025-08-20T09:23:35.127Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019353,"owners_count":26086711,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["duration","typed","typed-js","typescript"],"created_at":"2024-10-15T03:47:14.444Z","updated_at":"2025-10-14T15:45:24.467Z","avatar_url":"https://github.com/jwulf.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typed Duration \n\n![Node.js CI](https://github.com/jwulf/typed-duration/workflows/Node.js%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/typed-duration.svg)](https://badge.fury.io/js/typed-duration)\n\nA Zero-dependency typed duration library for JavaScript/TypeScript. Express and convert time durations with type-safety. \n\nThis library uses [Value Object Typing](https://medium.com/@hannespetri/type-safe-value-objects-in-typescript-d1b119c4f5cd) to allow you to express time durations in a type-safe way, and perform conversion between different units.\n\n**Note**: requires TypeScript 3.8 or later\n\nVersion 1.x works on Node 10+\nVersion 2.x requires Node 16+\n\n## Installation \n\nInstall the library to your project:\n\n```\nnpm i typed-duration\n```\n\n## Use \n\nConsider the following code:\n\n```TypeScript\nsetTimeout(doSomething, 1000)\n```\n\nIt's pretty clear that these are milliseconds, because you know the API. Typically, developers might do something like:\n\n```TypeScript\nsetTimeout(doSomething, 5 * 60 * 1000) // In Five Minutes\n```\n\nWith this library, you can do this: \n\n```TypeScript\nimport { Duration } from 'typed-duration'\nconst { milliseconds, minutes } = Duration\n\nconst period = minutes.of(5)\n\nsetTimeout(doSomething, milliseconds.from(period)) // Every Five Minutes\n```\n\nWell, that looks like more code. Yes, it is. It is also _more semantically expressive_ of the programmer's intent, which makes it _better for maintenance_.\n\nThe situation is exacerbated when you expose a programming API that takes a time duration as a `number`. We all know that `setTimeout` takes milliseconds, but how do you communicate to consumers of your API what the time units are for `timeout` in _your_ API call?\n\nYou should, of course, document it, and put it in JSDoc comments so that they can get hinting in their IDE. \n\nYou could call it `timeoutSeconds` to make it clear that it expects seconds.\n\nOr you could make it take a `TimeDuration` and allow them to pass in whatever they want, and convert it to the units you need, like this:\n\n```TypeScript\nimport { Duration, TimeDuration } from 'typed-duration'\n\nfunction executeLater(fn: () =\u003e void, delay: TimeDuration) {\n    setTimeout(fn, Duration.milliseconds.from(delay))\n}\n```\n\nNow, consumers of this function can call it like this:\n\n```TypeScript\nimport { Duration } from 'typed-duration'\nconst { milliseconds, seconds, minutes, hours, days } = Duration\n\n// After 2.5 seconds\nexecuteLater(doSomething, milliseconds.of(2500))\n\n// After 10 seconds\nexecuteLater(doSomething, seconds.of(10))\n\n// After 15 minutes\nexecuteLater(doSomething, minutes.of(15))\n\n// After 3 hours\nexecuteLater(doSomething, hours.of(3))\n\n// After 6 days\nexecuteLater(doSomething, days.of(6))\n```\n\n**#winning**\n\n## Backward-compatible API \n\nIf you have an existing API you want to add this to, you can use the `MaybeTimeDuration` type, like this:\n\n```TypeScript\nimport { Duration, MaybeTimeDuration } from 'typed-duration'\n\nfunction executeLater(fn: () =\u003e void, period: MaybeTimeDuration) {\n    setTimeout(fn, Duration.milliseconds.from(period))\n}\n\n// You can pass in a typed duration, and it will convert to a number of milliseconds\nexecuteLater(doSomething, Duration.seconds.from(20))\n\n// a number will be allowed by the MaybeTimeDuration type\n// and the milliseconds.from() call will simply pass it through\nexecuteLater(doSomething, 2500)\n```\n\n## Logging\n\nYou can log times for user information in the format that the user specified them, including units, with `Duration.value.of`. You can supply an optional default unit to be used for untyped numbers (if you don't, it will just print the number). \n\nFor example:\n\n```TypeScript\nimport { Duration, MaybeTimeDuration } from 'typed-duration'\n\nfunction executeLater(fn: () =\u003e void, delay: MaybeTimeDuration) {\n    console.log(`Executing in ${Duration.value.of(delay, \"ms\")}...`)\n    setTimeout(fn, Duration.milliseconds.from(delay))\n}\n\nexecuteLater(doSomething, Duration.seconds.from(20))\n// Executing in 20s...\n\nexecuteLater(doSomething, Duration.milliseconds.from(350))\n// Executing in 350ms...\n\nexecuteLater(doSomething, Duration.hours.from(3))\n// Executing in 3h...\n\nexecuteLater(doSomething, 2500)\n// Executing in 2500ms...\n```\n\n## Feature Requests, Bug Reports\n\nSee the [GitHub repo](https://github.com/jwulf/typed-duration).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwulf%2Ftyped-duration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwulf%2Ftyped-duration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwulf%2Ftyped-duration/lists"}