
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.
Inspired by MaDEiN83 mapper
$ npm install ts-mapper
To create a mapping between two objects, you must call the object method createMap of the TypeMapper class.
It takes two interfaces:
So, if we have an object of type ISource and we want a object of type IDestination, we should create a new mapping like that:
import { TypeMapper } from "ts-mapper";
import { ISource, IDestination } = "../path/of/interfaces.ts";
export class Mapper extends TypeMapper {
constructor() {
super();
this.config();
}
private config(): void {
// put here your mapping configurations
this.createMap<ISource, IDestination>();
}
}
const mapper = new Mapper();
After we create a mapping between interfaces, we can now create all mappings between all wanted properties of our objects (source & destination).
For example, if we want to map the property sourceObject.srcOther to destinationObjet.other, we can define rule like that:
mapper.createMap<ISource, IDestination>();
.map(src => src.srcProperty, dest => dest.destProperty)
.map(src => src.srcOther, dest => dest.other);
src type is ISourcedest type is IDestinationYou can chain your rules !
conditions method allows you to check if the previous map will be analysed and mapped to the destination object.
Example:
We want to map the property srcProperty (source object) into destProperty (destination object) only if the property visible of the source object is true.
mapper.createMap<ISource, IDestination>();
.map(src => src.srcProperty, dest => dest.destProperty)
.conditions((s: ISource) => s.visible);
The conditions method takes two arguments:
Examples:
mapper
.createMap<ISource, IDestination>()
.map(src => src.my_prop, dest => dest.myProp)
.conditions((s: ISource, d: IDestination) => s.visible);
mapper
.createMap<ISource, IDestination>()
.map(src => src.my_prop, dest => dest.myProp)
.conditions((s: ISource, d: IDestination) => s.visible !== d.visible);
Sometime the source properties don't match the destination properties.
Example: sourceObject.age can be a string and destinationObject.age is a number.
To work with, you can cast property by chaining the is method after a map.
import { TypeMapper, AutoMapperTypes } from "ts-mapper";
mapper
.createMap<ISource, IDestination>()
.map(p => p.age, p => p.age)
.is(AutoMapperTypes.NUMBER);
mapper
.createMap<ISource, IDestination>()
.map(p => p.name, p => p.name)
.is(AutoMapperTypes.STRING);
const source: ISource = {
name: "Marluan",
email: "marluan@refactoring.com.do",
password: "my_sup3r_s3cr3t_p455w0rd"
};
const destination: IDestination = { name: null };
mapper.map<ISource, IDestination>(source, destination);
console.log(destination);
// {
// name: "Marluan";
// }
FAQs
Object mapper for TypeScript
The npm package ts-mapper receives a total of 1,020 weekly downloads. As such, ts-mapper popularity was classified as popular.
We found that ts-mapper 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
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.