MCPcopy
hub / github.com/tinyplex/tinybase / mapToObj

Function mapToObj

src/common/map.ts:85–103  ·  view source on GitHub ↗
(
  map: IdMap<MapValue> | undefined,
  valueMapper?: (mapValue: MapValue, id: Id) => ObjValue,
  excludeMapValue?: (mapValue: MapValue, id: Id) => boolean,
  excludeObjValue?: (objValue: ObjValue) => boolean,
)

Source from the content-addressed store, hash-verified

83};
84
85export const mapToObj = <MapValue, ObjValue = MapValue>(
86 map: IdMap<MapValue> | undefined,
87 valueMapper?: (mapValue: MapValue, id: Id) => ObjValue,
88 excludeMapValue?: (mapValue: MapValue, id: Id) => boolean,
89 excludeObjValue?: (objValue: ObjValue) => boolean,
90): IdObj<ObjValue> => {
91 const obj: IdObj<ObjValue> = {};
92 collForEach(map, (mapValue, id) => {
93 if (!excludeMapValue?.(mapValue, id)) {
94 const objValue = valueMapper
95 ? valueMapper(mapValue, id)
96 : (mapValue as any as ObjValue);
97 if (!excludeObjValue?.(objValue)) {
98 obj[id] = objValue;
99 }
100 }
101 });
102 return obj;
103};
104
105export const mapToObj2 = <MapValue, ObjValue = MapValue>(
106 map: IdMap2<MapValue> | undefined,

Callers 15

getMergeableTableHashesFunction · 0.90
getMergeableValueHashesFunction · 0.90
getMergeableValueDiffFunction · 0.90
getEncodedContentFunction · 0.90
getRowFunction · 0.90
getValuesFunction · 0.90
setCellFunction · 0.90
getTransactionLogFunction · 0.90
setPersistedFunction · 0.90
stampMapToObjWithHashFunction · 0.90

Calls 1

collForEachFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…