UNPKG

@publidata/utils-fontawesome

Version:
34 lines (30 loc) 919 B
const prefixes = require("../jsons/prefixes.json"); /** * Checks if the fa is a kit * @param {string} fa - The fa to check example: "fak fa-tshirt" * @returns {boolean} */ const isFaKit = (fa) => { // Should match "fak" and "fa-kit" const regex = new RegExp(/\b(^fa-?k(it)?)\b/i); return regex.test(fa); }; /** * Checks if the fa is valid, by checking the prefix and the fa name * @param {string} fa - The fa to check example: "fas fa-tshirt" * @returns */ const isValidFa = (fa) => { // Prefixes should be in the prefixes.json file const prefix = fa.split(" ")[0]; const isValidPrefix = Object.keys(prefixes).includes(prefix); // should macth the pattern "[prefix] fa-*" const faName = fa.split(" ")[1]; const regex = new RegExp(/^fa-([a-z]|[0-9]){1,}/g); const isValidFaName = regex.test(faName); return isValidPrefix && isValidFaName; }; module.exports = { isFaKit, isValidFa };