JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 225
  • Score
    100M100P100Q91374F
  • License MIT

Collection of methods to handle opening hours

Package Exports

  • @publidata/utils-fontawesome
  • @publidata/utils-fontawesome/dist/fontawesome.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@publidata/utils-fontawesome) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@publidata/utils-fontawesome

Description:

Provides utilities to work with fontawesome icons and retrieve them as SVG.

Installation:

npm install @publidata/utils-fontawesome

# or

yarn add @publidata/utils-fontawesome

Usage:

Retrieve a FA icon as SVG (native of from a kit) :

import { FontAwesomeUtils } from "@publidata/utils-fontawesome";

const icons = [
  "fas fa-home", // Native icon are retrieved from fontawesome npm package
  "far fa-home", // Regular icon are retrieved from fontawesome npm package
  "fa-home", // No prefix will not work
  "fak fa-[name]", // Custom icon are retrieved from fontawesome api
];

// Only if you use icons from a fontawesome kit
FontAwesomeUtils.setToken("YOUR_TOKEN");
FontAwesomeUtils.setKit("KIT_ID");

// To get a single icon
FontAwesomeUtils.toSvg("fas fa-ambulance").then(svg => {
  console.log(svg);
});

// To get multiple icons
FontAwesomeUtils.toSvgs(icons).then(svgs => {
  console.log(svgs);
});

The FontAwesomeApi class allows to communicate with the fontawesome api.

import { FontAwesomeApi } from "@publidata/utils-fontawesome";

const fontAwesomeApi = new FontAwesomeApi("YOUR_TOKEN"); // Mandatory to pass the token in the constructor

// Get all kits related to the account
fontAwesomeApi.kits().then(kits => {
  console.log(kits);
});
/* LOGS :
--------
  {
    me {
      kits [
        {
          id,
          name,
          token,
          version,
          licenseSelected,
          technologySelected
        },
        ...
      ]
    }
  }
*/

// Get one kit with all details
fontAwesomeApi.getKit("KIT_ID").then(kit => {
  console.log(kit);
});
/* LOGS :
--------
  {
    me: {
      kit: {
        name,
        token,
        version,
        licenseSelected,
        technologySelected,
        iconUploads:[
          {
            name,
            path,
            width,
            height,
            version,
            unicode
          },
          ...
        ]
      }
    }
*/

// Get all icons related uploded to the kit
fontAwesomeApi.kitIcons("KIT_ID").then(icons => {
  console.log(icons);
});
/* LOGS :
--------
  [
    {
      name,
      path,
      width,
      height,
      version,
      unicode
    }
  ]
*/

Use isValidFa to check if a string is a valid fontawesome icon.

import { isValidFa } from "@publidata/utils-fontawesome";

isValidFa("fas fa-home"); // true
isValidFa("far fa-home"); // true
isValidFa("fa-home"); // false
isValidFa("fak fa-[name]"); // true

See the test file for more examples : ./tests/4_validators.test.js

Use isFaKit to check if a string is a valid fontawesome kit.

import { isFaKit } from "@publidata/utils-fontawesome";

isFaKit("fas fa-home"); // false
isFaKit("far fa-home"); // false
isFaKit("fa-home"); // false
isFaKit("fak fa-[name]"); // true

See the test file for more examples : ./tests/4_validators.test.js