{"id":20760516,"url":"https://github.com/blueoakjs/model-xformer","last_synced_at":"2026-04-18T20:31:43.899Z","repository":{"id":57300412,"uuid":"57411662","full_name":"BlueOakJS/model-xformer","owner":"BlueOakJS","description":"Common utilities for bidirectionally mapping data between two models","archived":false,"fork":false,"pushed_at":"2018-01-02T17:13:45.000Z","size":44,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-11T16:51:16.675Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BlueOakJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-29T20:39:34.000Z","updated_at":"2018-09-12T14:05:30.000Z","dependencies_parsed_at":"2022-09-08T11:50:13.050Z","dependency_job_id":null,"html_url":"https://github.com/BlueOakJS/model-xformer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/BlueOakJS/model-xformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueOakJS%2Fmodel-xformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueOakJS%2Fmodel-xformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueOakJS%2Fmodel-xformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueOakJS%2Fmodel-xformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BlueOakJS","download_url":"https://codeload.github.com/BlueOakJS/model-xformer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BlueOakJS%2Fmodel-xformer/sbom","scorecard":{"id":23128,"data":{"date":"2025-08-11","repo":{"name":"github.com/BlueOakJS/model-xformer","commit":"60b60bc3800855689b1fa21bf52ec18b45095a2e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":1,"reason":"Found 3/27 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 6 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"19 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm","Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574","Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4","Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g","Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-14T17:15:26.796Z","repository_id":57300412,"created_at":"2025-08-14T17:15:26.796Z","updated_at":"2025-08-14T17:15:26.796Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31984125,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T20:23:30.271Z","status":"ssl_error","status_checked_at":"2026-04-18T20:23:29.375Z","response_time":103,"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":[],"created_at":"2024-11-17T10:14:03.684Z","updated_at":"2026-04-18T20:31:43.876Z","avatar_url":"https://github.com/BlueOakJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BlueOakJS Model Transformer\n\n**Common utilities for bidirectionally mapping data between two models**\n\n If you need to map and transform data from one model (format) to another, this is the module for you!\n\nProvide one JSON configuration that connects the two models, and use `model-xformer` to interpret and apply that\nconfiguration onto real data you provide in one format to output the other.\n\nIn addition to the info below, checkout the [tests](./test) for running examples.\n\n## configuration\n\nMapping from one model to the other is done based on a configuration provided.\n\nexample:\n```javascript\nvar myMappingConfig = {\n    baseObject: {\n        // describes the object that is used as the basis for the mapping. By default the mapper will\n        // base the mapping invocation on an empty object, {}.\n        // The value can be a string - 'source' or a function.\n        map : function (source) {\n            // return the source object as the basis, with the _private attributes removed.\n            return _.omit(source, ['_private']);\n        }\n        mapReverse: 'source'\n    },\n    dataMappings: {\n        // by default, field data is simply mapped from one to the other\n        'targetModel.path.to.field1': 'sourceModel.path.to.comparible-field1',\n        // a transform function can be provided (see below) to handle any formatting nuances\n        'targetModel.path.to.field2': 'sourceModel.path.to.comparible-field2',\n        // dataMappings paths may uses the extended path patterns for picking specific items out of an array, e.g.:\n        'targetModel.somethingSpecial' : 'sourceModel.path.to.array[@_type=Special]'\n    },\n    dataTransforms: {\n        // N.B.: the dataTransforms keys MUST also be keys in the dataMappings object\n        'targetModel.path.to.field1': function transformFnToCall(fieldValue, reverse) { /* ... */ }\n    }\n    customProcessors: [\n        // custom processors are called in the order they're defined\n        {\n            // customProcessors paths may use the standard path patterns supported by lodash get, set, etc.\n            targetModelPath: 'targetModel.path.to.destination',\n            sourceModelPath: 'sourceModel.path.to.whatever.is.needed.to.do.this.mapping',\n            processor: function fnToCallForCustomProcessing(sourceValue, reverse) { /* ... */ }\n        },\n        {\n            // if either the targetModelPath or sourceModelPath is not provided, the whole data object will be used\n            // e.g.: in this case, when the processor function is called going \"forward\",\n            // `sourceValue` will be the entire source object, and when called for \"reverse\" processing,\n            // the whole target object will be passed in\n            targetModelPath: 'targetModel.path.to.something',\n            processor: function anotherFnForCustomProcessing(sourceValue, reverse) { /* ... */ }\n        },\n        /* ... */\n        {\n            /* ... */\n        }\n    ],\n    defaultValues: {\n        // provide default values to use when a mapping fails to produce a value for the named fields,\n        // i.e. when the path in the key is 'undefined' (if there's a value, including 'null', it won't be applied)\n        // default values are added to the mapped object after all mappings/transforms and custom processors are done\n        map: {\n            // in case the data object didn't have the source data to map,\n            // you can provide default values for fields that could be set from elsewhere\n            'targetModel.path.to.field1': 'my default value',\n            // you can also just fill in additional data that is always the same\n            'targetModel.somethingSpecial.reallySpecial': true\n        },\n        mapReverse: {\n            // the keys of this object are the keys of the mapped object when the mapper is run in reverse\n            // i.e. they match to the model described by the dataMappings values\n            'sourceModel.path.to.array[@_type=Special]': {\n                type: 'Special',\n                reallySpecial: false\n            },\n            // you can call a function too, but it won't get the either the data object or the mapped object as context\n            'sourceModel.timeCreated': Date.now\n        }\n    }\n};\n```\n\n## direction\n\nConceptually, the \"normal\", or **forward**, mapping assumes the object to be mapped is in the format defined by the\n`dataMappings` field's \"values\", and produces an object in the format defined by the `dataMappings` field's keys.\n\nThus, in a similar way, the **reverse** mapping assumes that the object to be mapped is in the format defined by the\n`dataMappings` field's keys, and produces an object in the format defined by the `dataMappings` field's \"values\".\n\n## baseObject options\n\nThe baseObject configuration describes the object that is used as the basis for the mapping. By default the mapper will base the mapping on an empty object, {}.\n\nWhen the map or mapReverse configuration values are the string -- `source`, the mapper will deep clone the source data object and begin mapping using that as the basis.\n\n```\nbaseObject: {\n    map : 'source'\n    mapReverse: 'source'\n}\n```\n\nIn the case where either the `map` or `mapReverse` configurations are functions, the mapper passes the source object as the first argument. The function should return the object to be used as the basis of the mapping.\n\n```\nbaseObject: {\n    map : function (source) {\n        // return the source object as the basis, with the _private attributes removed.\n        return _.omit(source, ['_private']);\n    }\n}\n```\n\n## use\n\n```javascript\nvar modelMapper = require('model-xformer');\n\nvar myMappingConfig = { /* see above ... */ };\nvar myMapper = modelMapper.createMapper(myMappingConfig);\n\n/* ... */\n\n// assuming our \"public\" model is the one in the `dataMappings` field's keys ...\nvar publicModelInstance = myMapper.map(privateModelInstance);\nvar differentPrivateModelInstance = myMapper.mapReverse(anotherPublicModelInstance);\n\n// you can also map an array of objects\nvar publicModelArrayInstance = myMapper.mapArray(privateModelArrayInstance);\nvar differentPrivateModelArrayInstance = myMapper.mapArrayReverse(anotherPublicModelArrayInstance);\n```\n\n## reuse\n\nOften times it's handy to build up complex mappings from smaller mappings.\nA good example of this is object composition, e.g. a \"`Car` _has a_ `Engine`\" relationship.\nIn this case, you can reuse the engine mapper to provide the mapping for that element of the car's mapping.\n\n**engine-mapper.js**\n```javascript\nvar modelMapper = require('model-xformer');\nvar engineMappingConfig = { /* ... */ };\nmodule.exports = modelMapper.createMapper(engineMappingConfig);\n```\n\n**car-mapper.js**\n```javascript\nvar modelMapper = require('model-xformer');\nvar engineMapper = require('./engine-mapper');\nvar carMappingConfig = {\n    /* ... */\n    dataMappings: {\n        /* ... */\n        'engine': 'Mechanical_Systems.Engine',\n        /* ... */\n    },\n    dataTransforms: {\n        /* ... */\n        'engine': engineMapper.map\n        /* ... */\n    }\n    ],\n    /* ... */\n};\nmodule.exports = modelMapper.createMapper(carMappingConfig);\n```\n\nThen, from somewhere else in your code:\n```javascript\nvar carMapper = require('./mappers/car-mapper');\n/* ... */\nvar publicModelInstance = carMapper.map(privateModelInstance);\nvar differentPrivateModelInstance = carMapper.mapReverse(anotherPublicModelInstance);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblueoakjs%2Fmodel-xformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblueoakjs%2Fmodel-xformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblueoakjs%2Fmodel-xformer/lists"}