Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyxla/object-extract
Extract object key-value pairs as variables to a specified context.
https://github.com/tyxla/object-extract
Last synced: about 1 month ago
JSON representation
Extract object key-value pairs as variables to a specified context.
- Host: GitHub
- URL: https://github.com/tyxla/object-extract
- Owner: tyxla
- License: mit
- Created: 2015-11-30T23:17:59.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-30T23:47:59.000Z (about 9 years ago)
- Last Synced: 2024-10-31T14:43:23.766Z (2 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# object-extract
Extract object key-value pairs as variables to a specified context.
```
npm install object-extract
```[![Build Status](https://travis-ci.org/tyxla/object-extract.svg)](https://travis-ci.org/tyxla/object-extract)
## About
This will assign each property of the specified object as a variable in the specified context.
When assigning, the property key is used for the variable name, and the property value is used for the variable value.
## Syntax
``` js
objectExtract(objectToExtract, context);
```#### objectToExtract
This is the object that you wish to extract to the specified context.
#### context
This is the context you wish to extract the object to. If not specified, variables will be assigned to the global scope.
## Usage
Pass the object you want to extract, and the context object you want it to get extracted to.
``` js
var obj = {
test: 123
};objectExtract({
example: 456
}, obj);console.log(obj);
/*
{
test: 123,
example: 456
}
*/```
In case you want to extract the object in the global scope, omit the `context` parameter.
``` js
objectExtract({
example: 456
});console.log(example);
/*
456
*/
```## License
MIT