Novice Prime Minister

    flg

    2.0.1 • Public • Published

    FLG

    Build Status Coverage Status

    Flg is the simplest thing ever. You give it a string with "+" and "-" and flags in it, and it returns an object.

    Parse flag string

    A flag string is a string including +flag or -flag or just flag tokens, separated by spaces. They tell us what flags are to be turned on or turned off! You can use a flag string to define feature flags.

    var flags = flg('+foo -bar +baz')
    flags // -> { foo: true, bar: false, baz: true }

    It also does defaults.

    var defaults = { foo: false, bar: true }
    var flags = flg('+foo', defaults)
    flags // -> { foo: true, bar: true }

    The plus sign is implied. And spaces are optional.

    flg('foo') // -> { foo: true }
    flg('-foo+bar') // -> { foo: false, bar: true }

    Stringify flag string

    (see "parse flag string"'s first paragraph for an explanation on what a flag string is)

    You can also stringify an object into a flag string. The flags that come out are sorted alphabetically.

    flg.stringify({ foo: true }) // -> '+foo'

    And if you pass a defaults object, it will omit any values which are the same as the default.

    var defaults = { foo: false, bar: true }
    flg.stringify({ foo: false, baz: true }, defaults) // -> '+baz'

    And you can turn off spaces by doing this

    flg.stringify({ foo: true, baz: false }, {}, { spaces: false }) // -> '-baz +foo'

    Keywords

    none

    Install

    npm i flg

    DownloadsWeekly Downloads

    4

    Version

    2.0.1

    License

    WTFPL

    Unpacked Size

    3.58 kB

    Total Files

    3

    Last publish

    Collaborators

    • fabiosantoscode