Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/binocarlos/etcd-flatten
Flatten the results of a recursive etcd query into a flat object with keys and values
https://github.com/binocarlos/etcd-flatten
Last synced: 10 days ago
JSON representation
Flatten the results of a recursive etcd query into a flat object with keys and values
- Host: GitHub
- URL: https://github.com/binocarlos/etcd-flatten
- Owner: binocarlos
- License: mit
- Created: 2014-05-05T11:54:44.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-05-05T22:11:50.000Z (over 10 years ago)
- Last Synced: 2024-10-06T13:16:23.041Z (about 1 month ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
etcd-flatten
============[![Travis](http://img.shields.io/travis/binocarlos/etcd-flatten.svg?style=flat)](https://travis-ci.org/binocarlos/etcd-flatten)
Flatten the results of a recursive etcd query into a flat object with keys and values
## installation
```
$ npm install etcd-flatten
```## usage
Imagine we have some deeply nested keys in etcd:
```bash
$ etcdctl ls --recursive
``````
/shapes
/shapes/circle
/shapes/circle/red
/shapes/circle/green
/shapes/square
/shapes/square/red
```We can do a recursive query and get a tree like structure
etcd-flatten will take this tree structure and return a flat object with paths mapped to values and no directories included
```js
var etcdjs = require('etcdjs')
var flatten = require('etcd-flatten')var etcd = etcdjs('127.0.0.1:4001')
etcd.get('/shapes', {
recursive:true
}, function(err, results){if(!err && results.node){
var leafs = flatten(results.node)
console.dir(leafs)
}
})/*
{
'/shapes/circle/red':'CIRCLE RED',
'/shapes/circle/green':'CIRCLE GREEN',
'/shapes/square/red':'SQUARE RED'
}
*/
```## api
### `var flatObject = flatten(etcdResults)`
Pass the top-level node from an etcd query.
A flat object containing all leafs by their path is returned.
## license
MIT