
Security News
Frontier AI Is Now Critical Infrastructure
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.
@mkrause/constructor
Advanced tools
Create JavaScript constructors using declarative schema definitions.
Utility library to create JavaScript constructors based on a declarative schema.
Example:
import constructor from '@mkrause/constructor';
const MyConstructor = constructor({ x: String, y: Number });
const myInstance = MyConstructor({ x: "foo", y: 42 });
myInstance instanceof MyConstructor; // true
MyConstructor({ x: "foo", y: "42" }); // Throws `InvalidInstanceException`
Each instance stores the validated value in a property accessed through a special symbol constructor.internal:
const Person = constructor({ name: String, score: Number });
const john = Person({ name: "John", score: 101 });
john[constructor.internal]; // { name: "John", score: 101 }
This internal property is not supposed to be accessed by the consumer directly. Instead, a constructor should specify a public API through extend():
const Person = constructor({ name: String, score: Number })
.extend({
get name() { return this[constructor.internal].name; },
get score() { return this[constructor.internal].score; },
});
const john = Person({ name: "John", score: 101 });
john.name; // "John"
Any JS constructor can be used as type in a schema, including other constructors defined using constructor():
const Post = constructor({ author: Person, submitted: Date });
const post = Post({ author: john, submitted: new Date("2017-01-01") });
FAQs
Create JavaScript constructors using declarative schema definitions.
The npm package @mkrause/constructor receives a total of 5 weekly downloads. As such, @mkrause/constructor popularity was classified as not popular.
We found that @mkrause/constructor demonstrated a not healthy version release cadence and project activity because the last version was released 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
The Fable shutdown shows how quickly model access can become a business continuity risk for AI-dependent engineering teams.

Security News
AI agents are pulling packages into environments no scanner is watching, creating exposure before security teams can see it.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.