FLG
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 = flags // -> { foo: true, bar: false, baz: true }
It also does defaults.
var defaults = foo: false bar: true var flags = flags // -> { foo: true, bar: true }
The plus sign is implied. And spaces are optional.
// -> { foo: true } // -> { 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 // -> '+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 // -> '+baz'
And you can turn off spaces by doing this
flg // -> '-baz +foo'