-
-
Notifications
You must be signed in to change notification settings - Fork 0
4. Recipes
This example shows how to handle card reversals in a tarot deck without needing to create separate cards like "The Fool Reversed". Instead, we'll keep each card with a single name (e.g., "The Fool") and store both upright and reversed meanings. When performing a reading, we’ll select the appropriate meaning based on whether the card is drawn upright or reversed.
-
Import Tarot.js Import the
Tarot.jslibrary:import Tarot from "https://esm.sh/gh/MarketingPipeline/Tarot.js";
-
Initialize Tarot and Custom Deck Initialize a Tarot instance and define your custom tarot deck. Each card will include both upright and reversed meanings inside a
meaningsobject. The card itself will retain its name, so you don't need separate cards for reversed versions like"The Fool Reversed".const tarot = new Tarot(); const your_own_custom_deck = tarot.initializeDeck([ { name: "The Fool", meanings: { upright: "New beginnings, innocence", reversed: "Recklessness, naivety" } }, { name: "The Coder", meanings: { upright: "Tired, broke, curious", reversed: "Burnout, blocked creativity, frustration" } }, { name: "The Magician", meanings: { upright: "Skill, resourcefulness, power", reversed: "Manipulation, deceit, illusion" } }, { name: "The High Priestess", meanings: { upright: "Wisdom, intuition, mystery", reversed: "Secrets, disconnection from intuition" } } ]);
- Each card in your custom deck includes the
meaningsproperty with bothuprightandreverseddefinitions.
- Each card in your custom deck includes the
-
Create and Add a Custom Spread Create your own tarot spread, specifying the positions and their associated meanings. This example uses a simple "Shakespeare" spread with two positions: "To be" and "Not to be."
tarot.addSpread("shakespeare", { positions: ["To be", "Not to be"], description: "Random example spread" });
-
Assigning Reversals Define a function to assign the
reversedproperty to each card in your deck. In this case, we use a 50% chance to randomly assignreversed: true.function assignReversals(deck) { // Add a `reversed` property to each card return deck.map(card => { const isReversed = Math.random() > 0.5; // 50% chance to reverse the card return { ...card.card, // Copy the card object reversed: isReversed // Add `reversed` property }; }); }
- This function will randomly reverse cards. Each card will retain its
nameandmeanings, but we add thereversedproperty to indicate if the card is reversed.
- This function will randomly reverse cards. Each card will retain its
-
Performing a Reading with Reversals Use the
tarot.doReading()method to draw a spread (e.g., "shakespeare"). Then, apply theassignReversals()function to add thereversedstate to the cards.// Perform the "shakespeare" spread and add reversals const deckWithReversals = assignReversals(tarot.doReading("shakespeare")); console.log(deckWithReversals);
Example Output: After running the reading, each card will include the
reversedstate along with its upright or reversed meaning:[ { name: "The Fool", meanings: { upright: "New beginnings, innocence", reversed: "Recklessness, naivety" }, reversed: true }, { name: "The Coder", meanings: { upright: "Tired, broke, curious", reversed: "Burnout, blocked creativity, frustration" }, reversed: false }, { name: "The Magician", meanings: { upright: "Skill, resourcefulness, power", reversed: "Manipulation, deceit, illusion" }, reversed: true }, { name: "The High Priestess", meanings: { upright: "Wisdom, intuition, mystery", reversed: "Secrets, disconnection from intuition" }, reversed: false } ]
-
Selecting the Meaning Based on Reversal When performing a reading, check the
reversedproperty to select either theuprightorreversedmeaning for each card. This allows you to interpret the card according to its orientation in the spread.
- Custom Deck: You define cards with both upright and reversed meanings.
-
Reversals: Use a function to assign a
reversedproperty to each card. - Reading: Select meanings dynamically based on whether the card is drawn in an upright or reversed position.
- Immutability: The original deck remains unchanged, and reversals are added on the fly during readings.
import Tarot from "https://esm.sh/gh/MarketingPipeline/Tarot.js";
// Initialize a Tarot instance
const tarot = new Tarot();
// Initialize your custom deck with meanings for both upright and reversed
const your_own_custom_deck = tarot.initializeDeck([
{
name: "The Fool",
meanings: {
upright: "New beginnings, innocence",
reversed: "Recklessness, naivety"
}
},
{
name: "The Coder",
meanings: {
upright: "Tired, broke, curious",
reversed: "Burnout, blocked creativity, frustration"
}
},
{
name: "The Magician",
meanings: {
upright: "Skill, resourcefulness, power",
reversed: "Manipulation, deceit, illusion"
}
},
{
name: "The High Priestess",
meanings: {
upright: "Wisdom, intuition, mystery",
reversed: "Secrets, disconnection from intuition"
}
}
]);
// Add your custom spread
tarot.addSpread("shakespeare", {
positions: ["To be", "Not to be"],
description: "Random example spread"
});
// Function to assign reversals
function assignReversals(deck) {
return deck.map(card => {
const isReversed = Math.random() > 0.5; // 50% chance to reverse the card
return {
...card.card, // Copy the card object
reversed: isReversed // Add `reversed` property
};
});
}
// Add reversals to reading
const deckWithReversals = assignReversals(tarot.doReading("shakespeare"));
// Log the result with reversals
console.log(deckWithReversals);