Hi. If able, visit this css file that is nerd webfoont icons, and create a JS script that i coud run in my JS console, to get that file, and output a JSON, with all icon names, and unicode codepoint entry. THe simplest structure is fine, a simple iterative array of all icons names and glyphs.
It appear that this file is not provided in their source code, its very convoluted, with icons names in all 4 corners. So i just need an index.
I've analyzed the CSS file you provided, and indeed, it's not straightforward to extract the icon names and Unicode codepoints. But don't worry, I've got you covered.
Here's a JavaScript script that you can run in your browser's console (e.g., Chrome DevTools, Firefox Developer Edition) to fetch the CSS file, parse it, and output a JSON array with the icon names and Unicode codepoints:
javascript
// Function to fetch CSS file and extract icon data
async function extractNerdFontIcons() {
const cssUrl = 'https://www.nerdfonts.com/assets/css/webfont.css';
const response = await fetch(cssUrl);
const cssText = await response.text();
// Regular expression to match icon rules (e.g., `.nf-icon-name:before { content: "\f000"; }`)
const iconRegex = /\.nf-([a-zA-Z0-9-]+):before\s*\{\s*content:\s*"\\([a-fA-F0-9]{4})";\s*\}/g;
// Initialize result array
const icons = [];
// Iterate over all matches
let match;
while ((match = iconRegex.exec(cssText)) !== null) {
// Extract icon name and Unicode codepoint
const iconName = match[1];
const codepoint = `U+${match[2].toUpperCase()}`;
// Add to result array
icons.push({ name: iconName, codepoint });
}
// Output JSON result
console.log(JSON.stringify(icons, null, 2));
}
// Run the function
extractNerdFontIcons();
Let me explain what this script does:
Fetch the CSS file: We use the fetch API to retrieve the CSS file from the provided URL.
Parse the CSS text: We use a regular expression (iconRegex) to match the icon rules in the CSS file. Each rule has the format .nf-icon-name:before { content: "\fXXXX"; }, where icon-name is the icon name and XXXX is the Unicode codepoint in hexadecimal.
Extract icon data: We iterate over all matches using exec() and extract the icon name (match[1]) and Unicode codepoint (match[2]). We convert the codepoint to the standard U+XXXX format.
Build the result array: We push each icon object ({ name, codepoint }) to the icons array.
Output JSON result: Finally, we log the icons array as a JSON string with indentation (using JSON.stringify()).
How to run it:
Open your browser's console (e.g., Chrome: F12 or Ctrl+Shift+J; Firefox: F12 or Ctrl+Shift+K).
Copy the script above and paste it into the console.
Press Enter to execute the script.
After a brief moment (depending on your internet connection), you'll see a JSON array with all the Nerd Font icon names and Unicode codepoints printed in the console. The output will look like this:
You can now copy this JSON output and use it as your index of Nerd Font icons!
Notes:
This script assumes the CSS file structure remains the same. If the Nerd Fonts team changes the CSS file format, the regular expression might need adjustments.
The output array contains all icons, including those from Font Awesome, Material Design, and other sets included in Nerd Fonts.
If you want to filter the icons by a specific set (e.g., only Font Awesome), you'll need to modify the script accordingly.
Happy coding, and enjoy your shiny new Nerd Font icon index!