https://github.com/ricardobeat/flatkeys
Flatten object keys
https://github.com/ricardobeat/flatkeys
Last synced: about 1 year ago
JSON representation
Flatten object keys
- Host: GitHub
- URL: https://github.com/ricardobeat/flatkeys
- Owner: ricardobeat
- Created: 2013-07-11T03:02:11.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-07-11T03:42:30.000Z (almost 13 years ago)
- Last Synced: 2025-03-26T18:51:53.584Z (about 1 year ago)
- Language: CoffeeScript
- Size: 109 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-micro-npm-packages-zh - flatkeys - 使用自定义分隔符,将对象键层次结构变为字符串列表. (模块 / 对象)
- fucking-awesome-micro-npm-packages - flatkeys - Flatten object key hierarchies into a list of strings using a custom separator. (Modules / Object)
- awesome-micro-npm-packages - flatkeys - Flatten object key hierarchies into a list of strings using a custom separator. (Modules / Object)
- awesome-micro-npm-packages - flatkeys - Flatten object key hierarchies into a list of strings using a custom separator. (Modules / Object)
README
flatKeys
=========
npm install flatkeys
Flatten object key hierarchies into a list of strings using a custom separator. Used in [Konf](http://github.com/ricardobeat/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](http://ricardo.mit-license.org)