
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@albud/kind
Advanced tools
TypeScript friendly library for creating classes with automatic validation and type conversion
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.
The key advantages of using kind over traditional class definitions:
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()
Explore more sophisticated patterns and capabilities:
import { kind, optional } from "@albud/kind";
const User = kind({
name: String,
email: optional(String),
});
const user = new User({ name: "John" }); // email is undefined
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]
});
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: "John@Example.COM", // Converted to "john@example.com"
extraEmails: ["admin@site.com", "user@site.com"]
});
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: "john@example.com" });
user.save(); // Method from BaseEntity
console.log(user.id); // Property from BaseEntity
How kind transforms input data using constructor functions:
String: Converts any value to stringNumber: Converts strings/booleans to numbers (throws on invalid)Boolean: Converts strings ("false"/"0"/"" → false, others → true)Date: Converts strings/numbers to Date objectsnew Constructor(value)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";
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.
FAQs
TypeScript friendly library for creating classes with automatic validation and type conversion
We found that @albud/kind demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.