Gets Nerd Fonts glyph icons via a CSS class name or a file path with an extension.
- Nerd Fonts version:
3.4.0. - No dependencies.
- Built-in TypeScript declarations.
- Convert a Nerd Fonts CSS class to an icon: 10 764 icons.
- Convert a file path into a colored icon using the Seti preset or a custom callback.
npm i @m234/nerd-fontsImport:
import * as nf from "@m234/nerd-fonts";Using icons:
const icon = nf.icons['nf-md-weather_lightning']
console.log(`Weather: ${icon.value}`);
// >> Weather: Using iconsMap:
const icon = nf.iconsMap.get('nf-md-weather_lightning')
console.log(`Weather: ${icon.value}`);
// >> Weather: Using fromPath preset:
const file = 'example/index.js';
const ficon = nf.fromPath(file, 'seti');
console.log(`Icon ${ficon.value} for ${file}`);
// >> Icon for example/index.jsUsing fromPath custom:
const file = 'example/index.js';
const ficon = nf.fromPath(file, (base) => {
if (base.endsWith('/'))
return icons['nf-seti-folder']
return nf.fromPath(base, 'seti')
});
console.log(`Icon ${ficon.value} for ${file}`);
// >> Icon for example/index.jsUsing chalk:
import chalk from "chalk";
const file = 'example/index.js';
const ficon = nf.fromPath(file, 'seti');
const colorize = chalk.hex(ficon.color)
console.log(`Icon ${colorize(ficon.value)} for ${file}`);
// >> Icon for example/index.jsUsing %c:
const file = 'example/index.js';
const ficon = nf.fromPath(file, 'seti');
console.log(`Icon %c${ficon.value} for ${file}`, `color: ${ficon.color}`);
// >> Icon for example/index.js