UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

57 lines (56 loc) • 1.95 kB
/** * DevExtreme (esm/__internal/core/options/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 devices from "../../../core/devices"; import { findBestMatches } from "../../../core/utils/common"; import { compileGetter } from "../../../core/utils/data"; import { extend } from "../../../core/utils/extend"; import { isEmptyObject, isFunction } from "../../../core/utils/type"; const cachedGetters = {}; export const deviceMatch = (device, filter) => isEmptyObject(filter) || findBestMatches(device, Array.isArray(filter) ? filter : [filter]).length > 0; export const convertRulesToOptions = rules => { const currentDevice = devices.current(); return rules.reduce((options, _ref) => { let { device: device, options: ruleOptions } = _ref; const deviceFilter = device || {}; const match = isFunction(deviceFilter) ? deviceFilter(currentDevice) : deviceMatch(currentDevice, deviceFilter); if (match) { extend(true, options, ruleOptions) } return options }, {}) }; export const normalizeOptions = (options, value) => "string" !== typeof options ? options : { [options]: value }; export function getFieldName(fullName) { return fullName.substr(fullName.lastIndexOf(".") + 1) } export const getParentName = fullName => fullName.substr(0, fullName.lastIndexOf(".")); export const getNestedOptionValue = function(optionsObject, name) { cachedGetters[name] = cachedGetters[name] || compileGetter(name); return cachedGetters[name](optionsObject, { functionsAsIs: true }) }; export const createDefaultOptionRules = function() { let options = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : []; return options };