
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.
A lightweight, flexible, and type-safe AutoMapper utility for TypeScript, allowing you to easily map between different object types.
A lightweight, flexible, and type-safe AutoMapper utility for TypeScript, allowing you to easily map between different object types.
To install the package:
npm i ectomapper
Here’s how to create and use an AutoMapper in your TypeScript project:
import { createAutoMapper } from 'ectomapper'
// Define your source and destination types
interface SourceType {
id: number
name: string
}
interface DestinationType {
id: number
fullName: string
}
// Create an instance of AutoMapper
const autoMapper = createAutoMapper()
// Define a map between SourceType and DestinationType
autoMapper.createMap<SourceType, DestinationType>(
'SourceType',
'DestinationType',
(source) => ({
id: source.id,
fullName: source.name,
}),
)
// Use the map to transform an object
const source: SourceType = { id: 1, name: 'John Doe' }
const destination = autoMapper.map<SourceType, DestinationType>(
source,
'SourceType',
'DestinationType',
)
console.log(destination) // Output: { id: 1, fullName: 'John Doe' }
You can define multiple mappings for different types:
interface UserDTO {
userId: number
username: string
}
interface User {
id: number
name: string
}
// Create mappings
autoMapper.createMap<UserDTO, User>('UserDTO', 'User', (source) => ({
id: source.userId,
name: source.username,
}))
autoMapper.createMap<User, UserDTO>('User', 'UserDTO', (source) => ({
userId: source.id,
username: source.name,
}))
// Map between UserDTO and User
const userDTO: UserDTO = { userId: 42, username: 'johndoe' }
const user = autoMapper.map<UserDTO, User>(userDTO, 'UserDTO', 'User')
console.log(user) // Output: { id: 42, name: 'johndoe' }
If you attempt to map an object without a corresponding mapping, an error will be thrown:
try {
const unknownMapping = autoMapper.map<SourceType, DestinationType>(
source,
'UnknownSource',
'UnknownDestination',
)
} catch (error) {
console.error(error.message) // Output: No mapping found for key: UnknownSource->UnknownDestination
}
createMapcreateMap<TSource, TDestination>(
sourceKey: string,
destinationKey: string,
mappingFunction: MapperFunction<TSource, TDestination>
): void
Defines a mapping between two types using the provided string keys.
mapmap<TSource, TDestination>(
source: TSource,
sourceKey: string,
destinationKey: string
): TDestination
Maps an object from the source type to the destination type using the defined mapping.
Contributions are welcome! Please submit issues and pull requests to help improve the package.
This project is licensed under the terms of the MIT License.
FAQs
A lightweight, flexible, and type-safe AutoMapper utility for TypeScript, allowing you to easily map between different object types.
The npm package ectomapper receives a total of 1 weekly downloads. As such, ectomapper popularity was classified as not popular.
We found that ectomapper 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.