getSVGViewBox() and SVGViewBox type
This function is part of Iconify Utils package.
Function getSVGViewBox() is a helper function that parses viewBox attribute value.
Result is represented by SVGViewBox type, used in various functions in Iconify Utils.
Usage
The function has the following parameter:
- value, string. Attribute value.
Function returns SVGViewBox with parsed viewBox value or undefined on error.
Function validates numbers to make sure values are valid numbers and there are exactly 4 numbers. On failure, it will return undefined.
SVGViewBox type
Type SVGViewBox is an array of four numbers:
- x (or left)
- y (or top)
- width
- height
Example
usage.ts
ts
import { getSVGViewBox } from '@iconify/utils';
const viewBox = getSVGViewBox('0 0 24 24');
console.log(viewBox);
Result:
json
[0, 0, 24, 24]
Convert to string
To get viewBox attribute as a string from SVGViewBox, use join function:
js
const value = viewBox.join(' ');