Reference · Codes, URLs and SVG helpers
aspectOffunction
The aspect ratio of a flag, width over height, read from its SVG's viewBox: 1.5 for Japan's 2:3, 2 for Canada's 1:2, 1.9 for the United States' 10:19.
Import it
import { aspectOf } from "@johnmorrisdotca/hata";
Definition
function aspectOf(svg: string): number | null
Parameters
| Name | Type | Description |
|---|---|---|
svg | string | A flag's SVG string, from |
Returns
number | null
The width divided by the height, or null when the string is not an SVG with a viewBox.
Examples
import { aspectOf } from "@johnmorrisdotca/hata";
import japan from "@johnmorrisdotca/hata/flags/jp";
console.log(aspectOf(japan)); // 1.5
console.log(aspectOf("not an svg")); // null1.5
nullWhat it prints (run when this page was built)