@am92/securities-utility
Version:
A utility package for securities applications
27 lines (26 loc) • 900 B
JavaScript
/**
* Handles indexing of script IDs by associating them with metadata such as segment keys,
* item indices, and derivative item indices (if applicable). This allows quick lookup
* of script metadata based on their IDs.
*
* @returns {TIndexHandler<TScriptIdIndex>} An object containing methods to add rows to the index
* and retrieve the indexed data.
*/
export const scriptIdIndexHandler = () => {
const index = {};
const addRow = (segmentKey, itemIndex, itemData, derivativeItemIndex, derivativeItem) => {
let item = (derivativeItem && derivativeItem) ||
itemData;
const scriptId = item[0];
const map = [segmentKey, itemIndex];
if (derivativeItemIndex) {
map.push(3, derivativeItemIndex);
}
index[scriptId] = map;
};
const getIndex = () => index;
return {
addRow,
getIndex
};
};