devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
67 lines (66 loc) • 1.71 kB
JavaScript
/**
* DevExtreme (esm/__internal/ui/number_box/m_utils.js)
* Version: 25.2.5
* Build date: Fri Feb 20 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
adjust,
roundFloatPart
} from "../../../core/utils/math";
const getRealSeparatorIndex = function(str) {
let quoteBalance = 0;
let separatorCount = 0;
for (let i = 0; i < str.length; ++i) {
if ("'" === str[i]) {
quoteBalance++
}
if ("." === str[i]) {
++separatorCount;
if (quoteBalance % 2 === 0) {
return {
occurrence: separatorCount,
index: i
}
}
}
}
return {
occurrence: 1,
index: -1
}
};
const getNthOccurrence = function(str, c, n) {
let i = -1;
while (n-- && i++ < str.length) {
i = str.indexOf(c, i)
}
return i
};
const splitByIndex = function(str, index) {
if (-1 === index) {
return [str]
}
return [str.slice(0, index), str.slice(index + 1)]
};
const adjustPercentValue = function(rawValue, interval) {
if (!rawValue) {
return rawValue
}
return adjust(rawValue / 100, interval / 100)
};
const roundFloatPartPercentValue = function(rawValue, precision) {
if (!rawValue) {
return rawValue
}
return roundFloatPart(rawValue / 100, precision)
};
export {
adjustPercentValue,
getNthOccurrence,
getRealSeparatorIndex,
roundFloatPartPercentValue,
splitByIndex
};