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

@specialblend/superclass

v0.0.6

Published

ES6 class mixin (multi class "inheritance") utility - easily extend ES6 classes from multiple classes

Downloads

2

Readme

superclass

ES6 class mixin (multi class "inheritance") utility - easily extend ES6 classes from multiple classes

install

npm i @specialblend/superclass

quickstart

import superclass from '@specialblend/superclass'

class Foo {
    getTestValue() {
        return 'test from Foo'
    }
    getFooValue() {
        return 'hello from Foo'
    }
}

class Bar {
    getTestValue() {
        return 'test from Bar'
    }
    getBarValue() {
        return 'hello from Bar'
    }
}

class Baz {
     getTestValue() {
        return 'test from Bar'
    }
    getBarValue() {
        return 'hello from Bar'
    }
    getBazValue() {
        return 'hello from Baz'
    }
}

// Extend Foo and mixin properties and methods from Bar, Baz, Faz
// Precedence for accessing properties and methods is left to right:
// SpecialFoo, Foo, Bar, ... etc
class SpecialFoo extends superclass(Foo, Bar, Baz) {
    constructor(props) {
        super(props)
    }
    getTestValue() {
        return 'test from SpecialFoo'
    }
}

const specialFoo = new SpecialFoo
specialFoo.getTestValue() // 'test from SpecialFoo'
specialFoo.getFooValue() // 'hello from Foo'
specialFoo.getBarValue() // 'hello from Bar'
specialFoo.getBazValue() // 'hello from Baz'

methods

superclass

/**
 * create a defaultExport from a parent class and provided sister classes
 * @param {Class} base: the base class to extend
 * @param {Array<Class>} supertypes: the sister classes
 * @returns {Class}: the created defaultExport
 */
export const superclass = (base, ...supertypes) => {}

example: superclass

import SomeLogger from '@example/some-logger'
import superclass from '@specialblend/superclass'
import { EventEmitter } from 'events'

class Logger extends SomeLogger {
    info(message) {
        console.log(message);
    }
    error(message) {
        console.error(message);
    }
}

class EmitterLogger extends superclass(Logger, EventEmitter) {
    info(message) {
        super.info(message);
        this.emit('info', message);
    }
    error(message) {
        super.error(message);
        this.emit('error', message);
    }
}

const myEmitterLogger = new EmitterLogger

myEmitterLogger.on('error', message => {
    // message: they say it dont be like it is, but it do!
})

myEmitterLogger.error('they say it dont be like it is, but it do!')

myEmitterLogger instanceof Logger // true

mixin

/**
 * create a subclass of provided base class whose constructor
 * will receive arguments transformed by provided transformer function
 * @param {Class} base: the base class to extend
 * @param {Function} transform: the transformer function
 * @returns {Class}: the created subclass
 */
export const mixin = (base, transform) => {}

example: mixin

import { superclass, mixin } from '@specialblend/superclass'

class SayHello {
    constructor(name) {
        console.log(`Hello ${name}`);
    }
}

class SayWhatsUp {
    constructor(name) {
        console.log(`Whats up ${name}`);
    }
}

class SayBye {
    constructor(name) {
        console.log(`Bye ${name}`);
    }
}

const ExcitedSayHello = mixin(SayHello, name => [name.toUpperCase()]);
const BoredWhatsUp = mixin(SayWhatsUp, name => [`${name}...`]);
const HatefulSayBye = mixin(SayBye, name => [`${name}. See you never!`]);
class BipolarPerson extends superclass(ExcitedSayHello, BoredWhatsUp, HatefulSayBye) {}

const myBipolarPerson = new BipolarPerson('Alice')

// Hello ALICE
// Whats up Alice...
// Bye Alice. See you never!