Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abdizriel/setter.js
The Promise based set object parameters for the modern browsers and node.
https://github.com/abdizriel/setter.js
Last synced: 15 days ago
JSON representation
The Promise based set object parameters for the modern browsers and node.
- Host: GitHub
- URL: https://github.com/abdizriel/setter.js
- Owner: Abdizriel
- Created: 2016-05-20T14:50:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-05-25T15:06:32.000Z (over 8 years ago)
- Last Synced: 2024-12-09T23:30:50.417Z (about 1 month ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[![version](https://img.shields.io/npm/v/setter.js.svg?label=version)](https://www.npmjs.org/package/setter.js) [![Build Status](https://img.shields.io/travis/Abdizriel/setter.js.svg?branch=master)](https://travis-ci.org/Abdizriel/setter.js/) [![Coverage](https://img.shields.io/coveralls/Abdizriel/setter.js.svg)](https://coveralls.io/github/Abdizriel/setter.js)
# Setter.js
The Promise based set object parameters for the modern browsers and node.## Installation
```js
$ npm install --save setter.js
```## Before
```jsvar dataObj = {
test: 'testString',
test2: 'testString2',
setTest: newValue => {
const self = this;
self.test = newValue;
return new Promise(resolve => resolve(self));
},
setTest2: () => {
const self = this;
self.test2 = newValue;
return new Promise(resolve => resolve(self));
}
}dataObj
.setTest('updatedString')
.then(response => console.log(response));```
## After
```js
import setter from 'setter.js'let dataObj = {
test: 'testString',
test2: 'testString2'
};
dataObj = setter(dataObj);await dataObj.setTest('updatedString');
let config = {
async: false,
multiple: false
};
dataObj = setter(dataObj, config);
const testValue = dataObj.set('test', 'updatedString');```
## API
### setter({Object} Object, {Object} [Config])
Object - provided argument where you want to add set functions.
Config - provided configuration object for additional options
Config.async - default true - setter functions returns Promise
Config.multiple - default true - if true you would add to object x setKey functions if false you would get only set('key', value) function