0.0.6 • Published 1 year ago

@ssts/item v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Get a random item from an array

One straight forward function that returns a random item from an array 😍

Install

npm i @ssts/item

Import

import seniorITEM from "@ssts/item";

Use

const randomItem = seniorITEM(["Item 1", "Item 2", "Item 3"]);

Arguments

Returns a random item from an array or undefined if the array is empty

OrderParameterTypeDefault
1arrayany[]required

Examples

import seniorITEM from "@ssts/item";

const snacks = ["Peanuts", "Chips", "Candy", "Chocolate", "Popcorn", "Cookies", "Donuts", "Ice cream", "Yogurt", "Brownies", "Cupcakes", "Gummies", "Muffins", "Your favorite drink lol"] as const;

const randomSnack = seniorITEM(snacks);
console.log(randomSnack);                   // 'Chips'

type Snacks = (typeof snacks)[number];
// It's okay With/Without a generic
console.log(seniorITEM(snacks));            // 'Cookies'
console.log(seniorITEM<Snacks>(snacks));    // 'Candy'

type Item = {
  key: string;
  name: string;
  imgSrc: string;
};
type Items = Item[];
const items: Items = [/* ... */];

console.log(seniorITEM([]));                // undefined
console.log(seniorITEM(items));             // { key: "17", name: "Item 17", imgSrc: "https://picsum.photos/200" }
console.log(seniorITEM<Item>(items));       // { key: "5", name: "Item 5", imgSrc: "https://picsum.photos/200" }





Made With Chocolate By Senior Sedo 😎

Be Chocolateful 💙😍

ssts stands for senior-sedo-typescript 💙

So instead of @senior-sedo-typescript/rand-item

@ssts/item for simplicity sake 😍






0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago