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

@albud/kind

v0.1.7

Published

TypeScript friendly library for creating classes with automatic validation and type conversion

Downloads

15

Readme

@albud/kind

Create classes with automatic validation and type conversion in TypeScript/JavaScript.

Note: kind is designed for constructing data-centric classes with properties and simple methods. It may not be good fit if that doesn't sound like the kinds of classes you want to construct.

Benefits

The key advantages of using kind over traditional class definitions:

  • Boilerplate reduction - No more repetitive constructor code
  • Automatic validation - Input data is validated and converted to correct types
  • Type safety - Full TypeScript support with proper type inference

Basic Usage

A simple example showing how to create a class with properties and methods:

import { kind } from "@albud/kind";

const Person = kind({
  name: String,
  age: Number,
  get greeting() {
    return `Hello, I'm ${this.name} and I'm ${this.age}`;
  }
  greet() {
    console.log(this.greeting)
  }
});

// Automatically validates and converts types
const john = new Person({ name: "John", age: 30 });
console.log(john.name); 
console.log(john.age);  
console.log(john.greeting)
john.greet()

Advanced Features

Explore more sophisticated patterns and capabilities:

Optional Properties

import { kind, optional } from "@albud/kind";

const User = kind({
  name: String,
  email: optional(String),
});

const user = new User({ name: "John" }); // email is undefined

Arrays

import { kind, array } from "@albud/kind";

const TodoList = kind({
  items: array(String),
  completed: array(Boolean),
});

const todos = new TodoList({
  items: ["Task 1", 2, true],        // ["Task 1", "2", "true"]
  completed: ["true", 0, 1]          // [true, false, true]
});

Custom Types

class Email extends String {
  constructor(email: string) {
    if (!email.includes("@")) {
      throw new Error("Invalid email format");
    }
    super(email.toLowerCase());
  }
}

const User = kind({
  name: String,
  email: Email,
  extraEmails: array(Email),  // Arrays of custom types work too
});

const user = new User({
  name: "John",
  email: "[email protected]",  // Converted to "[email protected]"
  extraEmails: ["[email protected]", "[email protected]"]
});

Custom Base Class

class BaseEntity {
  id = Math.random();
  createdAt = new Date();
  
  save() {
    console.log(`Saving entity ${this.id}`);
  }
}

const User = kind({
  name: String,
  email: String,
}, BaseEntity);

const user = new User({ name: "John", email: "[email protected]" });
user.save(); // Method from BaseEntity
console.log(user.id); // Property from BaseEntity

Value Construction

How kind transforms input data using constructor functions:

  • String: Converts any value to string
  • Number: Converts strings/booleans to numbers (throws on invalid)
  • Boolean: Converts strings ("false"/"0"/"" → false, others → true)
  • Date: Converts strings/numbers to Date objects
  • Custom constructors: Uses new Constructor(value)

Installation

How to add kind to your project:

# npm
npm install @albud/kind

# yarn
yarn add @albud/kind

# pnpm
pnpm add @albud/kind
import { kind, optional, array } from "@albud/kind";

But Why?

See the difference between kind and traditional class construction:

Here's what the same Person class looks like without kind:

class Person {
  name: string;
  age: number;

  constructor(data: { name: string | number; age: string | number }) {
    if (typeof data.name !== 'string') {
      this.name = String(data.name);
    } else {
      this.name = data.name;
    }
    
    if (typeof data.age === 'string') {
      this.age = Number(data.age);
      if (isNaN(this.age)) {
        throw new Error('Invalid age');
      }
    } else {
      this.age = data.age;
    }
  }

  greet() {
    return `Hello, I'm ${this.name} and I'm ${this.age} years old`;
  }
}

That's 20+ lines of boilerplate for what kind does in 8 lines, and kind handles edge cases you might forget.