{"id":16439161,"url":"https://github.com/posva/shapify","last_synced_at":"2025-04-06T20:12:49.265Z","repository":{"id":34307561,"uuid":"177116241","full_name":"posva/shapify","owner":"posva","description":"🌀Easily transform objects/rename keys with full TypeScript support","archived":false,"fork":false,"pushed_at":"2025-03-21T23:12:41.000Z","size":809,"stargazers_count":68,"open_issues_count":7,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T18:08:32.694Z","etag":null,"topics":["functional","javascript","typescript","utility"],"latest_commit_sha":null,"homepage":"","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/posva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/funding.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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},"funding":{"github":"posva"}},"created_at":"2019-03-22T10:00:16.000Z","updated_at":"2024-03-19T19:08:31.000Z","dependencies_parsed_at":"2023-01-15T06:13:11.577Z","dependency_job_id":"eae999d5-9e28-402a-8ef0-3474b4a5f61d","html_url":"https://github.com/posva/shapify","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fshapify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fshapify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fshapify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posva%2Fshapify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posva","download_url":"https://codeload.github.com/posva/shapify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247543593,"owners_count":20955865,"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":["functional","javascript","typescript","utility"],"created_at":"2024-10-11T09:08:16.306Z","updated_at":"2025-04-06T20:12:49.244Z","avatar_url":"https://github.com/posva.png","language":"JavaScript","readme":"# shapify [![Build Status](https://badgen.net/circleci/github/posva/shapify)](https://circleci.com/gh/posva/shapify) [![npm package](https://badgen.net/npm/v/shapify)](https://www.npmjs.com/package/shapify) [![coverage](https://badgen.net/codecov/c/github/posva/shapify)](https://codecov.io/github/posva/shapify) [![thanks](https://badgen.net/badge/thanks/♥/pink)](https://github.com/posva/thanks)\n\n\u003e Easily reshape objects with TS support\n\n## Installation\n\n```sh\nnpm install shapify\n# or\nyarn install shapify\n```\n\n## Usage\n\n### Basic usage\n\nGiven an array of users:\n\n```js\nconst users = [\n  { fullname: 'Eduardo San Martin morote', id: 1, more: 'properties', that: 'exist', but: \"you don't always need\"]},\n  // more users\n]\n```\n\nYou can transform objects\n\n```js\nimport { shapify } from 'shapify'\n\nconst reshapedUser = shapify(\n  {\n    text: 'fullname',\n    value: 'id',\n  },\n  users[0]\n)\n/**\n * only text and value are present\n * { text: 'Eduardo San Martin Morote', value: 1 }\n */\n```\n\n### Functional approach\n\nThis can be used to transform whole arrays of objects:\n\n```js\nimport { shapify, shaper } from 'shapify'\n// create a function with the first parameter fixed\nconst userShaper = shaper({ text: 'fullname', value: 'id' })\n// equivalent to\nconst sameUserShaper = shapify.bind(null, { text: 'fullname', value: 'id' })\n\n// generate the new array\nconst userChoices = users.map(userShaper)\n```\n\n**⚠️: (#3) this breaks typings (mark them as `unknown`), if you know how to make it work, please file a PR**\n\n### Customizing the new value\n\nIf you want to customize the value instead of just using the original one, you can provide a function:\n\n```js\nconst reshapedUser = shapify(\n  {\n    text: 'fullname',\n    value: user =\u003e 'id: ' + user.id,\n  },\n  users[0]\n)\n/**\n * only text and value are present\n * { text: 'Eduardo San Martin Morote', value: 'id: 1' }\n */\n```\n\n### Keeping original keys/values\n\nIf you need to keep original keys, you can provide a key with the same value:\n\n```js\nshapify({ id: 'id' }, users[0])\n```\n\nBut a more appropriate syntax is an array of keys (strings, numbers or symbols):\n\n```js\nshapify(['id', 'fullname'], users[0])\n```\n\nThis is similar to [`lodash.pick(users[0], ['id', 'fullname'])`](https://lodash.com/docs#pick). However, because shapify is type safe, it cannot support paths as strings as `lodash.pick` does. Instead you need to use a function.\n\nIf you need to keep **all of the original keys**, there is a helper that you can use:\n\n```js\nimport { shapify, keepKeys } from 'shapify'\n\n// this will generate a user object with all of the original properties as well\n// as text with fullname's value\nshapify(\n  {\n    ...keepKeys(users[0]),\n    text: 'fullname',\n  },\n  users[0]\n)\n```\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT)\n","funding_links":["https://github.com/sponsors/posva"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposva%2Fshapify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposva%2Fshapify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposva%2Fshapify/lists"}