UNPKG

web-audio-test-api

Version:
35 lines (29 loc) 800 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = toMicroseconds; var MIN_MICRO_SECONDS = 0; var MAX_MICRO_SECONDS = 24 * 60 * 60 * 1000 * 1000; function toMicroseconds(time) { var value = 0; if (typeof time === "number") { // seconds -> microseconds value = Math.floor(time * 1000 * 1000) || 0; return Math.max(MIN_MICRO_SECONDS, Math.min(value, MAX_MICRO_SECONDS)); } var matches = /^([0-5]\d):([0-5]\d)\.(\d\d\d)$/.exec(time); if (matches) { // minutes value += +matches[1]; value *= 60; // seconds value += +matches[2]; value *= 1000; // milliseconds value += +matches[3]; value *= 1000; return Math.max(MIN_MICRO_SECONDS, Math.min(value, MAX_MICRO_SECONDS)); } return value; }