UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

67 lines (66 loc) • 2.04 kB
/** * DevExtreme (cjs/__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/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.splitByIndex = exports.getRealSeparatorIndex = exports.getNthOccurrence = exports.asPattern = exports.adjustPercentValue = void 0; var _math = require("../../../core/utils/math"); var _type = require("../../../core/utils/type"); const asPattern = format => (0, _type.isString)(format) ? format : ""; exports.asPattern = asPattern; 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 } }; exports.getRealSeparatorIndex = getRealSeparatorIndex; 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 }; exports.getNthOccurrence = getNthOccurrence; const splitByIndex = (str, index) => { if (-1 === index) { return [str] } return [str.slice(0, index), str.slice(index + 1)] }; exports.splitByIndex = splitByIndex; const adjustPercentValue = (rawValue, interval) => { if (!rawValue) { return rawValue } return (0, _math.adjust)(rawValue / 100, interval / 100) }; exports.adjustPercentValue = adjustPercentValue;