Reference
Codes, URLs and SVG helpers
import { … } from "@johnmorrisdotca/hata";
3.5 kB minified and gzipped, with everything it imports (measured with esbuild)
Exports
| Name | Kind | What it is |
|---|---|---|
aspectOf | function | 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. |
Fit | type | How a flag sits in a frame of another shape. |
FLAG_CODES | constant | Every code with a flag in this version, in order: the countries by ISO 3166-1 alpha-2 code ("AD" to "ZW", and "XK" for Kosovo), then the first-level subdivisions of 10 countries by ISO 3166-2 code ("AT-1", "AU-NSW", "CA-AB", "DE-BY", "JP-01", "US-AK"). |
flagCode | function | The code of a flag, from a code written loosely: either case, with spaces around it, and an underscore for the hyphen ("jp", " Jp-13 ", "us_tx"). |
FlagCode | type | A code with a flag, as Kuni writes it: "JP", "JP-13", "CA-ON", "US-TX". |
flagUrl | function | 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. |
FlagUrlOptions | type | Where flagUrl finds the SVG files: a folder holding <code>.svg. |
frame | function | A flag framed in another shape without stretching it: at its own aspect ratio, at 4:3, square, or in a circle. |
FrameOptions | type | How to frame a flag: its shape, how it fits, and a label for assistive technology. |
isFlagCode | function | True for one of the codes with a flag, written exactly as Kuni writes it: "JP", "JP-13", "CA-ON", "US-TX". |
Shape | type | The shapes a flag can be framed in. |
toDataUri | function | A flag's SVG as a data: URI, ready for an <img src>, a CSS background-image: url(…) or a canvas. |
VERSION | constant | The package's version, the same as package.json's. |