1.0.8 • Published 6 years ago

@kingjs/descriptor.merge-wildcards v1.0.8

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

@kingjs/descriptor.merge-wildcards

If a descriptor contains a property named '*', then replace it with new properties with the same value but whose names are found on another descriptor but not on itself.

Usage

Promote Alice by two levels and everyone else by one like this:

var mergeWildcards = require('@kingjs/descriptor.merge-wildcards');

var people = {
  alice: { level: 0 },
  bob: { level: 1 },
  chris: { level: 2 }
}

var promotions = {
  alice: 2,
  '*': 1
}

var specificPromotions = mergeWildcards.call(
  promotions, people
);

for (var name in specificPromotions)
  people[name].level += specificPromotions[name];

result:

{
  alice: { level: 2 },
  bob: { level: 2 },
  chris: { level: 3 }
}

API

declare function mergeWildcards(
  this: Descriptor,
  other: Descriptor
): Descriptor

Interfaces

Parameters

  • this: The descriptor whose wildcard property * is expanded.
  • other: The descriptor whose names not present on this become the property names of the wildcard expansion.

Returns

Returns this with it's wildcard property * replaced with copies whose names are found on other but not on this.

Install

With npm installed, run

$ npm install @kingjs/descriptor.merge-wildcards

License

MIT

Analytics