Skip to content

quicklyValidateIconSet()

This function is part of Iconify Utils package.

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

If there are errors in provided data, it will return null.

This function does not check metadata.

Usage

Function has the following parameter:

  • data, object. Data to validate.

Function returns:

  • IconifyJSON object on success (same as passed in first parameter).
  • null on error.

Example

usage.ts
tsimport { promises as fs } from 'fs';
import { quicklyValidateIconSet } from '@iconify/utils';

(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 = quicklyValidateIconSet(data);
   if (!iconSet) {
       console.error('Bad icon set');
       return;
   }

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

Advanced validation

This function is optimised for bundle size and performance, therefore it does only basic validation.

If you want to fully validate icon set, use validateIconSet() instead.

Released under the Apache 2.0 License.