UNPKG

dtable-utils

Version:

dtable common utils

32 lines (29 loc) 843 B
/** * 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]; }; export { getTableById, getTableByIndex, getTableByName };