Greasy Fork is available in English.

Enum

Enumeration class. Each enum propertiy has the properties "ordinal", "name" and "text".

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @require https://update.greasyfork.org/scripts/391854/746956/Enum.js

Autor
Gerrit
Verzia
0.3
Vytvorené
01.11.2019
Aktualizované
05.11.2019
Licencia
neuvedené

Usage

Object initialization

const COLORS = class COLOR extends Enum {}.init({ "RED": "red" , "GREEN": "green" , "BLUE": "blue" }); console.log(COLORS[0] === COLORS.RED); // "true" console.log(COLORS[1] === COLORS.GREEN); // "true" console.log(COLORS[2] === COLORS.BLUE); // "true" console.log(COLORS.GREEN.name); // "GREEN" console.log(COLORS.GREEN.text); // "green" console.assert(COLORS.GREEN.ordinal); // "1" console.assert(COLORS.GREEN + ""); // "green" console.assert(COLORS.GREEN * 1); // "1"

Array initialization

const COLORS = class COLOR extends Enum {}.init([ "RED", "GREEN", "BLUE" ]); console.log(COLORS[2].name) // "BLUE" console.log(COLORS[2].text); // "" console.log(COLORS[2].ordinal); // "2" console.log(COLORS[2] === COLORS.BLUE); // "true" console.log(COLORS.BLUE + ""); // "BLUE" console.log(COLORS.BLUE * 1); // "2"

Ordinal value generator

class FLAGS extends Enum {}; FLAGS.init([ "FIRST", "SECOND", "THIRD", "FOURTH" ], 1, ord => ord<<1); console.log(FLAGS.FOURTH | FLAGS.SECOND); // "10"