
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
singleton-injection
Advanced tools
A simple way to manage singletons
This provides a way to create Singleton Container to store Singleton instances
// container.ts
import { SingletonContainer } from "singleton-injection";
// Define your singletons
const singletonMap = {
shape: () => new Circle() as Shape,
otherShape: () => new Square() as Shape
};
// Create Singleton container
export const container = new SingletonContainer(singletonMap);
// app.ts
// Get instance in your app with
import { container } from "./container";
// now you can get same instance of shape anywhere in your code
const shape = container.resolve("shape");
// you will get TS suggestions for parameter of `resolve`, so no need to worry about spelling mistakes
// Destroy container instances
container.destroy();
// after destroy, container.resolve will create and return new instances
container.mock({
shape: () => new MockedSquare() as Shape
});
// With above all `container.resolve("shape")` calls will return this mocked shape
// Note: mocked instances are not singletons, it will create instance everytime
// To restore mock, you can use same method with empty object, this will restore the original container
container.mock({});
FAQs
A simple way to manage singletons in TypeScript projects
The npm package singleton-injection receives a total of 4 weekly downloads. As such, singleton-injection popularity was classified as not popular.
We found that singleton-injection demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.