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 🙏

© 2026 – Pkg Stats / Ryan Hefner

classy-traits

v0.0.4

Published

Thin wrapper around traits.js that supports "classes".

Readme

Classy Traits

This is just a very thin wrapper around traits for use with "class" altjs languages like coffeescript and livescript. It provides an alternative to multiple inheritance and mixins that is less flawed.

The problem

Any sufficiently large OOP project will run in to hierarchy issues. Some languages solve this with multiple inheritance. Some solve this with mixins. Both approaches can get you into the diamond problem.

There is no good way to automatically handle conflicts once you're in a diamond. Some attempts are:

  • Arbitrarily decide which attribute/method to use globally. This is the approach most languages take.
  • Bloat the super class to have attributes/methods (that don't necessarily make sense in the superclass) from its subclasses.
  • Produce more boiler plate by duplicating classes.

A solution

Enter the concept of traits.

The original research and paper can be found here. It is recommended to read at least this paper in order to understand where multiple inheritance breaks down, and where mixins also break down.

These are actual traits, not mixins as we have in LiveScript, Ruby, or Scala. The main difference is that conflict resolution is forced upon the programmer, not the language. With mixins or multiple inheritance, conflicts are resolved in a linear fashion. Some use "first past the post" wins, some use "last past the post" wins, some are even more compilcated. With traits, the programmer must decide how to resolve the conflict. If you have a conflict, and you do not resolve it, you cannot use the program. In the case of classy-traits, you will get an runtime error upon instantiation. This seems like more upfront work, and it is, but it allows for better composition and greater reusability.

For more documentation see traits.

Usage

Inherit from Trait somewhere in your hierarchy. It's easiest if you go to most super class of your classes, and inherit from there. Then you need just one field in your class for the traits.

Example:

require! T: traits.Trait
require! CT: \classy-traits .Traits

Foo = T do
  foo: T.required
  foo2: -> @foo! + 1

Bar = T do
  bar: T.required

class Baz extends CT
  traits: ->
    compose:
      Foo
      Bar
    trait:
      foo: -> @bar
      bar: 110

baz = new Baz
baz.foo2! #=> 111

There are a three ways to resolve conflicts:

  • Renaming
  • Excluding
  • Overriding

You are encouraged to read the papers linked above to understand when to best use each. If you're too lazy, hopefully the names are descriptive enough. Of course, names in programming are all but meaningless, so code fast and loose at your own peril.

Options

compose

Compose other traits. Must be an array of traits.

create

Prototype to create traits from. Must be an actual prototype.

exclude

Attributes to exclude from specified traits. Must be an object with the form:

{
    <attribute_to_exclude1>: <trait_to_exclude_from1>,
    <attribute_to_exclude2>: <trait_to_exclude_from2>,
    ...
    <attribute_to_excluden>: <trait_to_exclude_fromn>
}
override

Traits to override. This favors earlier traits. Must be an array of traits.

required

Required attributes. Must be an array of strings.

rename

Attributes to rename from specified traits. Must be an object of the form:

{
    <attribute_to_rename1>: [<new_name1>, <trait_to_rename_from1>],
    <attribute_to_rename2>: [<new_name2>, <trait_to_rename_from2>],
    ...
    <attribute_to_renamen>: [<new_namen>, <trait_to_rename_fromn>]
}
trait

Object to create new trait. Must be an object.