Skip to content

ricardobeat/flatkeys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flatKeys

npm install flatkeys

Flatten object key hierarchies into a list of strings using a custom separator. Used in Konf to populate a config object from process.env variables.

Usage

flatKeys({
    zero: {
        one: 1,
        two: {
            three: 3
        }
    }
})

Returns the array

[
    'zero'
    'zero_one'
    'zero_two'
    'zero_two_three'
]

Options

flatKeys(keys, {
    sep    : '_'         // separator
    snake  : true        // convert keys from camelCase to snake_case
    filter : toLowerCase // transformation function, defaults to `String.prototype.toLowerCase`
})

Running the example above with { sep: ':', filter: String.prototype.toUpperCase } would yield

[
    'ZERO'
    'ZERO:ONE'
    'ZERO:TWO'
    'ZERO:TWO:THREE'
]

License

MIT

About

Flatten object keys

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published