Skip to content

Instantly share code, notes, and snippets.

@aleqsio
Created September 9, 2025 13:40
Show Gist options
  • Select an option

  • Save aleqsio/63a2f378286c727780ef6056d66d8e43 to your computer and use it in GitHub Desktop.

Select an option

Save aleqsio/63a2f378286c727780ef6056d66d8e43 to your computer and use it in GitHub Desktop.
// Import the filesystem module
import * as fs from 'fs';
// Interface to describe the symbol structure
interface Symbol {
name: string;
codepoint: number;
}
// The function to read, transform, and save the data
function convertSymbolsFile(inputFilePath: string, outputFilePath: string): void {
// Read the input file
fs.readFile(inputFilePath, 'utf-8', (err, data) => {
if (err) {
console.error("Failed to read file:", err);
return;
}
// Parse the JSON data
const symbols: Symbol[] = JSON.parse(data);
// Transform into the desired object format
const result: { [key: string]: number } = {};
symbols.forEach(symbol => {
result[symbol.name] = symbol.codepoint;
});
// Convert the result object back to a JSON string
const outputJson = JSON.stringify(result, null, 4);
// Write the transformed data to the output file
fs.writeFile(outputFilePath, outputJson, 'utf-8', (writeErr) => {
if (writeErr) {
console.error("Failed to write file:", writeErr);
return;
}
console.log("File has been converted and saved successfully.");
});
});
}
// Execute the function
convertSymbolsFile('./symbolsFromGF.json', './symbols.json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment