validateIconSet()

This function is part of Iconify Utils package.

Function validateIconSet() validates icon set, returning cleaned up IconifyJSON object.

If there are errors in provided data:

  • If error is critical, function will throw an exception.
  • If error can be fixed, function will throw an exception, unless fix option is provided.

Usage

Function has the following parameters:

  • data, object. Data to validate.
  • options, object. Optional options object.

Options

Options object has the following properties:

  • fix, boolean. If set to true, function will attempt to fix errors whenver possible instead of throwing exception. Default value is false.
  • prefix, string. Default value for prefix property of icon set. If set, function will overwrite prefix in icon set with your value.
  • provider, string. Default value for provider property of icon set. If set, function will overwrite provider in icon set with your value.

Example

usage.ts
import { promises as fs } from 'fs';
import { validateIconSet } from '@iconify/utils/lib/icon-set/validate';

(async () => {
   // Load data from file
   const data = JSON.parse(
       await fs.readFile(
           './node_modules/@iconify-json/mdi-light/icons.json',
           'utf8'
       )
   );

   // Validate data
   const iconSet = validateIconSet(data);

   // Count icons (simple calculation)
   const count =
       Object.keys(iconSet).length +
       (iconSet.aliases ? Object.keys(iconSet.aliases).length : 0);
   console.log(`Found ${count} icons`);
})();