New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ssts/item

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ssts/item

Get a random item from an array.

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-92.31%
Maintainers
0
Weekly downloads
 
Created
Source

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 😍






Keywords

FAQs

Package last updated on 25 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc