{"id":13394040,"url":"https://github.com/developit/dlv","last_synced_at":"2025-05-14T10:05:18.243Z","repository":{"id":55030809,"uuid":"64888432","full_name":"developit/dlv","owner":"developit","description":"Safe deep property access in 120 bytes. x = dlv(obj, 'a.b.x')","archived":false,"fork":false,"pushed_at":"2020-12-13T17:19:09.000Z","size":26,"stargazers_count":1235,"open_issues_count":10,"forks_count":41,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-30T11:33:26.596Z","etag":null,"topics":["dlv","javascript","key","object"],"latest_commit_sha":null,"homepage":"https://npm.im/dlv","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developit.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}},"created_at":"2016-08-04T00:22:41.000Z","updated_at":"2025-03-21T02:43:55.000Z","dependencies_parsed_at":"2022-08-14T09:40:20.134Z","dependency_job_id":null,"html_url":"https://github.com/developit/dlv","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdlv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdlv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdlv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developit%2Fdlv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developit","download_url":"https://codeload.github.com/developit/dlv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271224,"owners_count":20911584,"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":["dlv","javascript","key","object"],"created_at":"2024-07-30T17:01:06.841Z","updated_at":"2025-04-11T03:30:01.115Z","avatar_url":"https://github.com/developit.png","language":"JavaScript","readme":"# `dlv(obj, keypath)` [![NPM](https://img.shields.io/npm/v/dlv.svg)](https://npmjs.com/package/dlv) [![Build](https://travis-ci.org/developit/dlv.svg?branch=master)](https://travis-ci.org/developit/dlv)\n\n\u003e Safely get a dot-notated path within a nested object, with ability to return a default if the full key path does not exist or the value is undefined\n\n\n### Why?\n\nSmallest possible implementation: only **120 bytes.**\n\nYou could write this yourself, but then you'd have to write [tests].\n\nSupports ES Modules, CommonJS and globals.\n\n\n### Installation\n\n`npm install --save dlv`\n\n\n### Usage\n\n`delve(object, keypath, [default])`\n\n```js\nimport delve from 'dlv';\n\nlet obj = {\n\ta: {\n\t\tb: {\n\t\t\tc: 1,\n\t\t\td: undefined,\n\t\t\te: null\n\t\t}\n\t}\n};\n\n//use string dot notation for keys\ndelve(obj, 'a.b.c') === 1;\n\n//or use an array key\ndelve(obj, ['a', 'b', 'c']) === 1;\n\ndelve(obj, 'a.b') === obj.a.b;\n\n//returns undefined if the full key path does not exist and no default is specified\ndelve(obj, 'a.b.f') === undefined;\n\n//optional third parameter for default if the full key in path is missing\ndelve(obj, 'a.b.f', 'foo') === 'foo';\n\n//or if the key exists but the value is undefined\ndelve(obj, 'a.b.d', 'foo') === 'foo';\n\n//Non-truthy defined values are still returned if they exist at the full keypath\ndelve(obj, 'a.b.e', 'foo') === null;\n\n//undefined obj or key returns undefined, unless a default is supplied\ndelve(undefined, 'a.b.c') === undefined;\ndelve(undefined, 'a.b.c', 'foo') === 'foo';\ndelve(obj, undefined, 'foo') === 'foo';\n```\n\n\n### Setter Counterparts\n\n- [dset](https://github.com/lukeed/dset) by [@lukeed](https://github.com/lukeed) is the spiritual \"set\" counterpart of `dlv` and very fast.\n- [bury](https://github.com/kalmbach/bury) by [@kalmbach](https://github.com/kalmbach) does the opposite of `dlv` and is implemented in a very similar manner.\n\n\n### License\n\n[MIT](https://oss.ninja/mit/developit/)\n\n\n[preact]: https://github.com/developit/preact\n[tests]: https://github.com/developit/dlv/blob/master/test.js\n","funding_links":[],"categories":["JavaScript","Packages","Utilities"],"sub_categories":["Utility","Data Structures"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopit%2Fdlv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevelopit%2Fdlv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevelopit%2Fdlv/lists"}