dtable-utils
Version:
dtable common utils
38 lines (33 loc) • 985 B
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Get table by id
* @param {array} tables
* @param {string} tableId
* @returns table, object
*/
var getTableById = function getTableById(tables, tableId) {
if (!Array.isArray(tables) || !tableId) return null;
return tables.find(function (table) {
return table._id === tableId;
});
};
/**
* Get table by name
* @param {array} tables
* @param {string} tableName
* @returns table, object
*/
var getTableByName = function getTableByName(tables, tableName) {
if (!Array.isArray(tables) || !tableName) return null;
return tables.find(function (table) {
return table.name === tableName;
});
};
var getTableByIndex = function getTableByIndex(tables, tableIndex) {
if (!Array.isArray(tables) || tableIndex < 0) return null;
return tables[tableIndex];
};
exports.getTableById = getTableById;
exports.getTableByIndex = getTableByIndex;
exports.getTableByName = getTableByName;