@iconify/utils
Advanced tools
Comparing version 1.0.15 to 1.0.16
@@ -5,10 +5,2 @@ import type { IconifyAlias, IconifyJSON } from '@iconify/types'; | ||
/** | ||
* What to track when parsing icon set: | ||
* | ||
* none - do not track anything, return true on success | ||
* valid - track valid icons, return list of valid icons on success | ||
* all - track valid and missing icons, return full list on success | ||
*/ | ||
export declare type ParseIconSetTracking = 'none' | 'valid' | 'all'; | ||
/** | ||
* Which aliases to parse: | ||
@@ -33,3 +25,2 @@ * | ||
validate?: boolean | IconSetValidationOptions; | ||
list?: ParseIconSetTracking; | ||
aliases?: ParseIconSetAliases; | ||
@@ -39,3 +30,5 @@ } | ||
* Extract icons from an icon set | ||
* | ||
* Returns list of icons that were found in icon set | ||
*/ | ||
export declare function parseIconSet(data: IconifyJSON, callback: SplitIconSetCallback, options?: ParseIconSetOptions): boolean | string[]; | ||
export declare function parseIconSet(data: IconifyJSON, callback: SplitIconSetCallback, options?: ParseIconSetOptions): string[]; |
@@ -21,9 +21,14 @@ "use strict"; | ||
* Extract icons from an icon set | ||
* | ||
* Returns list of icons that were found in icon set | ||
*/ | ||
function parseIconSet(data, callback, options) { | ||
options = options || {}; | ||
// List of icon names | ||
const names = []; | ||
// Options | ||
options = options || {}; | ||
const list = options.list || 'none'; | ||
// Must be an object and must have 'icons' property | ||
if (typeof data !== 'object' || typeof data.icons !== 'object') { | ||
return names; | ||
} | ||
// Validate icon set | ||
const validate = options.validate; | ||
@@ -36,9 +41,5 @@ if (validate !== false) { | ||
catch (err) { | ||
return list === 'none' ? false : []; | ||
return names; | ||
} | ||
} | ||
// Must be an object | ||
if (typeof data !== 'object') { | ||
return list === 'none' ? false : names; | ||
} | ||
// Check for missing icons list returned by API | ||
@@ -48,11 +49,5 @@ if (data.not_found instanceof Array) { | ||
callback(name, null); | ||
if (list === 'all') { | ||
names.push(name); | ||
} | ||
names.push(name); | ||
}); | ||
} | ||
// Must have 'icons' object | ||
if (typeof data.icons !== 'object') { | ||
return list === 'none' ? false : names; | ||
} | ||
// Get icons | ||
@@ -84,4 +79,4 @@ const icons = data.icons; | ||
} | ||
return list === 'none' ? names.length > 0 : names; | ||
return names; | ||
} | ||
exports.parseIconSet = parseIconSet; |
@@ -5,3 +5,3 @@ { | ||
"author": "Vjacheslav Trushkin", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "bugs": "https://github.com/iconify/iconify/issues", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
121711
4070