{"id":43781768,"url":"https://github.com/twistezo/ts-dto-mapper","last_synced_at":"2026-02-05T18:19:28.259Z","repository":{"id":184832007,"uuid":"672546876","full_name":"twistezo/ts-dto-mapper","owner":"twistezo","description":"DTO (Data Transfer Object) to Object Model transformer","archived":false,"fork":false,"pushed_at":"2023-07-30T16:30:36.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T09:36:43.042Z","etag":null,"topics":["data","dto","map","mapper","model","object","transfer","transform","transformer","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@twistezo/ts-dto-mapper","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twistezo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-30T13:05:38.000Z","updated_at":"2023-10-16T04:36:55.000Z","dependencies_parsed_at":"2023-08-18T23:46:13.219Z","dependency_job_id":null,"html_url":"https://github.com/twistezo/ts-dto-mapper","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"d09f538392defadedd4a834ffde05b017df44815"},"previous_names":["twistezo/ts-dto-mapper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/twistezo/ts-dto-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistezo%2Fts-dto-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistezo%2Fts-dto-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistezo%2Fts-dto-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistezo%2Fts-dto-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twistezo","download_url":"https://codeload.github.com/twistezo/ts-dto-mapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twistezo%2Fts-dto-mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29128626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T17:12:17.649Z","status":"ssl_error","status_checked_at":"2026-02-05T17:11:23.670Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","dto","map","mapper","model","object","transfer","transform","transformer","typescript"],"created_at":"2026-02-05T18:19:26.279Z","updated_at":"2026-02-05T18:19:28.251Z","avatar_url":"https://github.com/twistezo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# DTO mapper based on TS types\n\n![](https://img.shields.io/npm/v/@twistezo/ts-dto-mapper?style=flat-square\u0026color=9cf)\n![](https://img.shields.io/npm/dt/@twistezo/ts-dto-mapper?style=flat-square\u0026color=9cf)\n![](https://img.shields.io/npm/l/@twistezo/ts-dto-mapper?style=flat-square\u0026color=yellow)\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Build and test](https://github.com/twistezo/ts-dto-mapper/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/twistezo/ts-dto-mapper/actions/workflows/build.yml?query=branch:main)\n\n\u003c/div\u003e\n\n## Description\n\nUtility for easy mapping between DTO and OM objects based on their data types.\n\nBenefits:\n\n- no object-oriented approach based on classes\n- no cluttering the code with decorators\n- no need to install a large library for a simple operation\n- only function based on objects types with access to the context inside\n\n## Knowledge\n\nDTO - Data Transfer Object\n\n- ex. object shape from API\n- https://en.wikipedia.org/wiki/Data_transfer_object\n\nOM - Object Model\n\n- various shape of object, ex. business object\n- https://en.wikipedia.org/wiki/Object_model\n\n## Setup\n\n```\nnpm install @twistezo/ts-dto-mapper\n```\n\n## Tips\n\n- Always populate generic types `\u003cFrom\u003e`, and `\u003cTo\u003e` in `mapDTO` function. This helps you with debugging and provides IDE IntelliSense.\n\n- `.transform` accepts callback with source context so you can put there reusable data transformation and have reusable mapper.\n\n## Usage\n\n### tldr;\n\nFrom DTO (one-way):\n\n```ts\nconst foo = mapDTO\u003cFooDTO, Foo\u003e({\n  from: fooDTO,\n}).transform(fooDTO =\u003e ({\n  // map with access to source context\n}))\n```\n\nTo DTO (one-way):\n\n```ts\nconst fooDTO = mapDTO\u003cFoo, FooDTO\u003e({\n  from: foo,\n}).transform(foo =\u003e ({\n  // map with access to source context\n}))\n```\n\nBidirectional (both ways at once):\n\n```ts\nconst { from, to } = mapDTO\u003cFooDTO, Foo\u003e({\n  from: fooDTO,\n})\n  .reverse(foo) // reverse source\n  .transform(\n    fooDTO =\u003e ({\n      // DTO -\u003e OM\n    }),\n    foo =\u003e ({\n      // OM -\u003e DTO\n    }),\n  )\n```\n\n### Full example\n\nImport:\n\n```ts\nimport { mapDTO } from '@twistezo/ts-dto-mapper'\n```\n\nPrepare OM and DTO shapes:\n\n```ts\ntype Foo = {\n  id: string\n  firstName: string\n  lastName: string\n}\n\ntype FooDTO = {\n  uuid: number\n  fullName: string\n  unnecessary: object\n}\n```\n\nPrepare objects:\n\n```ts\nconst foo: Foo = {\n  id: '1001',\n  firstName: 'John',\n  lastName: 'Smith',\n}\n\nconst fooDTO: FooDTO = {\n  uuid: 1001,\n  fullName: 'John Smith',\n  unnecessary: {},\n}\n```\n\nMap from DTO to OM:\n\n```ts\nconst fooFromFooDTO: Foo = mapDTO\u003cFooDTO, Foo\u003e({\n  from: fooDTO,\n}).transform((fooDTO: FooDTO): Foo =\u003e {\n  // map with access to source context\n\n  const { fullName, uuid } = fooDTO\n  const [firstName, lastName] = fullName.split(' ')\n\n  return {\n    id: uuid.toString(),\n    firstName,\n    lastName,\n  }\n})\n```\n\nMap from OM to DTO:\n\n```ts\nconst fooDTOfromFoo: FooDTO = mapDTO\u003cFoo, FooDTO\u003e({ from: foo }).transform(foo =\u003e {\n  // map with access to source context\n\n  const { firstName, id, lastName } = foo\n\n  return {\n    uuid: Number(id),\n    fullName: `${firstName} ${lastName}`,\n    unnecessary: {},\n  }\n})\n```\n\n#### Bidirectional mapping\n\nWhen you need to transform objects in both directions simultaneously, use the `.reverse()` method:\n\n```ts\nconst { from, to } = mapDTO\u003cFooDTO, Foo\u003e({ from: fooDTO })\n  .reverse(foo)\n  .transform(\n    // Forward: FooDTO -\u003e Foo\n    (fooDTO: FooDTO): Foo =\u003e {\n      const { fullName, uuid } = fooDTO\n      const [firstName, lastName] = fullName.split(' ')\n\n      return {\n        id: uuid.toString(),\n        firstName,\n        lastName,\n      }\n    },\n    // Reverse: Foo -\u003e FooDTO\n    (foo: Foo): FooDTO =\u003e {\n      const { firstName, id, lastName } = foo\n\n      return {\n        uuid: Number(id),\n        fullName: `${firstName} ${lastName}`,\n        unnecessary: {},\n      }\n    },\n  )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwistezo%2Fts-dto-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwistezo%2Fts-dto-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwistezo%2Fts-dto-mapper/lists"}