Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
transmutant
Advanced tools
A lightweight TypeScript library for flexible object transmutation with type safety.
npm install transmutant
import { transmute } from 'transmutant';
interface User {
firstName: string;
lastName: string;
age: number;
}
interface UserDTO {
fullName: string;
yearOfBirth: number;
}
const schema = [
{
to: 'fullName',
fn: ({ source }) => `${source.firstName} ${source.lastName}`
},
{
to: 'yearOfBirth',
fn: ({ source }) => new Date().getFullYear() - source.age
}
];
const user: User = {
firstName: 'John',
lastName: 'Doe',
age: 30
};
const userDTO = transmute<User, UserDTO>(schema, user);
// Result: { fullName: 'John Doe', yearOfBirth: 1994 }
interface Source {
id: number;
name: string;
}
interface Target {
userId: number;
userName: string;
}
const schema = [
{ from: 'id', to: 'userId' },
{ from: 'name', to: 'userName' }
];
const source: Source = { id: 1, name: 'John' };
const target = transmute<Source, Target>(schema, source);
// Result: { userId: 1, userName: 'John' }
interface Product {
price: number;
}
interface PricedProduct {
finalPrice: number;
}
const schema = [
{
to: 'finalPrice',
fn: ({ source, extra }) => source.price * (1 + extra.taxRate)
}
];
const product: Product = { price: 100 };
const pricedProduct = transmute<Product, PricedProduct>(
schema,
product,
{ taxRate: 0.2 }
);
// Result: { finalPrice: 120 }
transmute<Source, Target>(schema, source, extra?)
Transmutes a source object into a target type based on the provided schema.
schema
: Array of transmutation rules defining how properties should be transmutedsource
: Source object to transmuteextra
: (Optional) Additional data to pass to transmutation functions{
to: keyof Target;
from: keyof Source;
}
{
to: keyof Target;
fn: (args: { source: Source; extra?: Extra }) => unknown;
}
{
to: keyof Target;
from: keyof Source;
fn: (args: { source: Source; from?: keyof Source; extra?: Extra }) => unknown;
}
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
Powerful type transmutations for TypeScript 🧬
We found that transmutant 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.