Neighbor's Preppy Maltese

    @particle/make-enum

    3.0.2 • Public • Published

    @particle/make-enum

    Turn an array of values into an object that will throw an error when getting a non existing property to avoid typos in enum values

    Note: relies on Proxy which is a Javascript feature that cannot be polyfilled, so it's not safe to use in the browser.

    Installation

    npm install @particle/make-enum --save
    const makeEnum = require('@particle/make-enum');

    API

    @particle/make-enum


    module.exports(values) ⇒ Object

    Turn an array of values into an object that will throw an error when getting a non existing property to avoid typos in enum values

    Kind: Exported function
    Returns: Object - The extended array object where enum values can be accessed as properties

    Param Type Description
    values Array The array of string values for the enum

    Example

    const states = makeEnum(['new', 'in_progress']);
    // states.new === 'new'
    // states.inprogress throws

    NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests

    Keywords

    none

    Install

    npm i @particle/make-enum

    DownloadsWeekly Downloads

    316

    Version

    3.0.2

    License

    UNLICENSED

    Unpacked Size

    4.67 kB

    Total Files

    4

    Last publish

    Collaborators

    • amaury.particle
    • cole-abbeduto-particle
    • pedrosordo
    • rowan.hamilton
    • guohui
    • sbrust
    • busticated
    • particlebot
    • no1089
    • carlos.hdez
    • keeramis5
    • monkbroc
    • suda
    • mstan
    • sergeuz
    • debbie23
    • avtolstoy
    • mlauer
    • wraithan
    • toolboxbot
    • azenk
    • shewy
    • bwalach
    • parteberseth
    • rickkas7
    • mrlambchop_particle
    • hugo.montero
    • toddparticle
    • mphsi
    • zachary_russell_particle
    • davidbbe