https://github.com/borvelt/object-maker
Create object with dotted string
https://github.com/borvelt/object-maker
create dotted generate object string
Last synced: 26 days ago
JSON representation
Create object with dotted string
- Host: GitHub
- URL: https://github.com/borvelt/object-maker
- Owner: borvelt
- License: mit
- Created: 2018-10-06T08:25:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-24T14:08:35.000Z (over 7 years ago)
- Last Synced: 2025-05-09T07:03:53.732Z (about 1 year ago)
- Topics: create, dotted, generate, object, string
- Language: JavaScript
- Homepage:
- Size: 332 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# object-maker
_create object with string and map string to object_
## Installation
```bash
$ npm install --save object-maker
```
## Usage
##### Create Object
If you want to generate deep complex object dynamically, you should use this library
```javascript
import objectMaker from 'object-maker'
import merge from 'lodash.merge'
const info1 = objectMaker('package.author.email', 'borvelt@gmail.com')
const info2 = objectMaker('package.author.gitRepo', 'https://github.com/borvelt')
merge(info1, info2)
// merged object
// Object{
// package: {
// author: {
// email: "borvelt@gmail.com",
// gitRepo: "https://github.com/borvelt",
// }
// }
// }
```
#### Map string to object
When you have a deep complex object and you need to access the deepest part
it's good solution to make string and get equivalent of mapped string to
object. see this example:
```javascript
import {mapStringToObject} from 'object-maker'
const info = {
package: {
author: {
email: "borvelt@gmail.com",
gitRepo: "https://github.com/borvelt",
}
}
}
console.log(mapStringToObject('package.author.gitRepo', info))
// -> https://github.com/borvelt
```
Careful `mapStringToObject` works case-sensitive.
## Test
run `npm test` it will pass all test cases.
## license
MIT