{"id":19594866,"url":"https://github.com/glebbatykov/mapper_box","last_synced_at":"2026-06-13T11:32:05.730Z","repository":{"id":61975339,"uuid":"490226556","full_name":"GlebBatykov/mapper_box","owner":"GlebBatykov","description":"Simple wrapper to collect object conversion rules.","archived":false,"fork":false,"pushed_at":"2023-01-08T22:35:34.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T07:18:21.664Z","etag":null,"topics":["convert","dart","flutter","mapper"],"latest_commit_sha":null,"homepage":"","language":"Dart","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/GlebBatykov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-09T09:58:18.000Z","updated_at":"2022-05-10T05:31:01.000Z","dependencies_parsed_at":"2023-02-08T07:45:39.327Z","dependency_job_id":null,"html_url":"https://github.com/GlebBatykov/mapper_box","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlebBatykov%2Fmapper_box","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlebBatykov%2Fmapper_box/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlebBatykov%2Fmapper_box/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GlebBatykov%2Fmapper_box/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GlebBatykov","download_url":"https://codeload.github.com/GlebBatykov/mapper_box/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240867972,"owners_count":19870509,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["convert","dart","flutter","mapper"],"created_at":"2024-11-11T08:45:03.012Z","updated_at":"2026-06-13T11:32:05.689Z","avatar_url":"https://github.com/GlebBatykov.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n**Languages:**\n  \n[![English](https://img.shields.io/badge/Language-English-blue?style=?style=flat-square)](README.md)\n[![Russian](https://img.shields.io/badge/Language-Russian-blue?style=?style=flat-square)](README.ru.md)\n\n\u003c/div\u003e\n\n- [Introduction](#introduction)\n- [About MapperBox](#about-mapperbox)\n- [Installing](#installing)\n- [Using](#using)\n  - [Asynchronous mapping](#asynchronous-mapping)\n\n# Introduction\n\nWhen developing applications on Dart, I periodically encounter the need to convert some models into others. Due to the lack of reflection during AOT compilation, there are no packages for automatic conversion in Dart (although it is possible to implement this for JIT compilation using dart:mirrors). This package is a simple wrapper to store the type conversion rules in one place of the application.\n\n# About MapperBox\n\nThis package is a wrapper, a repository that stores the specified type conversion rules in your application.\n\n# Installing\n\nAdd MapperBox to your pubspec.yaml file:\n\n```dart\ndependencies:\n  mapper_box: ^1.0.1\n```\n\nImport ossa in file that it will be used:\n\n```dart\nimport 'package:mapper_box/mapper_box.dart';\n```\n\n# Using\n\nThe converter function is registered using the register\u0026lt;F, S\u0026gt; method of the MapperBox class, which takes the FutureOr\u0026lt;S\u0026gt; Function(F) function as an argument.\n\nConversion using previously registered converter functions is performed using the map\u0026lt;F, S\u0026gt; method of the MapperBox class, which takes an object of type F as an argument, and returns an object of type S.\n\nExample of registering a converter function, using conversion:\n\n```dart\nclass DatabaseUser {\n  final int id;\n\n  final String name;\n\n  final int age;\n\n  DatabaseUser(this.id, this.name, this.age);\n}\n\nclass User {\n  final String name;\n\n  final String age;\n\n  User(this.name, this.age);\n\n  @override\n  String toString() {\n    return 'User with name: $name, age: $age.';\n  }\n}\n\nvoid main() {\n  MapperBox.instanse.register\u003cDatabaseUser, User\u003e(\n      (object) =\u003e User(object.name, object.age.toString()));\n\n  var databaseUser = DatabaseUser(0, 'Alex', 22);\n\n  var user = MapperBox.instanse.map\u003cDatabaseUser, User\u003e(databaseUser);\n\n  print(user);\n}\n```\n\nExpacted output:\n\n```dart\nUser with name: Alex, age: 22.\n```\n\n## Asynchronous mapping\n\nDuring the conversion of one type to another, you may need to call asynchronous code, the converter function registered using the register\u0026lt;F, S\u0026gt; method returns FutureOr\u0026lt;S\u0026gt;, that is, it can return Future.\n\nFor asynchronous conversion, the map Async\u0026lt;F, S\u0026gt; method is used, which takes an object of type F as an argument, returns Future\u0026lt;S\u0026gt;.\n\nAn example of using asynchronous conversion:\n\n```dart\nclass DatabaseUser {\n  final int id;\n\n  final String name;\n\n  DatabaseUser(this.id, this.name);\n}\n\nclass User {\n  final String name;\n\n  final int age;\n\n  User(this.name, this.age);\n\n  @override\n  String toString() {\n    return 'User with name: $name, age: $age.';\n  }\n}\n\nFuture\u003cint\u003e getAgeFromFuture() async {\n  return 22;\n}\n\nvoid main() async {\n  MapperBox.instanse.register\u003cDatabaseUser, User\u003e((object) async {\n    var age = await getAgeFromFuture();\n\n    return User(object.name, age);\n  });\n\n  var databaseUser = DatabaseUser(0, 'Alex');\n\n  var user =\n      await MapperBox.instanse.mapAsync\u003cDatabaseUser, User\u003e(databaseUser);\n\n  print(user);\n}\n```\n\nExpacted output:\n\n```dart\nUser with name: Alex, age: 22.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglebbatykov%2Fmapper_box","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglebbatykov%2Fmapper_box","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglebbatykov%2Fmapper_box/lists"}