1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /*!
- * (C) Ionic http://ionicframework.com - MIT License
- */
- 'use strict';
- /**
- * Uses the compareWith param to compare two values to determine if they are equal.
- *
- * @param currentValue The current value of the control.
- * @param compareValue The value to compare against.
- * @param compareWith The function or property name to use to compare values.
- */
- const compareOptions = (currentValue, compareValue, compareWith) => {
- if (typeof compareWith === 'function') {
- return compareWith(currentValue, compareValue);
- }
- else if (typeof compareWith === 'string') {
- return currentValue[compareWith] === compareValue[compareWith];
- }
- else {
- return Array.isArray(compareValue) ? compareValue.includes(currentValue) : currentValue === compareValue;
- }
- };
- /**
- * Compares a value against the current value(s) to determine if it is selected.
- *
- * @param currentValue The current value of the control.
- * @param compareValue The value to compare against.
- * @param compareWith The function or property name to use to compare values.
- */
- const isOptionSelected = (currentValue, compareValue, compareWith) => {
- if (currentValue === undefined) {
- return false;
- }
- if (Array.isArray(currentValue)) {
- return currentValue.some((val) => compareOptions(val, compareValue, compareWith));
- }
- else {
- return compareOptions(currentValue, compareValue, compareWith);
- }
- };
- exports.compareOptions = compareOptions;
- exports.isOptionSelected = isOptionSelected;
|