dtable-utils
Version:
dtable common utils
45 lines (41 loc) • 1.14 kB
JavaScript
import { CellType } from '../constants/cell-type.js';
import { FORMULA_COLUMN_TYPES_MAP, FORMULA_RESULT_TYPE } from '../constants/formula.js';
/**
* Get column type.
* @param {object} column { type, ... }
* @returns column type
*/
var getColumnType = function getColumnType(column) {
var type = column.type,
data = column.data;
if (FORMULA_COLUMN_TYPES_MAP[type]) {
var _ref = data || {},
result_type = _ref.result_type,
array_type = _ref.array_type;
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
return array_type;
}
return result_type;
}
if (type === CellType.LINK) {
var _ref2 = data || {},
_array_type = _ref2.array_type;
return _array_type;
}
return type;
};
/**
* Get columns by type.
* @param {array} columns
* @param {string} columnType
* @returns the target type columns, array
*/
var getColumnsByType = function getColumnsByType(columns, columnType) {
if (!Array.isArray(columns) || !columnType) {
return [];
}
return columns.filter(function (column) {
return column.type === columnType;
});
};
export { getColumnType, getColumnsByType };