Skip to content
Flatten object keys
CoffeeScript JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
README.md
index.js
package.json

README.md

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

Something went wrong with that request. Please try again.