npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deck-suit

v0.1.9

Published

A reusable library for deck card components.

Downloads

659

Readme

Deck suits

deck-suit is a simple, customizable React library for rendering card components. The library provides a Card component to display standard playing cards and a BackCard component for displaying the back of cards. It is lightweight, styled using Tailwind CSS and JavaScript, and designed for flexibility.


Installation

Install the library via npm:

npm install deck-suit

Usage

Import the components into your project:

import { Card, BackCard } from 'deck-suit';

Components

1. Card

The Card component renders a customizable playing card with a specified suit, value, and height.

Props

| Prop | Type | Description | Default | |-----------|------------------------------------------------|--------------------------------------------|---------------| | suit | "Heart", "Diamond", "Club", "Spade", "Joker" | The suit of the card. | - | | value | 'A','2','3',....,'10','J','Q','K','JOOKER' | The value of the card. | - | | height | number | Height of the card in pixels. | 192 |

Example Usage

<Card suit="Heart" value="A" height={250} />
<Card suit="Joker" value="JOKER" height={290} />

2. BackCard

The BackCard component renders the back side of a playing card. It is useful for placeholders or representing a deck.

Props

| Prop | Type | Description | Default | |-----------|-----------|-------------------------------|-------------| | height | number | Height of the card in pixels. | 192 |

Example Usage

<BackCard height={300} />

Here's a detailed explanation of the TypeScript types provided by the library and their potential use cases:


Types

import { StandardCardType, JokerCardType, SuitTypeStandard, ValueTypeStandard, SuitTypeJoker, ValueTypeJoker, AllCardArrayType } from 'deck-suit';

1. StandardCardType

  • Definition: Represents a standard playing card with a suit (e.g., Spade, Heart) and a value (e.g., A, 2, K).
  • Properties:
    • suit: "Spade" | "Heart" | "Diamond" | "Club"
    • value: "A" | "2" | "3" | ... | "K"
    • height?: Optional property to define the card's height.

Use Case:

When you need to handle a standard card deck in your application, such as for a card game or a visualization of a deck, use StandardCardType to ensure consistent structure.

Example:

const standardCard: StandardCardType = {
  suit: "Spade",
  value: "A",
  height: 192, // Optional
};

2. JokerCardType

  • Definition: Represents a joker card, where both the suit and value are predefined as "Joker".
  • Properties:
    • suit: "Joker"
    • value: "JOKER"
    • height?: Optional property to define the card's height.

Use Case:

Use this type when handling joker cards separately from standard cards, such as for games where jokers are treated differently.

Example:

const jokerCard: JokerCardType = {
  suit: "Joker",
  value: "JOKER",
  height: 250, // Optional
};

3. SuitTypeStandard

  • Definition: A union type for all valid suits in a standard deck: "Spade" | "Heart" | "Diamond" | "Club".

Use Case:

Use SuitTypeStandard when you want to restrict inputs or values to valid card suits.

Example:

const cardSuit: SuitTypeStandard = "Heart"; // Valid
// const invalidSuit: SuitTypeStandard = "Star"; // Error: Not a valid suit

4. ValueTypeStandard

  • Definition: A union type for all valid values in a standard deck: "A" | "2" | ... | "K".

Use Case:

Use ValueTypeStandard to restrict inputs or validate that a card value is within the standard range.

Example:

const cardValue: ValueTypeStandard = "K"; // Valid
// const invalidValue: ValueTypeStandard = "11"; // Error: Not a valid card value

5. SuitTypeJoker

  • Definition: A fixed type representing the suit of a joker card: "Joker".

Use Case:

Use SuitTypeJoker to explicitly define that a card is a joker.

Example:

const jokerSuit: SuitTypeJoker = "Joker"; // Always valid

6. ValueTypeJoker

  • Definition: A fixed type representing the value of a joker card: "JOKER".

Use Case:

Use ValueTypeJoker to define the unique value of a joker card.

Example:

const jokerValue: ValueTypeJoker = "JOKER"; // Always valid

Styling Information

The components are styled using a mix of Tailwind CSS and JavaScript for optimal flexibility.

Notes:

  • Width: Automatically calculated based on a standard card aspect ratio.
  • _1 Variable: _1 is a scaling variable where:
    • _1 = 1px when height = 192.
    • Use _1 * 10 for 10px, _1 * 20 for 20px, etc.
    • Adjusts dynamically based on the specified height.

Contribution

Contributions are welcome! Feel free to submit issues or pull requests for improvements.

Installation

  1. Clone the repository:-
https://github.com/akash9m/deck-suit.git
  1. Install dependencies:
npm install

Development

Running the Project

To start the development server, run:

npm run dev

To Build the Project

To build the Project for production, run:

npm run build

Building the Library

to build the library for production, run:

npm run rollup

License

This project is licensed under the MIT License.