validateIcon()

This function is part of Iconify Utils package.

Function validateIcon() validates icon name.

Usage

Function has the following parameters:

  • name, IconifyIconName | null. Icon name.
  • allowSimpleName, boolean. Optional. If true, simple names without provider and prefix are considered valid.

Function returns boolean value.

Example

examples.ts
import { validateIcon } from '@iconify/utils/lib/icon/name';

// Valid names: function returns `true`
validateIcon({
   provider: '',
   prefix: 'mdi-light',
   name: 'home',
});

validateIcon({
   provider: 'my-api',
   prefix: 'awesome-test',
   name: 'alert-outline',
});

validateIcon(
   {
       provider: '',
       prefix: '',
       name: 'home',
   },
   true
);

// Invalid names: function returns `false`
validateIcon({
   provider: '',
   prefix: '', // Empty prefix
   name: 'home',
});

validateIcon({
   provider: '',
   prefix: 'my_set', // `_` is not allowed
   name: 'home',
});

validateIcon(
   {
       provider: 'my-api',
       prefix: '', // prefix cannot be empty if provider is set, even if second option is `true`
       name: 'home',
   },
   true
);