-
Notifications
You must be signed in to change notification settings - Fork 1
vitals.amend
Method | Section | Alias |
---|---|---|
amend | strict | |
amend.config | strict | |
amend.property | strict | amend.prop |
amend.property.config | strict | amend.prop.config |
amend.properties | strict | amend.props |
amend.properties.config | strict | amend.props.config |
A shortcut for Object.defineProperties that includes easier value assignment, strong type assignment, and more flexible default descriptor options.
Params
-
obj
!Object
-
props
!(Object<string, *>|Array<string>|string)
The details for the props param are as follows (per props type):
- object: Must be `propName => propVal` or `propName => propDescriptor`.
- array: An array of key names to define.
- string: Converted to an array of key names using one of the following values as the separator (values listed in order of rank):
- `", "`
- `","`
- `"|"`
- `" "`
-
val
*=
Only use (and required) if an array or string of keys is given for the props param. This param defines the value assigned for all keys regardless of descriptor type.
-
descriptor
!Object=
default value: ` { writable: true, enumerable: true, configurable: true } `
The default descriptor values for each prop.
-
strongType
string=
If defined all new properties are assigned an accessor descriptor (unless assigned a data descriptor in the props param) that includes a setter (unless assigned a setter in the props param) that throws an error if the new property value fails a [vitals.is](https://github.com/imaginate/vitals/wiki/vitals.is) type test. The setter is as follows:
```javascript
prop.set = function set(newVal) {
if ( !vitals.is(strongType, newVal) ) throw new TypeError("...");
value = newVal;
};
```
-
setter
function(*, *): *=
If defined all new properties are assigned an accessor descriptor (unless assigned a data descriptor in the props param) that includes a setter (unless assigned a setter in the props param) that sets the property to the value returned by this setter. Note that this setter function will receive two params, the new value and the current value. Also note that if the strongType param is defined this setter will not get called until the new value passes the type test.
```javascript
prop.set = function set(newVal) {
if ( !vitals.is(strongType, newVal) ) throw new TypeError("...");
value = setter(newVal, value);
};
```
Returns !Object
A shortcut for Object.defineProperties that only updates the descriptors of existing properties.
Params
-
obj
!Object
-
props
!(Object<string, !Object>|Array<string>|string)
Details for the props param are as follows (per props type):
- object: Must be `propName => propDescriptor` pairs.
- array: An array of key names to update.
- string: Converted to an array of key names using one of the following values as the separator (values listed in order of rank):
- `", "`
- `","`
- `"|"`
- `" "`
-
descriptor
!Object=
Only use (and required) if an array or string of keys is given for the props param.
Returns !Object
A shortcut for Object.defineProperty.
Params
-
obj
!Object
-
key
string
-
val
*=
A val is required if a descriptor is not supplied.
-
descriptor
!Object=
default value: ` { writable: true, enumerable: true, configurable: true } `
-
strongType
string=
If defined the new property is assigned an accessor descriptor that includes a setter that throws an error if the new property value fails a [vitals.is](https://github.com/imaginate/vitals/wiki/vitals.is) type test. The setter is as follows:
```javascript
prop.set = function set(newVal) {
if ( !vitals.is(strongType, newVal) ) throw new TypeError("...");
value = newVal;
};
```
-
setter
function(*, *): *=
If defined the new property is assigned an accessor descriptor that includes a setter that sets the property to the value returned by this setter method. The setter method will receive two params, the new value and the current value. If a strongType is defined this setter will not get called until the new value passes the type test.
```javascript
prop.set = function set(newVal) {
if ( !vitals.is(strongType, newVal) ) throw new TypeError("...");
value = setter(newVal, value);
};
```
Returns !Object
A shortcut for Object.defineProperty that only updates the descriptor of an existing property.
Params
-
obj
!Object
-
key
string
-
descriptor
!Object
Returns !Object
A shortcut for Object.defineProperties that includes easier value assignment, strong type assignment, and more flexible default descriptor options.
Params
-
obj
!Object
-
props
!(Object<string, *>|Array<string>|string)
The details for the props param are as follows (per props type):
- object: Must be `propName => propVal` or `propName => propDescriptor`.
- array: An array of key names to define.
- string: Converted to an array of key names using one of the following values as the separator (values listed in order of rank):
- `", "`
- `","`
- `"|"`
- `" "`
-
val
*=
Only use (and required) if an array or string of keys is given for the props param. This param defines the value assigned for all keys regardless of descriptor type.
-
descriptor
!Object=
default value: ` { writable: true, enumerable: true, configurable: true } `
The default descriptor values for each prop.
-
strongType
string=
If defined all new properties are assigned an accessor descriptor (unless assigned a data descriptor in the props param) that includes a setter (unless assigned a setter in the props param) that throws an error if the new property value fails a [vitals.is](https://github.com/imaginate/vitals/wiki/vitals.is) type test. The setter is as follows:
```javascript
prop.set = function set(newVal) {
if ( !vitals.is(strongType, newVal) ) throw new TypeError("...");
value = newVal;
};
```
-
setter
function(*, *): *=
If defined all new properties are assigned an accessor descriptor (unless assigned a data descriptor in the props param) that includes a setter (unless assigned a setter in the props param) that sets the property to the value returned by this setter. Note that this setter function will receive two params, the new value and the current value. Also note that if the strongType param is defined this setter will not get called until the new value passes the type test.
```javascript
prop.set = function set(newVal) {
if ( !vitals.is(strongType, newVal) ) throw new TypeError("...");
value = setter(newVal, value);
};
```
Returns !Object
A shortcut for Object.defineProperties that only updates the descriptors of existing properties.
Params
-
obj
!Object
-
props
!(Object<string, !Object>|Array<string>|string)
Details for the props param are as follows (per props type):
- object: Must be `propName => propDescriptor` pairs.
- array: An array of key names to update.
- string: Converted to an array of key names using one of the following values as the separator (values listed in order of rank):
- `", "`
- `","`
- `"|"`
- `" "`
-
descriptor
!Object=
Only use (and required) if an array or string of keys is given for the props param.
Returns !Object
-- Happy Developing,