toDataUri関数
リファレンスの説明と例は英語です。見出しと目次は日本語です。
A flag's SVG as a data: URI, ready for an <img src>, a CSS background-image: url(…) or a canvas. Only
the characters that must be escaped are, so it stays readable and close to the SVG's own size (smaller than
base64).
インポート
import { toDataUri } from "@johnmorrisdotca/hata";
定義
function toDataUri(svg: string): string | null
引数
| 名前 | 型 | 説明 |
|---|---|---|
svg | string | A flag's SVG string, framed or not. |
戻り値
string | null
data:image/svg+xml,…, or null when the string is not an SVG.
例
import { toDataUri } from "@johnmorrisdotca/hata";
import japan from "@johnmorrisdotca/hata/flags/jp";
const img = document.createElement("img");
img.src = toDataUri(japan) ?? "";
img.alt = "Japan";
console.log(img);この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。