Skip to content

Repository files navigation

@m234/nerd-fonts

jsDocs.io npm version npm downloads github github issues

Gets Nerd Fonts glyph icons via a CSS class name or a file path with an extension.

Features

  • Nerd Fonts version: 3.5.0.
  • No dependencies.
  • Built-in TypeScript declarations.
  • Convert a Nerd Fonts CSS class to an icon: 10 995 icons.
  • Convert a file path into a colored icon using the Seti preset or a custom callback.

Install

npm i @m234/nerd-fonts

Usage

Import:

import * as nf from "@m234/nerd-fonts";

Get by class name

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: 󰖓

Get by file path

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.js

Using 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.js

Using 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.js

Using %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

See also

About

Gets Nerd Fonts glyph icons via a CSS class name or a file path with an extension.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages