../public/snippets/typescript.ts
TypeScript is a superset of JavaScript that adds static types, improving code quality and maintainability.
With over three years of experience using TypeScript, I have a solid understanding of its type system and advanced features.
I have utilized TypeScript to build scalable applications, enhancing developer productivity and minimizing runtime errors.
// @ts-nocheck
function colorizeCode(): void {
const element = document.getElementsByTagName('code')[0];
if (element == null) {
return;
}
const text = element.innerText;
const language = element.classList[0];
const keywords = {
js: javascriptKeywords,
ts: typescriptKeywords,
html: htmlKeywords,
css: cssKeywords,
gql: graphqlKeywords,
sql: sqlKeywords,
jsx: reactKeywords,
yml: yamlKeywords,
}[language];
if (keywords == null) {
return;
}
let coloredText = text;
keywords.forEach((subKeywords: string[], i: number) => {
const regex = new RegExp(`\\b(${subKeywords.join('|')})\\b`, 'g');
coloredText = coloredText.replaceAll(
regex,
(match: string) => `<span class="${COLORS[i]}">${match}</span>`
);
});
element.innerHTML = coloredText;
}
async function getCodeSnippet(snippet: string): Promise<string> {
const response = await fetch(`../data/snippets/snippet.${snippet}`);
const text = await response.text();
return text;
}