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

toDataUrifunction

A flag's SVG as a data: URI, ready for an <img src>, a CSS background-image: url(…) or a canvas. Only the characters that must be escaped are, so it stays readable and close to the SVG's own size (smaller than base64).

Import it

import { toDataUri } from "@johnmorrisdotca/hata";

Definition

function toDataUri(svg: string): string | null

Parameters

NameTypeDescription
svgstring

A flag's SVG string, framed or not.

Returns

string | null

data:image/svg+xml,…, or null when the string is not an SVG.

Examples

import { toDataUri } from "@johnmorrisdotca/hata";
import japan from "@johnmorrisdotca/hata/flags/jp";

const img = document.createElement("img");
img.src = toDataUri(japan) ?? "";
img.alt = "Japan";
console.log(img);

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