Skip to content

Tiny util to check for an item in a list, reading from left to right

Notifications You must be signed in to change notification settings

ModestosV/is-in

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-in

A tiny utility to check if a value is included in a list or multiple values, with support for array or flattened arguments.

This lets you check whether a value belongs to a collection by placing the item first, just like Python’s value in list syntax.


Usage

import { isIn } from 'is-in';

// Check using an array
console.log(isIn(3, [1, 2, 3])); // true

// Check using multiple arguments (flattened)
console.log(isIn('a', 'a', 'b', 'c')); // true

// With enums
enum Color {
  Red = 'red',
  Blue = 'blue',
  Green = 'green',
}

console.log(isIn(Color.Red, [Color.Red, Color.Green])); // true
console.log(isIn(Color.Blue, Color.Red, Color.Green)); // false

About

Tiny util to check for an item in a list, reading from left to right

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published