Socket
Socket
Sign inDemoInstall

@fortawesome/fontawesome-svg-core

Package Overview
Dependencies
1
Maintainers
7
Versions
76
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.1.2 to 6.2.0

index.mjs

2

attribution.js

@@ -1,4 +0,4 @@

console.log(`Font Awesome Free 6.1.2 by @fontawesome - https://fontawesome.com
console.log(`Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com
License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
Copyright 2022 Fonticons, Inc.
`)
import {
IconDefinition,
IconName,
IconStyle,
IconFamily
} from '@fortawesome/fontawesome-common-types';
export type IconMacroParams = {
name: IconName,
style?: IconStyle,
family?: IconFamily
};
export function brands(iconName: IconName): IconDefinition;

@@ -12,1 +20,2 @@ export function duotone(iconName: IconName): IconDefinition;

export function thin(iconName: IconName): IconDefinition;
export function icon(params: IconMacroParams): IconDefinition;

@@ -17,2 +17,13 @@ const { createMacro, MacroError } = require('babel-plugin-macros')

const macroNames = [
...styles,
'icon'
]
const families = [
'classic',
'duotone',
'sharp'
]
function importer ({references, state, babel, source, config}) {

@@ -29,4 +40,4 @@ const license = (config !== undefined ? config.license : 'free')

replace({
style: key,
license: (key === 'brands' ? 'free' : license),
macroName: key,
license,
references: references[key],

@@ -40,23 +51,39 @@ state,

function replace ({ style, license, references, state, babel, source }) {
function replace ({ macroName, license, references, state, babel, source }) {
references.forEach((nodePath) => {
if (canBeReplaced({ nodePath, babel, state, style })) {
const iconName = nodePath.parentPath.node.arguments[0].value
const name = `fa${capitalize(camelCase(iconName))}`
const importFrom = `@fortawesome/${license}-${style}-svg-icons/${name}`
const {iconName, style, family} = resolveReplacement({ nodePath, babel, state, macroName })
const importName = addNamed(nodePath, name, importFrom)
const name = `fa${capitalize(camelCase(iconName))}`
const importFrom = getImport({family, style, license, name})
nodePath.parentPath.replaceWith(importName)
}
const importName = addNamed(nodePath, name, importFrom)
nodePath.parentPath.replaceWith(importName)
})
}
function canBeReplaced ({ nodePath, babel, state, style }) {
function getImport ({family, style, license, name}) {
if (family) {
return `@fortawesome/${family.toLowerCase()}-${style}-svg-icons/${name}`
} else {
return `@fortawesome/${license}-${style}-svg-icons/${name}`
}
}
function resolveReplacement ({ nodePath, babel, state, macroName }) {
if('icon' === macroName) {
return resolveReplacementIcon({ nodePath, babel, state, macroName })
} else {
return resolveReplacementLegacyStyle({ nodePath, babel, state, macroName })
}
}
// The macros corresonding to legacy style names: solid(), regular(), light(), thin(), duotone(), brands().
function resolveReplacementLegacyStyle({ nodePath, babel, state, macroName }) {
const { types: t } = babel
const { parentPath } = nodePath
if (!styles.includes(style)) {
if (!styles.includes(macroName)) {
throw parentPath.buildCodeFrameError(
`${style} is not a valid style. Use one of ${styles.join(', ')}`,
`${macroName} is not a valid macro name. Use one of ${macroNames.join(', ')}`,
MacroError

@@ -67,5 +94,5 @@ )

if (parentPath.node.arguments) {
if (parentPath.node.arguments.length !== 1) {
if (parentPath.node.arguments.length < 1) {
throw parentPath.buildCodeFrameError(
`Received an invalid number of arguments (must be 1)`,
`Received an invalid number of arguments for ${macroName} macro: must be exactly 1`,
MacroError

@@ -75,4 +102,12 @@ )

if (parentPath.node.arguments.length > 1) {
throw parentPath.buildCodeFrameError(
`Received an invalid number of arguments for ${macroName} macro: must be exactly 1`,
MacroError
)
}
if (
parentPath.node.arguments.length === 1 &&
(parentPath.node.arguments.length === 1 ||
parentPath.node.arguments.length === 2) &&
t.isStringLiteral(parentPath.node.arguments[0]) &&

@@ -87,3 +122,5 @@ nodePath.parentPath.node.arguments[0].value.startsWith('fa-')

if (parentPath.node.arguments.length === 1 && !t.isStringLiteral(parentPath.node.arguments[0])) {
if ((parentPath.node.arguments.length === 1 ||
parentPath.node.arguments.length === 2) &&
!t.isStringLiteral(parentPath.node.arguments[0])) {
throw parentPath.buildCodeFrameError(

@@ -101,5 +138,145 @@ 'Only string literals are supported when referencing icons (use a string here instead)',

return true
return {
iconName: nodePath.parentPath.node.arguments[0].value,
style: macroName,
family: undefined
}
}
// The icon() macro.
function resolveReplacementIcon ({ nodePath, babel, state, macroName }) {
const { types: t } = babel
const { parentPath } = nodePath
if ('icon' !== macroName) {
throw parentPath.buildCodeFrameError(
`${macroName} is not a valid macro name. Use one of ${macroNames.join(', ')}`,
MacroError
)
}
if (parentPath.node.arguments.length !== 1) {
throw parentPath.buildCodeFrameError(
`Received an invalid number of arguments for ${macroName} macro: must be exactly 1`,
MacroError
)
}
if (!t.isObjectExpression(parentPath.node.arguments[0])) {
throw parentPath.buildCodeFrameError(
'Only object expressions are supported when referencing icons with this macro, like this: { name: \'star\' }',
MacroError
)
}
const properties = (parentPath.node.arguments[0].properties || [])
const namePropIndex = properties.findIndex((prop) => 'name' === prop.key.name)
const name = namePropIndex >= 0
? getStringLiteralPropertyValue(t, parentPath, parentPath.node.arguments[0].properties[namePropIndex])
: undefined
if(!name) {
throw parentPath.buildCodeFrameError(
'The object argument to the icon() macro must have a name property',
MacroError
)
}
const stylePropIndex = properties.findIndex((prop) => 'style' === prop.key.name)
let style = stylePropIndex >= 0
? getStringLiteralPropertyValue(t, parentPath, parentPath.node.arguments[0].properties[stylePropIndex])
: undefined
if(style && !styles.includes(style)) {
throw parentPath.buildCodeFrameError(
`Invalid style name: ${style}. It must be one of the following: ${styles.join(', ')}`,
MacroError
)
}
const familyPropIndex = properties.findIndex((prop) => 'family' === prop.key.name)
let family = familyPropIndex >= 0
? getStringLiteralPropertyValue(t, parentPath, parentPath.node.arguments[0].properties[familyPropIndex])
: undefined
if(family && !families.includes(family)) {
throw parentPath.buildCodeFrameError(
`Invalid family name: ${family}. It must be one of the following: ${families.join(', ')}`,
MacroError
)
}
if('duotone' === style && family && 'classic' !== family) {
throw parentPath.buildCodeFrameError(
`duotone cannot be used as a style name with any family other than classic`,
MacroError
)
}
if('brands' === style && family && 'classic' !== family) {
throw parentPath.buildCodeFrameError(
`brands cannot be used as a style name with any family other than classic`,
MacroError
)
}
if(family && !style) {
throw parentPath.buildCodeFrameError(
`When a family is specified, a style must also be specified`,
MacroError
)
}
if('duotone' === style || 'duotone' === family) {
family = undefined
style = 'duotone'
}
if('brands' === style) {
family = undefined
}
// defaults
if(!style) {
style = 'solid'
}
if('classic' === family) {
family = undefined
}
return {
iconName: name,
family,
style
}
}
function getStringLiteralPropertyValue(t, parentPath, property) {
if(!('object' === typeof t && 'function' === typeof t.isStringLiteral)) {
throw Error("ERROR: invalid babel-types arg. This is probably a programming error in import.macro")
}
if(!('object' === typeof property && 'object' === typeof property.value && 'object' == typeof property.key)) {
throw Error("ERROR: invalid babel property arg. This is probably a programming error in import.macro")
}
if(!('object' === typeof parentPath && 'function' === typeof parentPath.buildCodeFrameError)) {
throw Error("ERROR: invalid babel parentPath arg. This is probably a programming error in import.macro")
}
if(!t.isStringLiteral(property.value)) {
throw parentPath.buildCodeFrameError(
`Only string literals are supported for the ${property.key.name} property (use a string here instead)`,
MacroError
)
}
return property.value.value
}
function capitalize (str) {

@@ -106,0 +283,0 @@ return str[0].toUpperCase() + str.slice(1)

@@ -1,3 +0,3 @@

import {IconDefinition, IconLookup, IconName, IconPrefix, IconPathData, IconPack } from '@fortawesome/fontawesome-common-types';
export {IconDefinition, IconLookup, IconName, IconPrefix, IconPathData, IconPack } from '@fortawesome/fontawesome-common-types';
import {IconDefinition, IconLookup, IconName, IconFamily, IconPrefix, CssStyleClass, IconStyle, IconPathData, IconPack} from '@fortawesome/fontawesome-common-types';
export {IconDefinition, IconLookup, IconName, IconFamily, IconPrefix, CssStyleClass, IconStyle, IconPathData, IconPack} from '@fortawesome/fontawesome-common-types';
export const dom: DOM;

@@ -23,5 +23,8 @@ export const library: Library;

export type SizeProp =
| "2xs"
| "xs"
| "sm"
| "lg"
| "sm"
| "xl"
| "2xl"
| "1x"

@@ -41,3 +44,6 @@ | "2x"

export interface Config {
familyPrefix: IconPrefix;
familyPrefix: string;
cssPrefix: string;
styleDefault: IconPrefix | CssStyleClass | IconStyle;
familyDefault: IconFamily;
replacementClass: string;

@@ -44,0 +50,0 @@ autoReplaceSvg: boolean | 'nest';

@@ -24,9 +24,9 @@ {

"dependencies": {
"@fortawesome/fontawesome-common-types": "6.1.2"
"@fortawesome/fontawesome-common-types": "6.2.0"
},
"version": "6.1.2",
"version": "6.2.0",
"name": "@fortawesome/fontawesome-svg-core",
"main": "index.js",
"module": "index.es.js",
"jsnext:main": "index.es.js",
"module": "index.mjs",
"jsnext:main": "index.mjs",
"style": "styles.css",

@@ -37,4 +37,4 @@ "license": "MIT",

".": {
"module": "./index.es.js",
"import": "./index.es.js",
"module": "./index.mjs",
"import": "./index.mjs",
"require": "./index.js",

@@ -45,4 +45,4 @@ "style": "./styles.css",

"./index": {
"module": "./index.es.js",
"import": "./index.es.js",
"module": "./index.mjs",
"import": "./index.mjs",
"require": "./index.js",

@@ -52,4 +52,4 @@ "default": "./index.js"

"./index.js": {
"module": "./index.es.js",
"import": "./index.es.js",
"module": "./index.mjs",
"import": "./index.mjs",
"require": "./index.js",

@@ -59,5 +59,5 @@ "default": "./index.js"

"./plugins": {
"module": "./plugins.es.js",
"import": "./plugins.es.js",
"default": "./plugins.es.js"
"module": "./plugins.mjs",
"import": "./plugins.mjs",
"default": "./plugins.mjs"
},

@@ -72,3 +72,3 @@ "./import.macro": "./import.macro.js",

"./index.js",
"./index.es.js",
"./index.mjs",
"./styles.css"

@@ -75,0 +75,0 @@ ],

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc