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 🙏

© 2025 – Pkg Stats / Ryan Hefner

predecessor

v0.0.3

Published

A set of useful classes to inherit from

Downloads

19

Readme

Predecessor

Overview

This set of libraries is intended to provide useful classes to inherit from, in a way that is cross compatible between multiple languages. A version of this library is currently available in:

  • Python (2 or 3)
  • Javascript

The libraries currently provide:

  • singleton objects
  • serializable objects

Singleton

The singleton class provides a way to ensure you only have one instance of a class. For instance:

from predecessor import Singleton


class Example(Singleton):
    def __init__(self, foo, bar):
        self.foo = foo
        self.bar = bar


a = Example(3, 8)
b = Example(2, 9)
a is b  # returns True
a.foo == b.foo == 3  # returns True

Or equivalently in Javascript:

const Singleton = require('predecessor').Singleton;

class Example extends Singleton {
    constructor(foo, bar)   {
        this.foo = foo;
        this.bar = bar;
    }
}

let a = new Example(3, 8);
let b = new Example(2, 9);
a === b;  // returns true
a.foo === 3;  // returns true
b.foo === 3;  // returns true

Serializable

The singleton class provides a way to serialize a class without needing to care about what form the resulting blob takes. If a compatible class definition is available in all supported languages, it should be deserializable in all supported languages.

The Basic Case

from predecessor import Serializable


class Example(Serializable):
    def __init__(self, foo, bar):  # Note that keyword args are not supported
        self.foo = foo
        self.bar = bar

    def serialized(self):
        return super(Example, self).serialized(self.foo, self.bar)


a = Example(3, 8)
b = Example.deserialize(a.serialized())
a.foo == b.foo == 3  # returns True
a.bar == b.bar == 8  # returns True

Or equivalently in Javascript:

const Serializable = require('predecessor').Serializable;

class Example extends Serializable {
    constructor(foo, bar)   {
        this.foo = foo;
        this.bar = bar;
    }

    serialized()    {
        return super.serialized(this.foo, this.bar);
    }
}

let a = new Example(3, 8);
let b = Example.deserialize(a.serialized());
a.foo === 3;  // returns true
b.foo === 3;  // returns true
a.foo === 8;  // returns true
b.foo === 8;  // returns true

Implied Serialization

In both languages, you can also use implied serialization. This looks like:

class Example(Serializable):
    __slots__ = ('a', 'b', 'c')

    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c
class Example extends Serializable  {
    constructor(a, b, c)    {
        super();
        this._slots = ['a', 'b', 'c'];
        this.a = a;
        this.b = b;
        this.c = c;
    }
}

Advanced Recombination

In both languages you can do data processing before feeding things into your constructor.

class Example(Serializable):
    def __init__(self, a, b, c):
        self.a = a
        self.b = b
        self.c = c

    def serialized(self):
        return super(Example, self).serialized(self.a, self.b)

    @classmethod
    def recombine(cls, a, b):
        return cls(a, b, a+b)
class Example extends Serializable  {
    constructor(a, b, c)    {
        super();
        this.a = a;
        this.b = b;
        this.c = c;
    }

    serialized()    {
        return super.serialized(this.a, this.b);
    }

    static recombine(a, b)  {
        return new this(a, b, a+b);
    }
}