{"id":17159246,"url":"https://github.com/akuzko/get-lookup","last_synced_at":"2025-07-13T06:32:41.227Z","repository":{"id":140897985,"uuid":"187919166","full_name":"akuzko/get-lookup","owner":"akuzko","description":"JS helper for object deeply nested properties lookup","archived":false,"fork":false,"pushed_at":"2019-08-05T20:43:04.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-25T14:53:19.431Z","etag":null,"topics":["getter","helper","js","lookup","object"],"latest_commit_sha":null,"homepage":null,"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/akuzko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"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}},"created_at":"2019-05-21T21:57:31.000Z","updated_at":"2019-09-02T20:09:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e346d0b-a491-40d6-a319-804cb9d21a3d","html_url":"https://github.com/akuzko/get-lookup","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/akuzko/get-lookup","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fget-lookup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fget-lookup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fget-lookup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fget-lookup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akuzko","download_url":"https://codeload.github.com/akuzko/get-lookup/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fget-lookup/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263833417,"owners_count":23517373,"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":["getter","helper","js","lookup","object"],"created_at":"2024-10-14T22:13:46.839Z","updated_at":"2025-07-06T01:03:58.532Z","avatar_url":"https://github.com/akuzko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"get-lookup\n==========\n\nJS helper for object deeply nested properties lookup. Much like\n[`lodash.get`](https://www.npmjs.com/package/lodash.get), but with some\nadditional useful features.\n\n[![build status](https://img.shields.io/travis/akuzko/get-lookup/master.svg?style=flat-square)](https://travis-ci.org/akuzko/get-lookup)\n[![npm version](https://img.shields.io/npm/v/get-lookup.svg?style=flat-square)](https://www.npmjs.com/package/get-lookup)\n\n## Installation\n\n```\nnpm install --save get-lookup\n```\n\n## Usage\n\nConsidering we have following object:\n\n```js\nconst obj = {\n  foo: {\n    bars: [{\n      bak: 1,\n      baz: 1\n    }, {\n      bak: 1,\n      baz: 2\n    }, {\n      bak: 2,\n      baz: 3\n    }]\n  }\n};\n```\n\n### Basic Usage\n\nPath segments are delimitered by `'.'`.\n\n```js\nimport get from 'get-lookup';\n\nget(obj, 'foo.bars.1.baz'); // =\u003e 2\n```\n\n### Property Lookup Keys\n\nProbably the most useful feature of `get-lookup` is ability to address objects\ninside of arrays by their properties via lookup keys. In the example bellow we\nuse lookup key `{bak:1}`, which resolves to the very first item in `'foo.bars'`\narray:\n\n```js\nget(obj, 'foo.bars.{bak:1}.baz'); // =\u003e 1\n```\n\nIt is also possible to use several fields in property lookup keys to resolve\nambiguity:\n\n```js\nget(obj, 'foo.bars.{bak:1,baz:2}.baz'); // =\u003e 2\n```\n\nNote, however, that lookup keys should be used with simple values since they\nuses `==` comparison.\n\n### Default Value\n\nIf the value resolved by `get` function is `undefined`, the default value, if\nprovided, is returned in its place:\n\n```js\nconst obj = {foo: {bar: 'baz'}};\n\nget(obj, 'foo.baz', 'bak'); // =\u003e 'bak';\n```\n\n### Helpers\n\n`get-lookup` also exports a set of helper functions related to it's internal\nlogic, but that may come in handy sometimes:\n\n```js\nimport { isLookupKey, lookupIndex } from 'get-lookup';\n```\n\n- `isLookupKey(key)` - returns `true` if `key` represents a property lookup key.\n- `lookupIndex(array, key)` - returns an integer index of the element of the\n  given `array` that is identified by lookup key `key`. Returns `-1` if no\n  corresponding element is found.\n\n### Configuration\n\nIt is also possible to set custom value for lookup key term `RegExp`. A term is\na part of the lookup key that represents property or value. Two terms together\nwith semicolon between them represent a segment. One or more segments separated\nby commas and surrounded by curly braces represent lookup key itself.\n\nTo set custom term regular expression simply assign `lookupTermRegExp` property\nto `get` function itself:\n\n```js\nimport get, { isLookupKey } from 'get-lookup';\n\nisLookupKey('{foo:b@r}'); // =\u003e false\n\nget.lookupTermRegExp = /[\\w\\d@_-]+/;\n\nisLookupKey('{foo:b@r}'); // =\u003e true\n```\n\nThe default value for lookup key term regexp is `/[\\w\\d_-]+/`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakuzko%2Fget-lookup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakuzko%2Fget-lookup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakuzko%2Fget-lookup/lists"}