本文へ移動

Fuda Cards札

画像やライブ3Dを入れるコレクション用のカード枠です。本物の厚み、縁、箔、山、傷み、バインダーを、2つのWebコンポーネントで使えます。

「札(ふだ)」は、カードや札を指す日本語です。 名前について(英語)

目次

リファレンス · コレクションと山:計算部分

randomDrawIndex関数

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

Choose a card whose name contains the filter, avoiding the current card when another match exists.

インポート

import { randomDrawIndex } from "@johnmorrisdotca/fuda-cards/collection";

定義

function randomDrawIndex(cards: CollectionCard[], current: number, filter: string, random?: () => number): number | null

引数

名前型説明
cardsCollectionCard[]

The collection.

currentnumber

The index of the card now on top.

filterstring

Text the name must contain, whatever its case; spaces round it are ignored. Empty matches every card.

random (省略可)() => number

A source of numbers from 0 up to but not including 1. Unless said, Math.random.

戻り値

number | null

The index of the card to draw, or null when no card matches.

例

import { randomDrawIndex } from "@johnmorrisdotca/fuda-cards/collection";

const cards = ["Alpha", "Beta", "Gamma"].map((name, i) => ({ id: String(i), name, image: `${i}.jpg` }));
console.log(randomDrawIndex(cards, 0, "", () => 0)); // 1
console.log(randomDrawIndex(cards, 0, "zzz")); // null
1
null

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

ソースを見るGitHub で編集@johnmorrisdotca/fuda-cards 0.11.0 のソースから作成しました。

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