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 · Flags by their colours

coloursOffunction

A flag's colours, the one that covers most of it first: each an exact hex as the drawing has it, the share of the flag it covers and its name. Measured from the flag's own drawing, never from a frame or a crop (manifest(code).colours is the same list).

Import it

import { coloursOf } from "@johnmorrisdotca/hata/search";

Definition

function coloursOf(code: string, options?: { variant?: string; }): readonly FlagColour[]

Parameters

NameTypeDescription
codestring

A flag's code in any case: "JP", "jp-13", "CA_ON"; a former country by its code or one of its aliases.

options (optional){ variant?: string; } | undefined

variant: the id of another of the place's flags (variantsOf(code)), such as Afghanistan's "de-facto".

Returns

readonly FlagColour[]

The colours, frozen; an empty list when the code has no flag here, or no such variant.

Examples

import { coloursOf } from "@johnmorrisdotca/hata/search";

console.log(coloursOf("JP"));                          // [{ hex: "#ffffff", share: 0.8116, name: "white" }, { hex: "#bc002d", share: 0.1884, name: "red" }]
console.log(coloursOf("FR").map((one) => one.name));   // ["blue", "red", "white"]
console.log(coloursOf("AF", { variant: "de-facto" })); // the Taliban's flag: white and black
console.log(coloursOf("XX"));                          // []
[
  { hex: '#ffffff', share: 0.8116, name: 'white' },
  { hex: '#bc002d', share: 0.1884, name: 'red' }
]
[ 'blue', 'red', 'white' ]
[
  { hex: '#ffffff', share: 0.8952, name: 'white' },
  { hex: '#000000', share: 0.1048, name: 'black' }
]
[]

What it prints (run when this page was built)

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