ms.macro is a Babel macro designed to convert human-readable time strings (e.g., "1 day", "2 hours") into their corresponding millisecond values directly at build time. This package, currently at version 2.0.0, aims to eliminate runtime dependencies and shift potential conversion errors from runtime to build time. It is a stable package that typically sees updates driven by changes in Babel's macro API or the underlying `ms` package's parsing logic. Its primary differentiator is its build-time execution, which means that the original `ms` package does not need to be shipped with your production code for these specific conversions, resulting in smaller bundle sizes and improved reliability by catching invalid time strings during compilation rather than during execution. Unlike the original `ms` package, `ms.macro` exclusively supports the string-to-number conversion; it does not offer the reverse conversion from milliseconds to a human-readable string.
npm install ms.macroVerified import paths — ran on the pinned version, not inferred.
Demonstrates `ms.macro` converting various human-readable time strings into millisecond values at build time, using both function call and tagged template literal syntax.
For converting milliseconds back to a string, you must use the original `ms` package directly (e.g., `import ms from 'ms';`). You can alias `ms.macro` if both are needed.
Ensure `babel-plugin-macros` is installed (`npm install babel-plugin-macros`) and added to your Babel configuration (e.g., in `.babelrc` or `babel.config.js`).
Always pass a single string representing the time duration to `ms.macro`, e.g., `ms('1 day')` or `ms`1 hour`.Correct the time string to a valid format understood by the `ms` library (e.g., '1 day', '2h', '30m').
Verify that `babel-plugin-macros` is installed and properly configured in your Babel setup. Ensure you are using `import ms from 'ms.macro';` in an environment where Babel is processing your files.