{"id":21662485,"url":"https://github.com/nicklason/node-select-properties","last_synced_at":"2025-03-20T05:47:42.517Z","repository":{"id":65493791,"uuid":"144464926","full_name":"Nicklason/node-select-properties","owner":"Nicklason","description":"Specify which properties to include or exclude in an object or an array of objects","archived":false,"fork":false,"pushed_at":"2019-01-03T18:49:07.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-25T14:22:31.738Z","etag":null,"topics":["exclude","fields","include","javascript","node","properties","select"],"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/Nicklason.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-08-12T12:30:08.000Z","updated_at":"2019-01-03T18:47:47.000Z","dependencies_parsed_at":"2023-01-25T21:15:16.839Z","dependency_job_id":null,"html_url":"https://github.com/Nicklason/node-select-properties","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/Nicklason%2Fnode-select-properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicklason%2Fnode-select-properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicklason%2Fnode-select-properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nicklason%2Fnode-select-properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nicklason","download_url":"https://codeload.github.com/Nicklason/node-select-properties/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244560373,"owners_count":20472219,"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":["exclude","fields","include","javascript","node","properties","select"],"created_at":"2024-11-25T10:16:25.298Z","updated_at":"2025-03-20T05:47:42.487Z","avatar_url":"https://github.com/Nicklason.png","language":"JavaScript","readme":"# node-select-properties\n\nSpecify which properties to include or exclude in an object or an array of objects\n\n[![npm](https://img.shields.io/npm/v/select-properties.svg)](https://www.npmjs.com/package/select-properties)\n[![Travis (.org)](https://img.shields.io/travis/Nicklason/node-select-properties.svg)](https://travis-ci.org/Nicklason/node-select-properties)\n[![Coveralls github](https://img.shields.io/coveralls/github/Nicklason/node-select-properties.svg)](https://coveralls.io/github/Nicklason/node-select-properties)\n\n[![npm](https://nodei.co/npm/select-properties.png)](https://nodei.co/npm/select-properties/)\n\n# Introduction\nI made this module to help me use [cachegoose](https://www.npmjs.com/package/cachegoose). I wanted to be able to cache all properties from queries, but only select specific fields. This is because I have two applications using the same [mongodb](https://www.mongodb.com/) and [redis](https://redis.io/) database, but they don't need the same data.\n\nThis module works the same way as mongoose's [select](http://mongoosejs.com/docs/queries.html) function, only difference is that you give it the result, and then give it the fields you want selected.\n\n*This is the reason to why I've made this module, but you can use it to solve your own problems!*\n\nIt can be used \n\n# Examples\n\n```js\nconst selectProperties = require('select-properties');\n\nconst target = { foo: '', bar: '' };\n// Object to select the fields of\n\nconst select = { foo: 0 };\n// Exclude the foo property\n\nconst result = selectProperties(target, select);\n// The result will be { bar: '' }\n```\n\nSelect nested properties using dot notation.\n\n```js\nconst target = {\n    some: {\n        nested: {\n            value: ''\n        },\n        other: {\n            nested: {\n                value: ''\n            }\n        }\n    }\n};\n\nconst select = '-some.nested';\n\nconst result = selectProperties(target, select);\n// The result will be { some: { other: { nested: { value: '' } } } }\n```\n\n---\n**NOTE**\n\nBoth nested paths, and properties, that match the selected field will be targeted.\n\nSee example below.\n\n---\n\n```js\nconst target = {\n    some: {\n        nested: {\n            value: ''\n        },\n        other: {\n            nested: {\n                value: ''\n            }\n        }\n    },\n    'some.nested': {\n        value: ''\n    }\n};\n\nconst select = '-some.nested';\n\nconst result = selectProperties(target, select);\n// The result will be { some: { other: { nested: { value: '' } } } }\n```\n\nSelect the properties of multiple objects.\n\n```js\nconst target = [{ foo: '', bar: '' }, { foo: '', bar: '' }];\n// Array of objects to select the fields of\n\nconst select = { foo: 0 };\n\nconst result = selectProperties(target, select);\n// The result will be [{ bar: '' }, { bar: '' }]\n```\n\nSelect using a string.\n\n```js\nconst select = '-foo';\n// Exclude foo\n```\n\nSelect specific properties.\n\n```js\nconst target = [{ foo: '', bar: '' }, { foo: '', bar: '' }];\n// Array of objects to select the fields of\n\nconst select = { foo: 1 };\n\nconst result = selectProperties(target, select);\n// The result will be [{ foo: '' }, { foo: '' }]\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicklason%2Fnode-select-properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnicklason%2Fnode-select-properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnicklason%2Fnode-select-properties/lists"}