{"id":22202149,"url":"https://github.com/rumkin/keyget","last_synced_at":"2025-03-25T00:59:19.544Z","repository":{"id":56178309,"uuid":"62399090","full_name":"rumkin/keyget","owner":"rumkin","description":"Tiny kit for nested objects modification.","archived":false,"fork":false,"pushed_at":"2020-11-23T12:11:59.000Z","size":66,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-13T08:44:59.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/keyget","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/rumkin.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":"2016-07-01T14:36:05.000Z","updated_at":"2021-11-07T20:44:08.000Z","dependencies_parsed_at":"2022-08-15T14:10:28.049Z","dependency_job_id":null,"html_url":"https://github.com/rumkin/keyget","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fkeyget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fkeyget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fkeyget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rumkin%2Fkeyget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rumkin","download_url":"https://codeload.github.com/rumkin/keyget/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245198813,"owners_count":20576448,"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-12-02T16:12:34.586Z","updated_at":"2025-03-25T00:59:19.523Z","avatar_url":"https://github.com/rumkin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keyget\n\n[![npm](https://img.shields.io/npm/v/keyget.svg?style=flat-square)](https://npmjs.com/package/keyget)\n[![Travis](https://img.shields.io/travis/rumkin/keyget.svg?style=flat-square)](https://travis-ci.org/rumkin/keyget)\n\nTiny kit for nested objects modification. It can find, get, set, push or call\nnested properties, create bindings, destructure objects and and construct\nthem back.\n\n## ToC\n\u003c!-- TOC --\u003e\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n  - [`get()`](#get)\n  - [`set()`](#set)\n  - [`push()`](#push)\n  - [`has()`](#has)\n  - [`call()`](#call)\n  - [`method()`](#method)\n  - [`breadcrumbs()`](#breadcrumbs)\n  - [`structure()`](#structure)\n  - [`at()`](#at)\n  - [`Path`](#path)\n  - [`PathArray`](#patharray)\n- [License](#license)\n\n\u003c!-- /TOC --\u003e\n\n\n## Installation\n\nInstall via npm:\n\n```shell\nnpm i keyget\n```\n\n## Usage\n\nUpdate nested object:\n\n```javascript\nimport {get, set, has} from 'keyget';\n\nconst target = {};\n\nif (! has(target, ['user', 'name'])) {\n  set(target, ['user', 'name'], 'Rick Sanchez');\n}\n\nget(target, ['user', 'name']); // -\u003e 'Rick Sanchez'\ntarget; // -\u003e {user: {name: 'Rick Sanchez'}}\n```\n\n## API\n\nEvery method accepts path argument. It should has [Path](#path) or [PathArray](#patharray) type.\n\n### `get()`\n\n```\n(target: *, path: Path) -\u003e *\n```\n\nGet deeply nested property from `target` by `path`, which could be a string\nwith dot as separator or array of path segments.\n\nReturns property value or undefined if there is no such property.\n\n### `set()`\n```\n(target: *, path: Path, value: *) -\u003e *\n```\n\nSet value into `target`. If any `target`'s property on the `path` is not an object,\nreplaces it with the new plain object.\n\nReturns `target`.\n\n### `push()`\n```\n(target: *, path: Path, value: *) -\u003e *\n```\n\nPush value into `target` by path. If any `target`'s property on the `path` is not an object,\nreplaces it with the new plain object. If the target pointed by path is not an array, replace\nit with an array, then push into it.\n\nReturns `target`.\n\n### `has()`\n\n```\n(target: *, path: Path) -\u003e Boolean\n```\n\nCheck wether `path` exists in a `target`.\n\n### `call()`\n\n```\n(target: *, path: Path, arguments: Array) -\u003e *\n```\n\nCall nested method with proper `this` context.\n\nReturns methods result or undefined if method not exists.\n\n### `method()`\n\n```\n(target: *, path: Path) -\u003e function\n```\n\nGet nested method of `target` by `path` and returns method binding with `this`\ncontext set to method's owner object. If method not found, returns no-op\nfunction.\n\n### `breadcrumbs()`\n\n```\n(target: *, path: Path) -\u003e []*\n```\n\nReturns values for each path segment. The first element is always `target`\nitself.\n\n```javascript\nconst target = {\n    a: {\n        b: {\n            c: 1,\n        },\n    },\n};\n\nbreadcrumbs(target, ['a', 'b']); // -\u003e [{a: {b: {c: 1}}}, {b: {c: 1}}, {c: 1}]\n```\n\n### `structure()`\n\n```\n(target: *) -\u003e []{path: PathArray, value: *}\n```\n\nPresent `target` as list of paths and values.\n\nExample:\n\n```javascript\nconst struct = structure({\n    a: {\n        b: {1},\n    }\n});\n\nstruct; // -\u003e [{path: ['a', 'b'], value: 1}]\n```\n\n### `at()`\n\n```\n(target: *, path: Path, update: UpdateFunc) -\u003e *\n\nUpdateFunc:\n  (target: *, key: Number|String) -\u003e *\n```\n\nUpdate deeply nested property of `target` by `path` using `update` function.\nResult of `update` will be used as value of last ancestor. Returns updated\n`target`.\n\n### `Path`\n```\nString|PathArray\n```\n\nExamples:\n```javascript\n// String: Dot separated paths\n'user.name';\n'user.friends.0.id';\n// PathArray: array of keys and indexes\n['user', 'name'];\n['user', 'friends', 0, 'id'];\n```\n\n### `PathArray`\n```\n[]\u003cString|Number\u003e\n```\n\nExamples:\n```javascript\n['user', 'name'];\n['user', 'friends', 0, 'id'];\n```\n\n## License\n\nMIT © [Rumkin](https://rumk.in)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fkeyget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frumkin%2Fkeyget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frumkin%2Fkeyget/lists"}