@iconify/tailwind
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -10,3 +10,3 @@ /** | ||
* @license MIT | ||
* @version 0.1.0 | ||
* @version 0.1.1 | ||
*/ | ||
@@ -312,15 +312,22 @@ 'use strict'; | ||
/** | ||
* Locate icon set | ||
*/ | ||
function locateIconSet(prefix, options) { | ||
if (options.files?.[prefix]) { | ||
return options.files?.[prefix]; | ||
return { | ||
main: options.files?.[prefix], | ||
}; | ||
} | ||
try { | ||
return require.resolve(`@iconify-json/${prefix}/icons.json`); | ||
const main = require.resolve(`@iconify-json/${prefix}/icons.json`); | ||
const info = require.resolve(`@iconify-json/${prefix}/info.json`); | ||
return { | ||
main, | ||
info, | ||
}; | ||
} | ||
catch { } | ||
try { | ||
return require.resolve(`@iconify/json/json/${prefix}.json`); | ||
const main = require.resolve(`@iconify/json/json/${prefix}.json`); | ||
return { | ||
main, | ||
}; | ||
} | ||
@@ -354,15 +361,21 @@ catch { } | ||
const filename = options.files?.[prefix] || locateIconSet(prefix, options); | ||
if (filename) { | ||
// Check for cache | ||
if (cache[filename]) { | ||
return cache[filename]; | ||
if (!filename) { | ||
return; | ||
} | ||
const main = typeof filename === 'string' ? filename : filename.main; | ||
// Check for cache | ||
if (cache[main]) { | ||
return cache[main]; | ||
} | ||
// Attempt to load it | ||
try { | ||
const result = JSON.parse(fs.readFileSync(main, 'utf8')); | ||
if (!result.info && typeof filename === 'object' && filename.info) { | ||
// Load info from a separate file | ||
result.info = JSON.parse(fs.readFileSync(filename.info, 'utf8')); | ||
} | ||
// Attempt to load it | ||
try { | ||
const result = JSON.parse(fs.readFileSync(filename, 'utf8')); | ||
cache[filename] = result; | ||
return result; | ||
} | ||
catch { } | ||
cache[main] = result; | ||
return result; | ||
} | ||
catch { } | ||
} | ||
@@ -472,3 +485,3 @@ | ||
const [prefix, name] = nameParts; | ||
if (!prefix.match(matchIconName) || !name.match(matchIconName)) { | ||
if (!(prefix.match(matchIconName) && name.match(matchIconName))) { | ||
throw new Error(`Invalid icon name: "${icon}"`); | ||
@@ -475,0 +488,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"author": "Vjacheslav Trushkin <cyberalien@gmail.com> (https://iconify.design)", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"license": "MIT", | ||
@@ -38,3 +38,3 @@ "main": "./dist/plugin.js", | ||
"typescript": "^4.9.4", | ||
"@iconify/utils": "^2.0.12" | ||
"@iconify/utils": "^2.1.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "scripts": { |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
25090
649
5