UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

68 lines (67 loc) • 1.72 kB
/** * DevExtreme (esm/__internal/ui/number_box/utils.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { adjust } from "../../../core/utils/math"; import { isString } from "../../../core/utils/type"; const asPattern = format => isString(format) ? format : ""; const getRealSeparatorIndex = format => { const pattern = asPattern(format); let quoteBalance = 0; let separatorCount = 0; for (let i = 0; i < pattern.length; i += 1) { if ("'" === pattern[i]) { quoteBalance += 1 } if ("." === pattern[i]) { separatorCount += 1; if (quoteBalance % 2 === 0) { return { occurrence: separatorCount, index: i } } } } return { occurrence: 1, index: -1 } }; const getNthOccurrence = (str, char, occurrence) => { let index = -1; for (let remaining = occurrence; remaining > 0; remaining -= 1) { index = str.indexOf(char, index + 1); if (-1 === index) { return -1 } } return index }; const splitByIndex = (str, index) => { if (-1 === index) { return [str] } return [str.slice(0, index), str.slice(index + 1)] }; const adjustPercentValue = (rawValue, interval) => { if (!rawValue) { return rawValue } return adjust(rawValue / 100, interval / 100) }; export { adjustPercentValue, asPattern, getNthOccurrence, getRealSeparatorIndex, splitByIndex };