{"library":"ms.macro","title":"Build-Time MS Converter Macro","description":"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.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install ms.macro"],"cli":null},"imports":["import ms from 'ms.macro';","import ms from 'ms.macro';\nconst ONE_DAY = ms`1 day`;","import msm from 'ms.macro';\nimport ms from 'ms';\nconst value = msm('1h');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import ms from 'ms.macro';\n\n// Basic function call usage\nconst ONE_HOUR = ms('1 hour');\nconst TWO_DAYS = ms('2 days');\nconst THIRTY_MINUTES = ms('30m');\n\n// Tagged template literal usage\nconst ONE_WEEK = ms`1 week`;\nconst HALF_DAY = ms`0.5d`;\n\nconsole.log(`One hour in milliseconds: ${ONE_HOUR}`); // -> 3600000\nconsole.log(`Two days in milliseconds: ${TWO_DAYS}`); // -> 172800000\nconsole.log(`Thirty minutes in milliseconds: ${THIRTY_MINUTES}`); // -> 1800000\nconsole.log(`One week in milliseconds: ${ONE_WEEK}`); // -> 604800000\nconsole.log(`Half day in milliseconds: ${HALF_DAY}`); // -> 43200000","lang":"javascript","description":"Demonstrates `ms.macro` converting various human-readable time strings into millisecond values at build time, using both function call and tagged template literal syntax.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}