UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

47 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertDurationToNumber = exports.maxCountBetweenChars = void 0; const maxCountBetweenChars = (charCount, value) => { if (!value) { return 0; } const arrayString = value.split(''); let max = -1; let aux = 0; arrayString.forEach((char, index) => { if (char === charCount && value.charAt(index + 1) !== charCount) { arrayString.slice(index + 1).some(charCom => { if (char !== charCom) { aux++; return false; } return true; }); if (max < aux) { max = aux; } aux = 0; } }); return max; }; exports.maxCountBetweenChars = maxCountBetweenChars; // The function is designed to convert a duration value, which could be a string or a number, into a numeric value representing milliseconds // If duration is already a number, it simply returns the number. const convertDurationToNumber = (duration) => { if (!duration) { return 0; } if (typeof duration === 'number') { return duration; } // Remove "ms" or "s" from the duration and convert it to a number const value = Number(duration.replace('ms', '').replace('s', '')); // If the duration was in seconds, convert it to milliseconds if (duration.includes('s') && !duration.includes('ms')) { return value * 1000; } return value; }; exports.convertDurationToNumber = convertDurationToNumber; //# sourceMappingURL=string.utility.js.map