Skip to the content

Fuda Cards札

Collectible card frames for images and live 3D: a true thickness, an edge, foil, stacks, wear and a binder, as two web components.

Fuda is the Japanese word 札 for a card or a tag. About the name

Contents

Reference · Collections and piles: pure helpers

randomDrawIndexfunction

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

Import it

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

Definition

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

Parameters

NameTypeDescription
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 (optional)() => number

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

Returns

number | null

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

Examples

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

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/fuda-cards 0.11.0.