{"id":22642455,"url":"https://github.com/kilix/dafit","last_synced_at":"2025-04-11T23:22:53.211Z","repository":{"id":82266156,"uuid":"87102075","full_name":"Kilix/dafit","owner":"Kilix","description":"Transform data to fit into any model","archived":false,"fork":false,"pushed_at":"2017-05-12T09:20:32.000Z","size":64,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-14T04:51:01.516Z","etag":null,"topics":["async","asynchronous","data","data-structures","javascript","js","transform","transform-data","transformer"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/Kilix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2017-04-03T17:34:23.000Z","updated_at":"2019-05-22T11:04:12.000Z","dependencies_parsed_at":"2023-04-03T21:26:38.421Z","dependency_job_id":null,"html_url":"https://github.com/Kilix/dafit","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":"0.040000000000000036","last_synced_commit":"598ececcb81cb46bb9273dc3ce0e92ea702f6d12"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilix%2Fdafit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilix%2Fdafit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilix%2Fdafit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kilix%2Fdafit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kilix","download_url":"https://codeload.github.com/Kilix/dafit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248493419,"owners_count":21113252,"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":["async","asynchronous","data","data-structures","javascript","js","transform","transform-data","transformer"],"created_at":"2024-12-09T05:06:52.628Z","updated_at":"2025-04-11T23:22:53.203Z","avatar_url":"https://github.com/Kilix.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dafit\n\nTransform data to fit your structures.\n\n\n[![npm](https://img.shields.io/npm/v/dafit.svg?style=flat-square)](https://www.npmjs.com/package/dafit)\n[![npm](https://img.shields.io/npm/dm/dafit.svg?style=flat-square)](https://www.npmjs.com/package/dafit)\n[![license](https://img.shields.io/github/license/alexandrebodin/dafit.svg?style=flat-square)](https://opensource.org/licenses/MIT)\n\n[![CircleCI](https://img.shields.io/circleci/project/Kilix/dafit.svg?style=flat-square)](https://circleci.com/gh/Kilix/dafit)\n[![Codecov](https://img.shields.io/codecov/c/github/Kilix/dafit.svg?style=flat-square)](https://codecov.io/github/Kilix/dafit)\n\n## Installation\n\n```bash\n$ npm install --save dafit\n```\n\n## Usage\n\nDafit enables you to create a dynamic schema you want your data to fit.\n\n```javascript\nimport { Resolver } from 'dafit';\n// import dafit from 'dafit';\n// then user dafit.Resolver\n// or\n// const { Resolver } = require('dafit');\n\nconst defaultValue = null;\n\nconst resolveUser = new Resolver({\n    id: defaultValue, // if field id is present will return it if not will set it to defaultValue\n    firstname: user =\u003e user.first_name, // will set firstname as the return value of the function\n    lastname: user =\u003e user.last_name,\n    fullName: user =\u003e `${user.first_name} ${user.last_name.toUpperCase()}` \n    friends: user =\u003e getFriends(user.id), // will wait for any thenable (e.g Promise) to resolve\n    permissions: (user, context) =\u003e { // receives a context to enable more dynamic resolving\n        if (contact.withPermissions) return getPermissions(user)\n        return []\n    },\n})\n\nconst user = {\n    id: 1,\n    first_name: 'John',\n    last_name: 'Cena',\n    age: 39\n}\n\nconst result = resolveUser(user, { withPermissions: true });\n// Promise\u003c{\n//    id: 1, \n//    firstname: 'John', \n//    lastname: 'Cena', \n//    fullName: 'John CENA', \n//    friends: [...], \n//    permissions: ['WRITE_DASHBOARD']\n// }\u003e\n```\n\nYou can also use a synchronuous resolver for some use case to avoid using Promises\n\n```javascript\nimport { SyncResolver } from 'dafit';\n// const { SyncResolver } = require('dafit');\n\nconst defaultValue = null;\n\nconst resolveUser = new SyncResolver({\n    id: defaultValue, // if field id is present will return it if not will set it to defaultValue\n    firstname: user =\u003e user.first_name, // will set firstname as the return value of the function\n    lastname: user =\u003e user.last_name,\n    fullName: user =\u003e `${user.first_name} ${user.last_name.toUpperCase()}`,\n    aPromise: () =\u003e new Promise((resolve) =\u003e resolve('Hello World!')), // the promise will not be resolved before return\n})\n\nconst user = {\n    id: 1,\n    first_name: 'John',\n    last_name: 'Cena',\n    age: 39\n}\n\nconst result = resolveUser(user, { withPermission: true });\n// {\n//    id: 1, \n//    firstname: 'John', \n//    lastname: 'Cena', \n//    fullName: 'John CENA',\n//    aPromise: Promise\u003c'Hello World!'\u003e\n// }\n```\n\n\n\n## Change Log \n\n- Changes are reported on the [Github release page](https://github.com/Kilix/dafit/releases)\n\n## Contributing\n\nRead [How to contribute](https://github.com/Kilix/dafit/blob/master/CONTRIBUTING.md) to help us improve this library.\n\n## Ideas for contribution\n\n- [] Adding before / after hooks\n- [] Adding support for default context\n- [] Handling nested structures\n- [] Adding support for Rx and such\n- [] Adding plugins feature to add more flexibility *(e.g immutable-plugin to pass a withMutation object to the resolvers for improved performance)*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilix%2Fdafit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkilix%2Fdafit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkilix%2Fdafit/lists"}