random-enum-value-from-text

1.1.1 • Public • Published

random-enum-value-from-text

Pseudo-random index selection from an enum, ensuring the same value is always selected for a given text

Motivation

This was made to support picking a random display colour from a persons initials, but can be used for any purpose where a deterministic pseudo-random enum value is required

Installation

npm i random-enum-value-from-text

or

pnpm add random-enum-value-from-text

or

yarn add random-enum-value-from-text

Usage

import randomEnumValueFromText from "random-enum-value-from-text";

enum Example {
  One = "one",
  Two = "two",
  Three = "three",
  Four = "four",
}

randomEnumValueFromText("AA", ETest); // Example.Two
randomEnumValueFromText("AB", ETest); // Example.Three
randomEnumValueFromText("AC", ETest); // Example.Four
randomEnumValueFromText("AD", ETest); // Example.One

Licence

ISC

Author(s)

Readme

Keywords

none

Package Sidebar

Install

npm i random-enum-value-from-text

Weekly Downloads

27

Version

1.1.1

License

ISC

Unpacked Size

6.12 kB

Total Files

7

Last publish

Collaborators

  • macroman