Change Content - Javascript
Change html element content using pure javascript author(s): Deepu Mohan Puthrote (WarFox)
by BrankoSabo
HTML
<div id="myelement">Old Text</div>
JavaScript
function jsonToTypeScriptInterface(json, interfaceName = 'MyInterface') {
let interfaceStr = `interface ${interfaceName} {\n`;
for (const key in json) {
if (json.hasOwnProperty(key)) {
const valueType = typeof json[key];
switch (valueType) {
case 'string':
case 'number':
case 'boolean':
interfaceStr += ` ${key}: ${valueType};\n`;
break;
case 'object':
if (Array.isArray(json[key])) {
interfaceStr += ` ${key}: any[];\n`; // simplistic handling for arrays
} else if (json[key] === null) {
interfaceStr += ` ${key}: any;\n`; // null handling
} else {
// Recursive call for nested objects
const nestedInterfaceName = `${key.charAt(0).toUpperCase() + key.slice(1)}Interface`;
interfaceStr += ` ${key}: ${nestedInterfaceName};\n`;
interfaceStr += jsonToTypeScriptInterface(json[key], nestedInterfaceName);
}
break;
default:
interfaceStr += ` ${key}: any;\n`;
}
}
}
interfaceStr += '}\n';
return interfaceStr;
}
// Example usage
const exampleJson = {
"SecId": "F00000PWB1",
"Isin": "NO0010676083",
"Name": "Fondsfinans Kreditt",
"FundName": "Fondsfinans Kreditt",
"ActualFrontLoad": null,
"ActualManagementFee": null,
"ManagementFee": 0.35,
"ActuallDeferLoad": null,
"ClosePrice": 11482.6996,
"ClosePriceDate": "2024-04-08",
"Currency": "NOK",
"Eet_EUSFDRType": 6,
"GlobalAssetClassId": "$BCG$FXINC",
"GlobalAssetClassName": "Fixed Income",
"HistoricalSustainabilityScore": null,
"InceptionDate": "2013-04-30",
"InvestmentStrategy": null,
"IsUCITS": true,
"Kid_sri": 3,
"LegalName": "Fondsfinans...