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

flagUrlfunction

The address of a flag's SVG file, for an <img src> or a CSS url(): on the jsDelivr CDN by default, or in a folder of your own. The file is the same SVG as the module's string.

Import it

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

Definition

function flagUrl(code: string, options?: FlagUrlOptions): string | null

Parameters

NameTypeDescription
codestring

A flag's code, in any case (as flagCode reads it).

options (optional)FlagUrlOptions

base, the folder holding the <code>.svg files; the CDN when left out.

Returns

string | null

The address (…/jp-13.svg), or null when the code has no flag here.

Examples

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

console.log(flagUrl("JP-13"));                      // "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/hata@1/dist/svg/jp-13.svg"
console.log(flagUrl("us-tx", { base: "/flags/" })); // "/flags/us-tx.svg"
console.log(flagUrl("XX"));                          // null
https://cdn.jsdelivr.net/npm/@johnmorrisdotca/hata@1/dist/svg/jp-13.svg
/flags/us-tx.svg
null

What it prints (run when this page was built)

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