alignmentFromString()

This function is part of Iconify Utils package.

Function alignmentFromString() applies align shorthand property to IconCustomisations object.

Usage

Function has the following parameters:

Function does not return anything, it applies changes to object passed in first parameter.

Value

Value can be set of the following strings, separated by space and/or comma:

  • "left", "center", "right" sets hAlign value.
  • "top", "middle", "bottom" sets vAlign value.
  • "slice" sets slice to true.
  • "meet" sets slice to false.

Example

demo.ts
import type { IconifyIconCustomisations } from '@iconify/utils/lib/customisations';
import { alignmentFromString } from '@iconify/utils/lib/customisations/shorthand';

let customisations: IconifyIconCustomisations;

customisations = {};
alignmentFromString(customisations, 'left');
// { hAlign: 'left' }
console.log(customisations);

customisations = {};
alignmentFromString(customisations, 'right,bottom');
// { hAlign: 'right', vAlign: 'bottom' }
console.log(customisations);

// Function does not toggle existing value, so this code does not change anything
customisations = { hAlign: 'center', slice: false };
alignmentFromString(customisations, 'center,meet');
console.log(customisations);