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
| Name | Type | Description |
|---|---|---|
code | string | A flag's code, in any case (as |
options (optional) | FlagUrlOptions |
|
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")); // nullhttps://cdn.jsdelivr.net/npm/@johnmorrisdotca/hata@1/dist/svg/jp-13.svg
/flags/us-tx.svg
nullWhat it prints (run when this page was built)