
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
@synstack/enhance
Advanced tools
Type-safe object enhancement with proxy-based method extension
Type-safe object enhancement with proxy-based method extension
Sometimes you need to add functionality to existing objects without modifying their prototype or breaking equality checks. This package provides a safe way to enhance objects with new methods while maintaining type safety:
import { enhance } from "@synstack/enhance";
// Create an extension with new methods
const objExtensions = {
stringify: function () {
return JSON.stringify(this);
},
clone: function () {
return { ...this };
},
};
// Enhance an object with new methods
const obj = { name: "example", value: 42 };
const enhanced = enhance("object", obj, objExtensions);
// Use the enhanced object
console.log(enhanced.stringify()); // '{"name":"example","value":42}'
console.log(enhanced.clone()); // { name: "example", value: 42 }
// Access the original object
console.log(enhanced.$()); // { name: "example", value: 42 }
# Using npm
npm install @synstack/enhance
# Using yarn
yarn add @synstack/enhance
# Using pnpm
pnpm add @synstack/enhance
The package provides two main functions for enhancing objects:
The enhance()
function combines an object with extension methods:
import { enhance } from "@synstack/enhance";
// Define extension methods
const loggerExtensions = {
log: function () {
console.log(JSON.stringify(this));
},
getTimestamp: function () {
return { ...this, timestamp: Date.now() };
},
};
// Enhance an object
const data = { id: 1, message: "Hello" };
const enhanced = enhance("logger", data, loggerExtensions);
// Use enhanced methods
enhanced.log(); // Logs: {"id":1,"message":"Hello"}
const timestamped = enhanced.getTimestamp(); // { id: 1, message: "Hello", timestamp: 1234567890 }
Create reusable enhancers with enhanceFactory()
:
import { enhanceFactory } from "@synstack/enhance";
// Create a reusable enhancer
const withLogging = enhanceFactory("logger", {
log: function () {
console.log(JSON.stringify(this));
},
getTimestamp: function () {
return { ...this, timestamp: Date.now() };
},
});
// Enhance multiple objects
const obj1 = withLogging({ id: 1, name: "First" });
const obj2 = withLogging({ id: 2, name: "Second" });
obj1.log(); // Logs: {"id":1,"name":"First"}
obj2.log(); // Logs: {"id":2,"name":"Second"}
FAQs
Type-safe object enhancement with proxy-based method extension
The npm package @synstack/enhance receives a total of 323 weekly downloads. As such, @synstack/enhance popularity was classified as not popular.
We found that @synstack/enhance 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
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.