Skip to the content

Hata旗

Load a native country or region flag, choose supported framing and keep each drawing’s source, author and licence.

Hata (旗) is Japanese for a flag. About the name

Contents

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

NameTypeDescription
svgstring

A flag's SVG string, from /flags/<code> or flag().

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"));  // null
1.5
null

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/hata 1.6.0.