{"id":21747477,"url":"https://github.com/charlespascoe/subobject","last_synced_at":"2026-05-10T17:03:41.414Z","repository":{"id":57159127,"uuid":"134856002","full_name":"charlespascoe/subobject","owner":"charlespascoe","description":null,"archived":false,"fork":false,"pushed_at":"2018-06-01T10:44:53.000Z","size":41,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-03-17T00:41:55.413Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charlespascoe.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-05-25T12:54:53.000Z","updated_at":"2018-06-01T10:44:55.000Z","dependencies_parsed_at":"2022-09-08T10:40:08.319Z","dependency_job_id":null,"html_url":"https://github.com/charlespascoe/subobject","commit_stats":null,"previous_names":["cpascoe95/subobject"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Fsubobject","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Fsubobject/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Fsubobject/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlespascoe%2Fsubobject/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlespascoe","download_url":"https://codeload.github.com/charlespascoe/subobject/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244722734,"owners_count":20499154,"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":[],"created_at":"2024-11-26T08:09:16.637Z","updated_at":"2026-05-10T17:03:36.379Z","avatar_url":"https://github.com/charlespascoe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Subobject - pick a subset of keys from an object\n\nInstallation:\n\n`$ npm install --save subobject`\n\n## Usage\n\n```ts\nimport { subobject } from 'subobject';\n\n// An example object\nconst user = {\n    id: 123,\n    firstName: 'Bob',\n    otherNames: 'Smith',\n    role: {\n        name: 'Admin',\n        permissions: [\n            {id: 1, 'CAN_CREATE_WIDGETS'},\n            {id: 2, 'CAN_DELETE_WIDGETS'},\n        ]\n    }\n};\n\nconst pickNames = subobject('{firstName, otherNames}');\n\nconsole.log(pickNames(user));\n//{\n//    firstName: 'Bob',\n//    otherNames: 'Smith'\n//}\n\nconst idAndRoleName = subojbect('{id, role: { name }}');\n\nconsole.log(idAndRole(user));\n//{\n//    id: 123,\n//    role: {\n//        name: 'Admin'\n//    }\n//}\n\nconst rolePermissions = subobject('{role: { name, permissions: { id }}}');\n\n// For arrays, the filter is applied to each item\nconsole.log(roleAndPermissions(user))\n//{\n//    role: {\n//        name: 'Admin',\n//        permissions: [\n//            {id: 1},\n//            {id: 2}\n//        ]\n//    }\n//}\n```\n\n## Syntax\n\n```ebnf\nwhitespace = ? Any whitespace character ? ;\n\nsimple_char = 'a'..'z' | 'A'..'Z' | '0'..'9' | '-' | '$' | '_' ;\n\nsimple_key = simple_char, { simple_char } ;\n\ncomplex_key = '\"', ? Backslash-escaped string of characters ?, '\"' ;\n\nkey = simple_key | complex_key ;\n\nexpression = key, [ ':', { whitespace }, object ] ;\n\nobject = \"{\", { whitespace } [ expression, { \",\", { whitespace }, expression } ], { whitespace }, \"}\";\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlespascoe%2Fsubobject","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlespascoe%2Fsubobject","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlespascoe%2Fsubobject/lists"}