本文へ移動

Hata旗

国や地域の旗を読み込み、対応する表示の形を選び、絵ごとの資料・作者・ライセンスを保てます。

「旗(はた)」は、旗を表す日本語です。 名前について(英語)

目次

リファレンス · コード・URL・SVGの道具

flagUrl関数

リファレンスの説明と例は英語です。見出しと目次は日本語です。

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 { flagUrl } from "@johnmorrisdotca/hata";

定義

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

引数

名前型説明
codestring

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

options (省略可)FlagUrlOptions

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

戻り値

string | null

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

例

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

出力(このページを作ったときに実行した結果)

ソースを見るGitHub で編集@johnmorrisdotca/hata 1.6.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。