npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@tamnt-work/data-mapper

v1.0.32

Published

<h1 align="center">Welcome to @tamnt-work/data-mapper πŸ‘‹</h1> <p> <a href="https://www.npmjs.com/package/@tamnt-work/data-mapper" target="_blank"> <img alt="Version" src="https://img.shields.io/npm/v/@tamnt-work/data-mapper.svg"> </a> <a href="#

Downloads

10

Readme

Install

yarn add @tamnt-work/data-mapper

Usage with CLI

Create custom config

npx tw init

We will create a tw-config.json file in the root of your project.

Default config:

{
  "modulePath": "/app",
  "modelSuffix": ".model",
  "mapperSuffix": ".mapper",
  "entitySuffix": ".entity",
  "overwrite": false
}

Create schema

npx tw schema init

We will create a schema/schema.tws file in your project.

Define schema

Example:

user:
  id: string <=> id
  fullName: string <=> name
  username: string
  email: string
  phoneNumber: string <=> phone
  companyName: string <=> company.name
  address: string <=> address.street.name
  age: number

post:
  id: string
  title: string <=> name
  content: string <=> body
  views: number
  createdAt: string <=> date

Generate with schema

npx tw schema generate

Output

user.entity.ts

export interface UserEntity {
  id: string;
  name: string;
  username: string;
  email: string;
  phone: string;
  age: number;
  company: {
    name: string;
  };
  address: {
    street: {
      name: string;
    };
  };
}

user.model.ts

export interface UserModel {
  id: string;
  fullName: string;
  username: string;
  email: string;
  phoneNumber: string;
  companyName: string;
  address: string;
  age: number;
}

user.mapper.ts

import { Mapper, type TransformationMap } from "@tamnt-work/data-mapper";
import type { UserEntity } from "./user.entity";
import type { UserModel } from "./user.model";

const transformationMap: TransformationMap<UserModel, UserEntity> = {
  id: "id",
  fullName: "name",
  username: "username",
  email: "email",
  phoneNumber: "phone",
  companyName: "company.name",
  address: "address.street.name",
  age: "age",
};

export const UserMapper = new Mapper<UserEntity, UserModel>(transformationMap);

Example

Auto suggestion with key and value

Alt Text

Usage with code

const data = {
  id: "1",
  name: "Leanne Graham",
  username: "Bret",
  email: "[email protected]",
  address: {
    street: "Kulas Light",
    suite: "Apt. 556",
    city: "Gwenborough",
    zipcode: "92998-3874",
    geo: {
      lat: "-37.3159",
      lng: "81.1496",
    },
  },
  phone: "1-770-736-8031 x56442",
  website: "hildegard.org",
  company: {
    name: "Romaguera-Crona",
    catchPhrase: "Multi-layered client-server neural-net",
    bs: "harness real-time e-markets",
  },
};

const model = UserMapper.toModel(data);

// Output
{
  "id": "1",
  "companyName": "Romaguera-Crona",
  "email": "[email protected]",
  "fullName": "Leanne Graham",
  "phoneNumber": "1-770-736-8031 x56442",
  "username": "Bret"
}

const entity = UserMapper.toEntity(model);

// Output
{
  "id": "1",
  "company": {
    "name": "Romaguera-Crona"
  },
  "email": "[email protected]",
  "name": "Leanne Graham",
  "phone": "1-770-736-8031 x56442",
  "username": "Bret"
}

Method

Mapper

toArrayModel

toArrayModel(entity: Entity[]): Model[]

toEntityArray

toEntityArray(model: Model[]): Entity[]

toModel

toModel(entity: Entity): Model

toEntity

toEntity(model: Model): Entity

Author

πŸ‘€ TamNT

Email: [email protected]

Show your support

Give a ⭐️ if this project helped you!