1.0.1 • Published 6 years ago

@kingjs/descriptor.update-each v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@kingjs/descriptor.update-each

Updates values of a descriptor using a callback.

Usage

Increment all descriptor values like this:

var updateEach = require('@kingjs/descriptor.update-each');

function callback(value, key) {
  return value + 1;
}

var descriptor = {
  foo: 0,
  bar: 1,
}

updateEach.call(descriptor, callback);

result:

{
  foo: 1,
  bar: 2
}

API

declare function updateEach(
  this: Descriptor,
  callback: (value, key: string) => any,
  copyOnWrite: boolean
): Descriptor

Interfaces

Parameters

  • this: The descriptor whose properties are to be mapped.
  • callback: A mapping function called for each property of this.
    • value: The value being mapped.
    • key: The name of the property being mapped.
  • copyOnWrite: If true, then a copy of this will be created on the first write and returned instead of this.

Returns

Returns this after mapping properties using the callback.

If this is frozen or copyOnWrite specified then a copy of this will be created on the first write and returned instead of this.

Install

With npm installed, run

$ npm install @kingjs/descriptor.update-each

License

MIT

Analytics