{"id":13396751,"url":"https://github.com/vercel/ms","last_synced_at":"2026-04-02T18:45:34.497Z","repository":{"id":2664585,"uuid":"3655872","full_name":"vercel/ms","owner":"vercel","description":"Tiny millisecond conversion utility","archived":false,"fork":false,"pushed_at":"2024-08-29T22:24:11.000Z","size":433,"stargazers_count":5264,"open_issues_count":32,"forks_count":274,"subscribers_count":91,"default_branch":"main","last_synced_at":"2025-05-06T20:24:04.158Z","etag":null,"topics":["conversion","milliseconds","utility"],"latest_commit_sha":null,"homepage":"https://npmjs.com/ms","language":"TypeScript","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/vercel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-03-08T02:10:13.000Z","updated_at":"2025-05-05T16:03:10.000Z","dependencies_parsed_at":"2023-07-06T12:19:06.124Z","dependency_job_id":"3c77e845-22f7-4bc6-b1ec-a6e30c5ea73d","html_url":"https://github.com/vercel/ms","commit_stats":{"total_commits":138,"total_committers":38,"mean_commits":"3.6315789473684212","dds":0.6666666666666667,"last_synced_commit":"8b5923d1d86c84a9f6aba8022d416dcf2361aa8d"},"previous_names":["guille/ms.js","zeit/ms","rauchg/ms.js"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vercel%2Fms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vercel","download_url":"https://codeload.github.com/vercel/ms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252949321,"owners_count":21830150,"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":["conversion","milliseconds","utility"],"created_at":"2024-07-30T18:01:01.923Z","updated_at":"2025-12-17T21:10:50.791Z","avatar_url":"https://github.com/vercel.png","language":"TypeScript","readme":"# ms\n\n![CI](https://github.com/vercel/ms/workflows/CI/badge.svg)\n![Edge Runtime Compatible](https://img.shields.io/badge/edge--runtime-%E2%9C%94%20compatible-black)\n\nUse this package to easily convert various time formats to milliseconds.\n\n## Examples\n\n\u003c!-- prettier-ignore --\u003e\n```js\nms('2 days')  // 172800000\nms('1d')      // 86400000\nms('10h')     // 36000000\nms('2.5 hrs') // 9000000\nms('2h')      // 7200000\nms('1m')      // 60000\nms('5s')      // 5000\nms('1y')      // 31557600000\nms('100')     // 100\nms('-3 days') // -259200000\nms('-1h')     // -3600000\nms('-200')    // -200\n```\n\n### Convert from Milliseconds\n\n\u003c!-- prettier-ignore --\u003e\n```js\nms(60000)             // \"1m\"\nms(2 * 60000)         // \"2m\"\nms(-3 * 60000)        // \"-3m\"\nms(ms('10 hours'))    // \"10h\"\n```\n\n### Time Format Written-Out\n\n\u003c!-- prettier-ignore --\u003e\n```js\nms(60000, { long: true })             // \"1 minute\"\nms(2 * 60000, { long: true })         // \"2 minutes\"\nms(-3 * 60000, { long: true })        // \"-3 minutes\"\nms(ms('10 hours'), { long: true })    // \"10 hours\"\n```\n\n## Features\n\n- Works both in [Node.js](https://nodejs.org) and in the browser\n- If a number is supplied to `ms`, a string with a unit is returned\n- If a string that contains the number is supplied, it returns it as a number (e.g.: it returns `100` for `'100'`)\n- If you pass a string with a number and a valid unit, the number of equivalent milliseconds is returned\n\n## TypeScript support\n\nAs of `v3.0`, this package includes TypeScript definitions.\n\nFor added safety, we're using [Template Literal Types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html) (added in [TypeScript 4.1](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html)). This ensures that you don't accidentally pass `ms` values that it can't process.\n\nThis won't require you to do anything special in most situations, but you can also import the `StringValue` type from `ms` if you need to use it.\n\n```ts\nimport ms, { StringValue } from 'ms';\n\n// Using the exported type.\nfunction example(value: StringValue) {\n  ms(value);\n}\n\n// This function will only accept a string compatible with `ms`.\nexample('1 h');\n```\n\nIn this example, we use a [Type Assertion](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions) to coerce a `string`.\n\n```ts\nimport ms, { StringValue } from 'ms';\n\n// Type assertion with the exported type.\nfunction example(value: string) {\n  try {\n    // A string could be \"wider\" than the values accepted by `ms`, so we assert\n    // that our `value` is a `StringValue`.\n    //\n    // It's important to note that this can be dangerous (see below).\n    ms(value as StringValue);\n  } catch (error: Error) {\n    // Handle any errors from invalid values.\n    console.error(error);\n  }\n}\n\n// This function will accept any string, which may result in a bug.\nexample('any value');\n```\n\nYou may also create a custom Template Literal Type.\n\n```ts\nimport ms from 'ms';\n\ntype OnlyDaysAndWeeks = `${number} ${'days' | 'weeks'}`;\n\n// Using a custom Template Literal Type.\nfunction example(value: OnlyDaysAndWeeks) {\n  // The type of `value` is narrower than the values `ms` accepts, which is\n  // safe to use without coercion.\n  ms(value);\n}\n\n// This function will accept \"# days\" or \"# weeks\" only.\nexample('5.2 days');\n```\n\n## Advanced Usage\n\nAs of `v3.0`, you can import `parse` and `format` separately.\n\n```ts\nimport { parse, format } from 'ms';\n\nparse('1h'); // 3600000\n\nformat(2000); // \"2s\"\n```\n\nIf you want strict type checking for the input value, you can use `parseStrict`.\n\n```ts\nimport { parseStrict } from 'ms';\n\nparseStrict('1h'); // 3600000\n\nfunction example(s: string) {\n  return parseStrict(str); // tsc error\n}\n```\n\n## Edge Runtime Support\n\n`ms` is compatible with the [Edge Runtime](https://edge-runtime.vercel.app/). It can be used inside environments like [Vercel Edge Functions](https://vercel.com/edge) as follows:\n\n```js\n// Next.js (pages/api/edge.js) (npm i next@canary)\n// Other frameworks (api/edge.js) (npm i -g vercel@canary)\n\nimport ms from 'ms';\nconst start = Date.now();\n\nexport default (req) =\u003e {\n  return new Response(`Alive since ${ms(Date.now() - start)}`);\n};\n\nexport const config = {\n  runtime: 'experimental-edge',\n};\n```\n\n## Related Packages\n\n- [ms.macro](https://github.com/knpwrs/ms.macro) - Run `ms` as a macro at build-time.\n\n## Caught a Bug?\n\n1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device\n2. Link the package to the global module directory: `npm link`\n3. Within the module you want to test your local development instance of ms, just link it to the dependencies: `npm link ms`. Instead of the default one from npm, Node.js will now use your clone of ms!\n\nAs always, you can run the tests using: `npm test`\n","funding_links":[],"categories":["时间","Repository","Packages","TypeScript","Uncategorized","JavaScript","GIT 仓库","包","Dates and Time"],"sub_categories":["Date \u0026 Time","Humanize","Uncategorized","日期/时间","人性化","Reactive Programming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercel%2Fms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvercel%2Fms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvercel%2Fms/lists"}