Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pbojinov/recursive-key-replace
🔑 Recursively replace object keys
https://github.com/pbojinov/recursive-key-replace
Last synced: 5 days ago
JSON representation
🔑 Recursively replace object keys
- Host: GitHub
- URL: https://github.com/pbojinov/recursive-key-replace
- Owner: pbojinov
- License: mit
- Created: 2017-08-19T01:45:56.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-19T02:35:53.000Z (about 7 years ago)
- Last Synced: 2024-10-12T03:09:04.937Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# recursive-key-replace
> 🔑 Recursively replace object keys
## Install
```
$ npm install --save recursive-key-replace
```## Usage
```js
const recursiveKeyReplace = require('recursive-key-replace');
const obj = {
"cats.are.cool": true,
"dogs": {
"are.too": true
}
};recursiveKeyReplace(obj, /\./g, '');
//=> {"catsarecool": true, "dogs": {"aretoo": true}}```
## API
### recursiveKeyReplace(input, search, replace)
Returns a new object.
#### input
*Required*
Type: `object`The object which keys will be replaced.
#### search
*Required*
Type: `string` or `RegExp`Search for matching substring that will be replaced.
#### replaceValue
*Required*
Type: `string`Replace the matching substring with this value.
## But why? 🤔
Because Elasticsearch doesn't like dots in field names...
https://www.elastic.co/guide/en/elasticsearch/reference/2.4/dots-in-names.html
## License
MIT © [Petar Bojinov](http://github.com/pbojinov)