Neurotic and Probably Misinformed

    enumish

    1.0.2 • Public • Published

    Enumish

    Version Build Status

    Easily create Enum-like objects.

    Installation

    npm install enumish --save

    Usage

    Basic

    Import the library and invoke it with a list of strings (for mirrored values):

    import enums from 'enumish';
     
    // basic usage
    const Directions = enums('TOP', 'LEFT', 'RIGHT', 'BOTTOM', 'CENTER');
     
    // result
    Directions.TOP === 'TOP'; // true

    Custom values

    Some of the arguments can be objects, for custom values:

    // custom values
    const SideBarComponents = enums('ICON_PICKER', {
        LAYOUT_SELECTOR:    'LayoutSelector',
        COLOR_PICKER:       'ColorPickerSection'
    });
     
    // result
    SideBarComponents.ICON_PICKER === 'ICON_PICKER'; // true
    SideBarComponents.LAYOUT_SELECTOR === 'LayoutSelector'; // true

    Converter function

    You can supply the keys as an array, and a converter function for the second argument:

    // custom converter function as the second argument
    const Icons = enums(['BOLD', 'ITALIC'], val => val.toLowerCase());
     
    // result
    Icons.BOLD === 'bold'; // true

    Further usage can be found in the tests.

    Test

    npm run test

    Configuration

    Built using Library Starter Light.

    License

    MIT

    Install

    npm i enumish

    DownloadsWeekly Downloads

    805

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • liady