{"id":18824150,"url":"https://github.com/gastonpereyra/objects-normalizer","last_synced_at":"2026-01-06T19:05:03.797Z","repository":{"id":57312987,"uuid":"288306954","full_name":"gastonpereyra/objects-normalizer","owner":"gastonpereyra","description":"Normalizes object keys, to have all the same keys","archived":false,"fork":false,"pushed_at":"2021-09-11T22:25:39.000Z","size":194,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T15:47:47.532Z","etag":null,"topics":["nodejs","normalize","objects"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/objects-normalizer","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/gastonpereyra.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":"2020-08-17T23:23:07.000Z","updated_at":"2021-09-12T17:18:56.000Z","dependencies_parsed_at":"2022-09-20T23:22:02.384Z","dependency_job_id":null,"html_url":"https://github.com/gastonpereyra/objects-normalizer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":"gastonpereyra/npm-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fobjects-normalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fobjects-normalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fobjects-normalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gastonpereyra%2Fobjects-normalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gastonpereyra","download_url":"https://codeload.github.com/gastonpereyra/objects-normalizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248807499,"owners_count":21164694,"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":["nodejs","normalize","objects"],"created_at":"2024-11-08T00:55:42.105Z","updated_at":"2026-01-06T19:05:03.759Z","avatar_url":"https://github.com/gastonpereyra.png","language":"JavaScript","readme":"# Objects Normalizer\n\n## Code Quality Status\n![Build Status](https://github.com/gastonpereyra/objects-normalizer/workflows/Build%20Status/badge.svg)\n[![Coverage Status](https://img.shields.io/coveralls/github/gastonpereyra/objects-normalizer/master.svg)](https://coveralls.io/r/gastonpereyra/objects-normalizer?branch=master)\n\n![npm-object-normalizer](https://user-images.githubusercontent.com/39351850/90986214-66554080-e557-11ea-9497-8262238b8e08.png)\n\n## Description\nNormalizes object keys, to have all the same ones\n\n## Installation\n\n```\nnpm i objects-normalizer\n```\n\n## Params\n\n### items\n\n*Object* or *Array of Objects*.\n\nThe set of data to normalize.\n\n#### Conditions\n\n* If set is empty, return an empty list.\n* If only one object is passed, only one object is return\n* List of objects, returns a list of objects\n\n#### Examples\n\nSingle Object\n\n```json\n{\n    \"name\": \"Kamala Khan\",\n    \"alterego\": \"Miss Marvel\",\n    \"superpower\": \"super-stretch\"\n}\n\n```\n\nList of Objects\n\n```json\n[\n    {\n        \"name\": \"Kamala Khan\",\n        \"alterego\": \"Miss Marvel\",\n        \"superpower\": \"super-stretch\"\n    },\n    {\n        \"name\": \"Lois Lane\",\n        \"alterego\": \"Lois Lane\",\n        \"superpower\": \"press\",\n        \"city\": \"Metropolis\"\n    },\n]\n\n```\n\n### options\n\n*Object*.\n\nThe way to normalize.\n\n* `fieldsToKeep`: *array of strings*, list of fields to keep after formatting.\n* `fieldsToRemove`: *array of strings*, list of fields to remove.\n\n#### Conditions\n\n* Only one of them, if both is passed, `fieldsToKeep` has priority, an will be considered the only option.\n* If any of them is passed, or another non-supported property, or nothing is passed, will return the same object or objects without modifications.\n\n#### Examples\n\n```json\n{\n    \"fieldsToKeep\": [\"name\", \"city\"]\n}\n```\n\n```json\n{\n    \"fieldsToRemove\": [\"name\", \"city\"]\n}\n```\n\n## Usage\n\n### objectNormalizer(items)\n\nItems without any option or valid options.\n\n```js\nconst objectsNormalizer = require('objects-normalizer');\n\nobjectsNormalizer({ name: 'Bruce Wayne', alterego: 'Batman', superPower: 'money' });\n\n// It's equivalent\nobjectsNormalizer({ name: 'Bruce Wayne', alterego: 'Batman', superPower: 'money' }, {});\nobjectsNormalizer({ name: 'Bruce Wayne', alterego: 'Batman', superPower: 'money' }, { fieldsToDuplicate: ['city']});\n\n/*\n    output: \n    {\n        name: 'Bruce Wayne',\n        alterego: 'Batman',\n        superPower: 'money'\n    }\n*/\n```\n\n### objectsNormalizer(items, { fieldsToKeep: [fields] })\n\nFormat items to only keep some fields. If these fields not exist in the items, will not be added.\n\n```js\nconst objectsNormalizer = require('objects-normalizer');\n\nconst superHeroes = [\n    { name: 'Bruce Wayne', alterego: 'Batman', superPower: 'money', city: 'Gotham' },\n    { name: 'Peter Parker', alterego: 'Spiderman', superPower: 'spider things but stronger', city: 'New York' },\n    { name: 'Zatanna Zatara', alterego: 'Zatanna', superPower: 'magic'},\n    { name: 'Ororo Monroe', alterego: 'Storm', superPower: 'weather control' }\n];\n\nobjectsNormalizer(superHeroes, { fieldsToKeep:['name', 'city'] });\n\n// It's equivalent\nobjectsNormalizer(superHeroes, { fieldsToKeep:['name', 'city'], fieldsToRemove: ['alterego', 'superPower'] });\nobjectsNormalizer(superHeroes, { fieldsToKeep:['name', 'city'], fieldsToRemove: ['name', 'city'] });\n\n/*\n    output: \n    [\n        { name: 'Bruce Wayne', city: 'Gotham' },\n        { name: 'Peter Parker', city: 'New York' },\n        { name: 'Zatanna Zatara' },\n        { name: 'Ororo Monroe' }\n    ]\n*/\n\nobjectsNormalizer(superHeroes[0], { fieldsToKeep:['name', 'city'] });\n\n/*\n    output: { name: 'Bruce Wayne', city: 'Gotham' }\n*/\n```\n\n### objectsNormalizer(items, { fieldsToRemove: [fields] })\n\nFormat items to remove some fields and keep the others.\n\n```js\nconst objectsNormalizer = require('objects-normalizer');\n\nconst superHeroes = [\n    { name: 'Bruce Wayne', alterego: 'Batman', superPower: 'money', city: 'Gotham' },\n    { name: 'Peter Parker', alterego: 'Spiderman', superPower: 'spider things but stronger', city: 'New York' },\n    { name: 'Zatanna Zatara', alterego: 'Zatanna', superPower: 'magic'},\n    { name: 'Ororo Monroe', alterego: 'Storm', superPower: 'weather control' }\n];\n\nobjectsNormalizer(superHeroes, { fieldsToRemove:['name', 'city'] });\n\n/*\n    output: \n    [\n        { alterego: 'Batman', superPower: 'money' },\n        { alterego: 'Spiderman', superPower: 'spider things but stronger' },\n        { alterego: 'Zatanna', superPower: 'magic'},\n        { alterego: 'Storm', superPower: 'weather control' }\n    ]\n*/\n\nobjectsNormalizer(superHeroes[0], { fieldsToRemove:['name', 'city'] });\n\n/*\n    output: { alterego: 'Batman', superPower: 'money' }\n*/\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgastonpereyra%2Fobjects-normalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgastonpereyra%2Fobjects-normalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgastonpereyra%2Fobjects-normalizer/lists"}