Skip to content
Adam Smith edited this page Mar 1, 2016 · 11 revisions

vitals.amend npm version

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

amend

A shortcut for Object.defineProperties that includes easier value assignment, strong type assignment, and more flexible default descriptor options.

Examples

Params

  1. obj !Object
  2. 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):
    - `", "`
    - `","`
    - `"|"`
    - `" "`
  1. 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.
  1. descriptor !Object=
default value: ` { writable: true, enumerable: true, configurable: true } `

 The default descriptor values for each prop.
  1. 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;
};
```
  1. 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

amend.config

A shortcut for Object.defineProperties that only updates the descriptors of existing properties.

Examples

Params

  1. obj !Object
  2. 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):
    - `", "`
    - `","`
    - `"|"`
    - `" "`
  1. descriptor !Object=
Only use (and required) if an array or string of keys is given for the props param.

Returns !Object

amend.property

A shortcut for Object.defineProperty.

Examples

Params

  1. obj !Object
  2. key string
  3. val *=
A val is required if a descriptor is not supplied.
  1. descriptor !Object=
default value: ` { writable: true, enumerable: true, configurable: true } `
  1. 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;
};
```
  1. 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

amend.property.config

A shortcut for Object.defineProperty that only updates the descriptor of an existing property.

Examples

Params

  1. obj !Object
  2. key string
  3. descriptor !Object

Returns !Object

amend.properties

A shortcut for Object.defineProperties that includes easier value assignment, strong type assignment, and more flexible default descriptor options.

Examples

Params

  1. obj !Object
  2. 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):
    - `", "`
    - `","`
    - `"|"`
    - `" "`
  1. 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.
  1. descriptor !Object=
default value: ` { writable: true, enumerable: true, configurable: true } `

 The default descriptor values for each prop.
  1. 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;
};
```
  1. 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

amend.properties.config

A shortcut for Object.defineProperties that only updates the descriptors of existing properties.

Examples

Params

  1. obj !Object
  2. 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):
    - `", "`
    - `","`
    - `"|"`
    - `" "`
  1. descriptor !Object=
Only use (and required) if an array or string of keys is given for the props param.

Returns !Object

-- Happy Developing,

Algorithm IV Logo

Clone this wiki locally