{"id":13725009,"url":"https://github.com/lukeed/ms","last_synced_at":"2025-10-09T18:23:45.707Z","repository":{"id":49220845,"uuid":"247785499","full_name":"lukeed/ms","owner":"lukeed","description":"A tiny (414B) and fast utility to convert milliseconds to and from strings.","archived":false,"fork":false,"pushed_at":"2024-01-15T17:14:21.000Z","size":24,"stargazers_count":216,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-08T00:08:29.716Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/lukeed.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"lukeed"}},"created_at":"2020-03-16T18:10:25.000Z","updated_at":"2024-10-17T00:59:29.000Z","dependencies_parsed_at":"2024-01-15T18:55:16.655Z","dependency_job_id":"3981c844-990d-4370-886e-6c4c88504f7e","html_url":"https://github.com/lukeed/ms","commit_stats":{"total_commits":29,"total_committers":3,"mean_commits":9.666666666666666,"dds":"0.10344827586206895","last_synced_commit":"552c409e55b4789b9d9be7f0a592b80f2fc2676d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukeed%2Fms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukeed","download_url":"https://codeload.github.com/lukeed/ms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645171,"owners_count":17346090,"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-08-03T01:02:09.738Z","updated_at":"2025-10-09T18:23:40.683Z","avatar_url":"https://github.com/lukeed.png","language":"JavaScript","funding_links":["https://github.com/sponsors/lukeed"],"categories":["JavaScript"],"sub_categories":[],"readme":"# ms [![CI](https://github.com/lukeed/ms/workflows/CI/badge.svg)](https://github.com/lukeed/ms/actions) [![codecov](https://badgen.net/codecov/c/github/lukeed/ms)](https://codecov.io/gh/lukeed/ms)\n\n\u003e A tiny (414B) and [fast](#benchmarks) utility to convert milliseconds to and from strings.\n\n---\n\n***NOTICE:** This is a fork of [vercel/ms](https://github.com/vercel/ms)!*\u003cbr\u003e\nIn June 2019, I [opened a PR](https://github.com/zeit/ms/pull/120) with signficiant performance and code size improvements. After nearly 2 years of silence, it was eventually closed. :cry: A year into my wait, I started anew (this repo), hoping to improve upon my own improvements.\n\n---\n\nThis module is delivered as:\n\n* **CommonJS**: [`dist/index.js`](https://unpkg.com/@lukeed/ms/dist/index.js)\n* **ES Module**: [`dist/index.mjs`](https://unpkg.com/@lukeed/ms/dist/index.mjs)\n* **UMD**: [`dist/index.min.js`](https://unpkg.com/@lukeed/ms/dist/index.min.js)\n\n## Install\n\n```\n$ npm install --save @lukeed/ms\n```\n\n\n## Usage\n\n```js\nimport { parse, format } from '@lukeed/ms';\n\n// string =\u003e number\nparse('2 days');   //=\u003e 172800000\nparse('1d');       //=\u003e 86400000\nparse('10h');      //=\u003e 36000000\nparse('2.5 hrs');  //=\u003e 9000000\nparse('2h');       //=\u003e 7200000\nparse('1m');       //=\u003e 60000\nparse('5s');       //=\u003e 5000\nparse('1y');       //=\u003e 31557600000\nparse('100');      //=\u003e 100\nparse('-3 days');  //=\u003e -259200000\nparse('-1h');      //=\u003e -3600000\nparse('-200');     //=\u003e -200\n\n// number =\u003e string\nformat(60000);             //=\u003e '1m'\nformat(2 * 60000);         //=\u003e '2m'\nformat(-3 * 60000);        //=\u003e '-3m'\nformat(parse('10 hours')); //=\u003e '10h'\n\n// number =\u003e string (long)\nformat(60000, true);             //=\u003e '1 minute'\nformat(2 * 60000, true);         //=\u003e '2 minutes'\nformat(-3 * 60000, true);        //=\u003e '-3 minutes'\nformat(parse('10 hours'), true); //=\u003e '10 hours'\n```\n\n\n## API\n\n### ms.parse(input)\nReturns: `Number`| `undefined`\n\nParses the input string, returning the number of milliseconds or `undefined` if the value can't be parsed successfully.\n\n#### input\nType: `String`\n\nThe human-readable time string; eg: `10min`, `10m`, `10 minutes`.\n\n\n### ms.format(milli, long?)\nReturns: `Number`\n\nFormats the millisecond count to a human-readable time string.\n\n\u003e **Important:** The output will be rounded to the nearest whole integer.\n\n#### milli\nType: `Number`\n\nThe number of milliseconds.\n\n#### long\nType: `Boolean`\u003cbr\u003e\nDefault: `false`\n\nWhether or not the output should use the interval's long/full form; eg `hour` or `hours` instead of `h`.\n\n\u003e **Note:** When `long`, the count and interval will be separated by a single space.\u003cbr\u003eAlso, when `long`, the interval may be pluralized; eg `1 second` vs `2 seconds`.\n\n\n## Benchmarks\n\n\u003e Running on Node.js v12.18.4\n\n```\nValidation :: parse\n  ✔ lukeed/ms\n  ✔ zeit/ms\n\nBenchmark :: \"parse\"\n  lukeed/ms      x 351,319 ops/sec ±0.31% (96 runs sampled)\n  zeit/ms        x 245,576 ops/sec ±1.66% (94 runs sampled)\n\nBenchmark :: \"parse\" (long)\n  lukeed/ms      x 335,538 ops/sec ±0.50% (94 runs sampled)\n  zeit/ms        x 265,410 ops/sec ±1.72% (95 runs sampled)\n\n\nValidation :: format\n  ✔ lukeed/ms\n  ✔ zeit/ms\n\nBenchmark :: \"format\"\n  lukeed/ms      x 4,109,440 ops/sec ±0.35% (94 runs sampled)\n  zeit/ms        x 3,420,198 ops/sec ±1.61% (94 runs sampled)\n\nBenchmark :: \"format\" (long)\n  lukeed/ms      x 3,402,872 ops/sec ±0.14% (97 runs sampled)\n  zeit/ms        x 1,344,908 ops/sec ±3.68% (96 runs sampled)\n```\n\n\n## Credits\n\nThis is obviously a fork of [zeit/ms](https://github.com/zeit/ms).\n\nI opened a [PR in June 2019](https://github.com/zeit/ms/pull/120) that introduced significant performance gains and code reduction \u0026mdash; it was ignored for nearly two years. This repository is a from-scratch re-implementation that takes the goals of that PR a bit further.\n\n\n## License\n\nMIT © [Luke Edwards](https://lukeed.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukeed%2Fms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukeed%2Fms/lists"}