{"id":15552207,"url":"https://github.com/bahmutov/change-by-example","last_synced_at":"2025-08-31T00:31:15.750Z","repository":{"id":22957902,"uuid":"97786929","full_name":"bahmutov/change-by-example","owner":"bahmutov","description":"Finds a function that transforms a given object into another given object.","archived":false,"fork":false,"pushed_at":"2025-07-12T00:07:39.000Z","size":57,"stargazers_count":33,"open_issues_count":15,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-23T05:55:23.590Z","etag":null,"topics":["change","map","mapper","object","transform"],"latest_commit_sha":null,"homepage":null,"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/bahmutov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-07-20T03:32:54.000Z","updated_at":"2023-09-08T17:27:40.000Z","dependencies_parsed_at":"2024-04-10T00:21:52.655Z","dependency_job_id":"0f2aea36-7d44-4f9f-aa4e-9a8aa7d6b07b","html_url":"https://github.com/bahmutov/change-by-example","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/bahmutov/change-by-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fchange-by-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fchange-by-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fchange-by-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fchange-by-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/change-by-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fchange-by-example/sbom","scorecard":{"id":223297,"data":{"date":"2025-08-11","repo":{"name":"github.com/bahmutov/change-by-example","commit":"384023bcbd0931883759e9fb3f89f6afc580cdc5"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.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":"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":"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":"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":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","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":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: npmCommand not pinned by hash: next-update-travis.sh:22","Info:   0 out of   1 npmCommand dependencies pinned"],"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":"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":"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":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"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 18 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"}}]},"last_synced_at":"2025-08-17T03:06:56.326Z","repository_id":22957902,"created_at":"2025-08-17T03:06:56.327Z","updated_at":"2025-08-17T03:06:56.327Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272926171,"owners_count":25016423,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["change","map","mapper","object","transform"],"created_at":"2024-10-02T14:12:28.804Z","updated_at":"2025-08-31T00:31:15.496Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","readme":"# change-by-example\n\n\u003e Finds a function that transforms a given object into another given object.\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n[![next-update-travis badge][nut-badge]][nut-readme]\n[![renovate-app badge][renovate-badge]][renovate-app]\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 6 or above.\n\n```sh\nnpm install --save change-by-example\n```\n\n## Use\n\nImagine we have two objects: a source object and a destination object.\nIf we want to transform the source into destination, we have to write the\ntransform function ourselves. We could use shortcuts like\n[Ramda.evolve](http://ramdajs.com/docs/#evolve) or use one of the libs helping\nus write the tranform (like [map-factory](https://github.com/midknight41/map-factory),\n[xform](https://github.com/dvdln/xform), [mapper.js](https://github.com/Jokero/mapper.js).\n[transformo](https://github.com/lutowolk/transformo)). All this is complicated.\n\nWhy can't the computer *compute* the transform that from source -\u003e destination\npair? Well, `change-by-example` is an attempt to do this.\n\nGive it two objects and get back and transform function\n\n```js\nconst change = require('change-by-example')\nconst source = {\n  name: 'john',\n  age: '42',\n  occupation: 'mechanic'\n}\nconst destination = {\n  name: 'John',\n  age: 42\n}\nconst f = change(source, destination)\n```\n\nIf you call this transform function with original source object, you get\nback destination again\n\n```js\nconsole.log(f(source))\n// {name: \"John\", age: 42}\n```\n\nBut if you give it an object of the *same shape as source*, it will transform\nit **the same way**.\n\n```js\nconsole.log(f({\n  name: 'mary',\n  age: '30',\n  occupation: 'engineer'\n}))\n// {name: 'Mary', age: 30}\n```\n\n## Advanced\n\nYou can nest source and destination objects and even pass additional\nunary value transform functions to try. See [spec](src/custom-transforms-spec.js).\n\n## Examples\n\n* Extracting GitHub repo information [by example](examples/github.js)\n\n## Supported\n\n* [x] generates transformation function string representation [#1][1]\n* [x] property delete [spec](src/property-delete-spec.js)\n* [x] property rename [spec](src/property-rename-spec.js)\n* [x] simple string transforms from [Ramda](http://ramdajs.com/docs/)\n  and [Lodash](https://lodash.com/docs/)\n* [x] deep source paths [#3][3]\n* [x] deep destination paths [#7][7]\n* [x] compound transforms like `trim + toLower` [#8][8]\n* [x] extracting from arrays [#9][9] [spec](src/array-spec.js)\n* [x] passing custom transforms to use [#10][10] [spec](src/custom-transforms-spec.js)\n* [ ] combining values like `.fullName = .first` + `.last`\n\n[1]: https://github.com/bahmutov/change-by-example/issues/1\n[3]: https://github.com/bahmutov/change-by-example/issues/3\n[7]: https://github.com/bahmutov/change-by-example/issues/7\n[8]: https://github.com/bahmutov/change-by-example/issues/8\n[9]: https://github.com/bahmutov/change-by-example/issues/9\n[10]: https://github.com/bahmutov/change-by-example/issues/10\n\n## Debugging\n\nRun with environment variable `DEBUG=change-by-example ...`\n\n## Human text\n\nYou can see the human-friendly transformation by printing the\nreturned transform's function. It shows for each destination property\nthe transform and the source property. For above example it would print\n\n```js\nconst source = {\n  name: 'john',\n  age: '42',\n  occupation: 'mechanic'\n}\nconst destination = {\n  name: 'John',\n  age: 42\n}\nconst change = require('change-by-example')\nconst t = change(source, destination)\nconsole.log(t.toString())\n/*\nname: _.capitalize(name)\nage: _.parseInt(age)\n*/\n```\n\nSimilarly, deep paths will be shown using dots\n\n```js\nconst input = {\n  name: 'foo',\n  other: {\n    info: {\n      age: '42'\n    }\n  }\n}\nconst output = {\n  name: {\n    first: 'foo'\n  },\n  age: 42\n}\nconst t = change(input, output)\nconsole.log(t.toString())\n/*\nname.first: R.identity(name)\nage: _.parseInt(other.info.age)\n*/\n```\n\n## Related\n\nThis is much simpler problem that general value to value mapping like I\nam trying to do in [Rambo](https://github.com/bahmutov/rambo)\n\n### Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2017\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](https://glebbahmutov.com)\n* [blog](https://glebbahmutov.com/blog)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/change-by-example/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[npm-icon]: https://nodei.co/npm/change-by-example.svg?downloads=true\n[npm-url]: https://npmjs.org/package/change-by-example\n[ci-image]: https://travis-ci.org/bahmutov/change-by-example.svg?branch=master\n[ci-url]: https://travis-ci.org/bahmutov/change-by-example\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n[nut-badge]: https://img.shields.io/badge/next--update--travis-%E2%9C%94%EF%B8%8F-green.svg\n[nut-readme]: https://github.com/bahmutov/next-update-travis#readme\n[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg\n[renovate-app]: https://renovateapp.com/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fchange-by-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fchange-by-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fchange-by-example/lists"}