@atlaskit/motion
Version:
A set of utilities to apply motion in your application.
13 lines (12 loc) • 430 B
JavaScript
export var convertToMs = function convertToMs(duration) {
// Use regex to separate the number and the unit
var matches = duration.match(/^(\d+\.?\d*)(s|ms)$/);
if (!matches) return 0; // Or return for invalid format
var value = parseFloat(matches[1]);
var unit = matches[2];
if (unit === 's') {
return value * 1000; // Convert seconds to milliseconds
} else {
return value; // Already in milliseconds
}
};