MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / roughSizeOfObject

Function roughSizeOfObject

lib/utils.ts:584–610  ·  view source on GitHub ↗
(object: object)

Source from the content-addressed store, hash-verified

582}
583
584export function roughSizeOfObject(object: object): number {
585 /** Gets the rough memory size of the object in bytes. **/
586 let objectList: object[] = [];
587
588 function recurse(value: any): number {
589 let bytes = 0;
590
591 if (typeof value === "boolean") {
592 return 4;
593 } else if (typeof value === "string") {
594 return value.length * 2;
595 } else if (typeof value === "number") {
596 return 8;
597 } else if (typeof value === "object" && objectList.indexOf(value) === -1) {
598 objectList[objectList.length] = value;
599
600 for (const i in value) {
601 bytes += 8; // an assumed existence overhead
602 bytes += recurse(value[i]);
603 }
604 }
605
606 return bytes;
607 }
608
609 return recurse(object);
610}
611
612export function capitaliseFirstLetter(text: string): string {
613 return text.replace(/(^\w|\s\w)/g, function (m: string) {

Callers 1

runDataAnalysisFunction · 0.90

Calls 1

recurseFunction · 0.85

Tested by

no test coverage detected