The `ms` package is a small, focused utility designed for converting various time formats to milliseconds and vice versa. It parses human-readable strings (e.g., '2 days', '10h', '5s') into their millisecond equivalents and formats millisecond values back into concise, human-readable strings (e.g., 3600000 becomes '1h'). The current stable version is 2.1.3, though version 3.0.0 is actively in canary, introducing significant changes including full TypeScript support and a transition to an ESM-only distribution. This makes `ms` a reliable, lightweight choice for common duration parsing and formatting tasks in both Node.js and browser environments, distinguished by its minimal API and broad adoption in the Vercel ecosystem.
npm install msVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic conversion from human-readable strings to milliseconds and vice versa, including negative durations and the 'long' option.
Migrate from `const ms = require('ms');` to `import ms from 'ms';`. For Node.js, ensure your `package.json` contains `"type": "module"` or use `.mjs` file extensions for your consuming modules.Ensure that string inputs to `ms()` do not exceed 100 characters. Implement input validation or truncation if processing arbitrary user-provided strings.
Review any explicit references to `zeit/ms` (e.g., in CI configurations, monorepo paths, or dependency mirroring) and update them to `vercel/ms` if necessary. The npm package name remains 'ms'.
Update to `ms` version 2.1.1 or later to ensure reliable and correct handling of negative duration strings.
Remove the superfluous parentheses: `const ms = require('ms'); ms('1h');` or simply `require('ms')('1h');` for CommonJS. For ESM, ensure `import ms from 'ms';` and then `ms('1h');`.Ensure the input to `ms()` is always a valid string (e.g., '2 days') or a valid number (e.g., 3600000). Always validate external inputs before passing them to `ms()`.
Convert your consuming module to ESM by adding `"type": "module"` to your nearest `package.json` file and changing `require('ms')` to `import ms from 'ms';`. Alternatively, for existing CommonJS projects, stick to `ms` v2.x.x.Add `"type": "module"` to your project's `package.json` file or rename your file to `.mjs`. If maintaining a CommonJS module, you must use `ms` v2.x.x or earlier with `require()`.
No dependency data recorded yet.