Utilities Helper methods for component metadata tool API Reference
Categories

Utilities

Utility methods for accessing component metadata and formatting descriptions.

getTagName()

Returns the HTML tag name for the component.

Syntax

reader.getTagName(options)

Parameters

NameTypeDefaultDescription
pluralbooleanthis.pluralReturn plural tag name
langstring’html’Output language

Returns

String containing the tag name.

Usage

import { SpecReader } from '@semantic-ui/specs';
import buttonSpec from './button.spec.js';
const reader = new SpecReader(buttonSpec);
console.log(reader.getTagName()); // 'ui-button'
const pluralReader = new SpecReader(buttonSpec, { plural: true });
console.log(pluralReader.getTagName()); // 'ui-buttons'

getComponentName()

Returns the JavaScript export name for the component.

Syntax

reader.getComponentName(options)

Parameters

NameTypeDefaultDescription
pluralbooleanthis.pluralReturn plural export name
langstring’html’Output language

Returns

String containing the export name.

Usage

import { SpecReader } from '@semantic-ui/specs';
import buttonSpec from './button.spec.js';
const reader = new SpecReader(buttonSpec);
console.log(reader.getComponentName()); // 'UIButton'
const pluralReader = new SpecReader(buttonSpec, { plural: true });
console.log(pluralReader.getComponentName()); // 'UIButtons'

formatDescription()

Formats a description with the proper article and component name. Automatically prepends “A button can” or “An icon can” based on the component name.

Syntax

reader.formatDescription(description, options)

Parameters

NameTypeDefaultDescription
descriptionstringDescription text to format
pluralbooleanthis.pluralUse plural component name

Returns

String with formatted description.

Usage

import { SpecReader } from '@semantic-ui/specs';
import buttonSpec from './button.spec.js';
const reader = new SpecReader(buttonSpec);
console.log(reader.formatDescription('be emphasized'));
// 'A button can be emphasized.'
const iconReader = new SpecReader(iconSpec);
console.log(iconReader.formatDescription('indicate status'));
// 'An icon can indicate status.'
Previous
Generating HTML
Next
Template Helpers