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 · On-demand flag loading

flagDataUrifunction

A flag as a data: URI by its code, loaded when asked for: ready for an <img src> or a CSS url().

Import it

import { flagDataUri } from "@johnmorrisdotca/hata/load";

Definition

function flagDataUri(code: string, options?: FlagOptions): Promise<string | null>

Parameters

NameTypeDescription
codestring

A flag's code, in any case.

options (optional)FlagOptions | undefined

How to frame it first, as for frame(), and which variant; the flag as it is when left out.

Returns

Promise<string | null>

A promise of data:image/svg+xml,…, or of null when the code has no flag here.

Examples

import { flagDataUri } from "@johnmorrisdotca/hata/load";

const previewImage=document.createElement("img");
previewImage.src = (await flagDataUri("US-TX", { shape: "4:3" })) ?? "";

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