npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

talentcomposer

v2.0.12

Published

Composition tool using talents

Downloads

11

Readme

Build StatusCoverage StatusDependency status devDependency Status

NPM

talentcomposer

The talentcomposer is a tool which can compose pieces of capabilities (talents) with each other and also talents with an instance. This tool can help you to do role oriented programming. The implementation is based on the publication of the Software Composition Group part of the Institute of Computer Science (INF) at the University of Bern

##Supported engines

node v8 and v10

Notes

  1. The package mainliner utilizes this package.
  2. Conflict resolution between talents is explicit. The programmer has to resolve conflicts using either the alias or the exclude method. See below in the examples
  3. Conflict resolution between an instance and talents is implicit. The member will delegated on to the instance blindly. If there is already a member on the instance with same name it's gonna be shadowed or overridden.
  4. Although the publication allows stateful talents I would NOT not recommend to use them with this tool. Like DON'T do this (It's leaking anyway)
const Composer = require("talentcomposer");
let x = 0;

module.export = Composer.createTalent({
  method() {

    x += 1;

    return x;
  }
});

Examples

Composing an instance with talents

const assert = require("assert");
const Composer = require("talentcomposer");

class Person {
  constructor(name) {
    this.name = name;
  }
  eating() {}
  sleeping() {}
}

const studentTalent = Composer.createTalent({
  studying() {}
});

const teacherTalent = Composer.createTalent({
  teaching() {}
});

const sportTalent = Composer.createTalent({
  swimming() {}
});

let travis = new Person("Travis");
let mavis = new Person("Mavis");

travis = Composer.composeWithTalents(travis, studentTalent, sportTalent);
mavis = Composer.composeWithTalents(mavis, teacherTalent, sportTalent);

assert.ok(travis.studying);
assert.ok(travis.swimming);
assert.ok(mavis.teaching);
assert.ok(mavis.swimming);

Composing talents

const assert = require("assert");
const Composer = require("talentcomposer");

const circusTalent = Composer.createTalent({
  juggling() {},
  clowning() {}
});

const sportTalent = Composer.createTalent({
  running() {},
  swimming() {}
});

combinedTalents = Composer.composeTalents(circusTalent, sportTalent);

assert.ok(combinedTalents.juggling);
assert.deepEqual(combinedTalents.juggling, circusTalent.juggling);
assert.ok(combinedTalents.clowning);
assert.deepEqual(combinedTalents.clowning, circusTalent.clowning);
assert.ok(combinedTalents.running);
assert.deepEqual(combinedTalents.running, sportTalent.running);
assert.ok(combinedTalents.swimming);
assert.deepEqual(combinedTalents.swimming, sportTalent.swimming);

Require an unimplemented capability

const assert = require("assert");
const Composer = require("talentcomposer");

class Person {
  constructor(name) {
    this.name = name;
  }
  eating() {}
  sleeping() {}
}

const courierTalent = Composer.createTalent({
  "cycling": Composer.required,
  delivering() {
    this.cycling();
  }
});

const sportTalent = Composer.createTalent({
  cycling() {}
});

let travis = new Person("Travis");

travis = Composer.composeWithTalents(travis, courierTalent, sportTalent);

assert.ok(travis.cycling);
assert.deepEqual(travis.cycling, sportTalent.cycling);
assert.ok(travis.delivering);
assert.deepEqual(travis.delivering, courierTalent.delivering);

Require an unimplemented capability on the prototype of a class

const assert = require("assert");
const Composer = require("talentcomposer");

class Person {
  constructor(name) {
    this.name = name;
  }
  get drawing() {
    return Composer.required;
  }
  eating() {}
  sleeping() {}
}

const artTalent = Composer.createTalent({
  drawing() {}
});

let travis = new Person("Travis");

travis = Composer.composeWithTalents(travis, artTalent);

assert.ok(travis.drawing);
assert.deepEqual(travis.drawing, artTalent.drawing);

Require an unimplemented capability in the constructor of a class

const assert = require("assert");
const Composer = require("talentcomposer");

class Person {
  constructor(name) {
    this.name = name;
    this.painting = Composer.required;
  }
  eating() {}
  sleeping() {}
}

const artTalent = Composer.createTalent({
  painting() {}
});

let travis = new Person("Travis");

travis = Composer.composeWithTalents(travis, artTalent);

assert.ok(travis.painting);
assert.deepEqual(travis.painting, artTalent.painting);

Explicit conflict resolution (aliasing)

const assert = require("assert");
const Composer = require("talentcomposer");

const courierTalent = Composer.createTalent({
  cycling() {console.log("like a courier");}
});

const sportTalent = Composer.createTalent({
  cycling() {console.log("like an athlete");}
});

combinedTalents = Composer.composeTalents(
    courierTalent,
    Composer.alias(sportTalent, "cycling", "riding")
);

assert.ok(combinedTalents.cycling);
assert.deepEqual(combinedTalents.cycling, courierTalent.cycling);
assert.ok(combinedTalents.riding);
assert.deepEqual(combinedTalents.riding, sportTalent.cycling);

Explicit conflict resolution (excluding)

const assert = require("assert");
const Composer = require("talentcomposer");

const courierTalent = Composer.createTalent({
  cycling() {console.log("like a courier");},
  delivering() {}
});

const sportTalent = Composer.createTalent({
  cycling() {console.log("like a athlete");},
  swimming() {}
});

combinedTalents = Composer.composeTalents(
    courierTalent,
    Composer.exclude(sportTalent, "cycling")
);

assert.ok(combinedTalents.cycling);
assert.deepEqual(combinedTalents.cycling, courierTalent.cycling);
assert.ok(combinedTalents.cycling);
assert.deepEqual(combinedTalents.cycling, courierTalent.cycling);
assert.ok(combinedTalents.delivering);
assert.deepEqual(combinedTalents.delivering, courierTalent.delivering);

API

createTalent(record: Object): Talent

Creates a new talent

composeWithTalents(instance: Object, ...talents: Talent[]): Object

Composes talents with an instantiated object

composeTalents(...talents: Talent[]): Talent

Composes talents into one

alias(talent: Talent, methodName: string, alias: string): Talent

Aliases a method of the talent (It doesn't mutate the talent but returns a new one)

exclude(talent: Talent, methodName: string): Talent

Excludes a method of the talent (It doesn't mutate the talent but returns a new one)

required: Symbol

Property to mark required members for talents