{"id":22281731,"url":"https://github.com/mrodrig/doc-path","last_synced_at":"2025-07-28T20:31:17.561Z","repository":{"id":30731484,"uuid":"34287775","full_name":"mrodrig/doc-path","owner":"mrodrig","description":"A document path library for Node.JS","archived":false,"fork":false,"pushed_at":"2024-07-13T02:00:40.000Z","size":250,"stargazers_count":4,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-28T05:48:05.180Z","etag":null,"topics":["coverage","hacktoberfest","javascript","json-document","nested-paths","setpath"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/mrodrig.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":"2015-04-20T21:33:59.000Z","updated_at":"2024-07-13T02:00:13.000Z","dependencies_parsed_at":"2023-01-14T17:45:23.113Z","dependency_job_id":"36b6ab3f-911a-4852-897d-f8e8d4f12450","html_url":"https://github.com/mrodrig/doc-path","commit_stats":{"total_commits":77,"total_committers":6,"mean_commits":"12.833333333333334","dds":0.7012987012987013,"last_synced_commit":"40413fd9f3e8d7675e9b735e53532d11ee789ad7"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/mrodrig/doc-path","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrodrig%2Fdoc-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrodrig%2Fdoc-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrodrig%2Fdoc-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrodrig%2Fdoc-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrodrig","download_url":"https://codeload.github.com/mrodrig/doc-path/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrodrig%2Fdoc-path/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267580459,"owners_count":24110845,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["coverage","hacktoberfest","javascript","json-document","nested-paths","setpath"],"created_at":"2024-12-03T16:21:22.314Z","updated_at":"2025-07-28T20:31:17.282Z","avatar_url":"https://github.com/mrodrig.png","language":"TypeScript","readme":"# A Document Path Library for Node\n\n[![NPM version](https://img.shields.io/npm/v/doc-path.svg)](https://www.npmjs.org/package/doc-path)\n[![Downloads](https://img.shields.io/npm/dm/doc-path)](https://www.npmjs.org/package/doc-path)\n[![Minzipped Size](https://img.shields.io/bundlephobia/minzip/doc-path)](https://bundlephobia.com/result?p=doc-path)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/mrodrig/doc-path/automated-tests-workflow.yml)](https://github.com/mrodrig/doc-path/actions/workflows/automated-tests-workflow.yml)\n[![Coverage Status](https://coveralls.io/repos/github/mrodrig/doc-path/badge.svg?branch=main)](https://coveralls.io/github/mrodrig/doc-path?branch=main)\n[![Typings](https://img.shields.io/npm/types/doc-path)](https://www.npmjs.org/package/doc-path)\n\nThis module will take paths in documents which can include nested paths specified by '.'s and can evaluate the path\nto a value, or can set the value at that path depending on the function called.\n\n## Installation\n\n```bash\n$ npm install doc-path\n```\n\n## Usage\n\n```javascript\nlet path = require('doc-path');\n```\n\n### API\n\n#### path.evaluatePath(document, key)\n\n* `document` - `Object` - A JSON document that will be iterated over.\n* `key` - `String` - A path to the existing key whose value will be returned.\n  * Note: If your key has a dot in it (eg. `a.b`) then be sure to escape the dot with a blackslash (eg. `a\\\\.b`).\n\nIf the key does not exist, `undefined` is returned.\n\nIf the object's structure is extremely deep, then an error may be thrown if the maximum call stack size is exceeded while traversing the object.\n\n##### path.evaluatePath Example:\n\n```javascript\nconst path = require('doc-path');\n\nlet document = {\n    Make: 'Nissan',\n    Model: 'Murano',\n    Year: '2013',\n    Specifications: {\n        Mileage: '7106',\n        Trim: 'S AWD'\n    },\n    Features: [\n\t\t{\n\t\t    feature: 'A/C',\n\t\t\tpackages: [\n\t\t\t\t{name: 'Base'},\n\t\t\t\t{name: 'Premium'}\n\t\t\t]\n\t\t},\n\t\t{\n\t\t    feature: 'Radio',\n\t\t\tpackages: [\n\t\t\t\t{name: 'Convenience'},\n\t\t\t\t{name: 'Premium'}\n\t\t\t]\n\t\t}\n\t]\n};\n\nconsole.log(path.evaluatePath(document, 'Make'));\n// =\u003e 'Nissan'\n\nconsole.log(path.evaluatePath(document, 'Specifications.Mileage'));\n// =\u003e '7106'\n\nconsole.log(path.evaluatePath(document, 'Features.feature'));\n// =\u003e [ 'A/C', 'Radio' ]\n\nconsole.log(path.evaluatePath(document, 'Features.packages.name'));\n// =\u003e [ ['Base', 'Premium'], ['Convenience', 'Premium'] ]\n```\n\n#### path.setPath(document, key, value)\n\n* `document` - `Object` - A JSON document that will be iterated over.\n* `key` - `String` - A path to the existing key whose value will be set.\n  * Note: If your key has a dot in it (eg. `a.b`) then be sure to escape the dot with a blackslash (eg. `a\\\\.b`).\n* `value` - `*` - The value that will be set at the given key.\n\nIf the key does not exist, then the object will be built up to have that path.\nIf no document is provided, an error will be thrown.\nIf the object's structure is extremely deep, then an error may be thrown if the maximum call stack size is exceeded while traversing the object.\n\n#### path.setPath Example:\n\n ```javascript\n const path = require('doc-path');\n\n let document = {\n     Make: 'Nissan',\n     Features: [\n         { feature: 'A/C' }\n     ]\n };\n\n console.log(path.setPath(document, 'Color.Interior', 'Tan'));\n /*\n\t{ \n\t\tMake: 'Nissan',\n\t\tFeatures: [\n\t\t\t{ feature: 'A/C' }\n\t\t]\n\t\tColor: { \n\t\t\tInterior: 'Tan'\n\t\t}\n\t}\n */\n\n console.log(path.setPath(document, 'StockNumber', '34567'));\n /*\n\t{ \n\t\tMake: 'Nissan',\n\t\tFeatures: [\n\t\t\t{ feature: 'A/C' }\n\t\t]\n\t\tColor: { \n\t\t\tInterior: 'Tan'\n\t\t},\n\t\tStockNumber: '34567'\n\t}\n */\n \n console.log(path.setPath(document, 'Features.cost', '$0 (Standard)'));\n  /*\n \t{ \n\t\tMake: 'Nissan',\n\t\tFeatures: [\n\t\t\t{\n\t\t\t\tfeature: 'A/C',\n\t\t\t\tcost: '$0 (Standard)'\n\t\t\t}\n\t\t]\n\t\tColor: { \n\t\t\tInterior: 'Tan'\n\t\t},\n\t\tStockNumber: '34567'\n \t}\n  */\n ```\n\n## Tests\n\n```bash\n$ npm test\n```\n\n_Note_: This requires `mocha`, `should`, `async`, and `underscore`.\n\nTo see test coverage, please run:\n```bash\n$ npm run coverage\n```\n\nCurrent Coverage is:\n```\nStatements   : 100% ( 33/33 )\nBranches     : 100% ( 24/24 )\nFunctions    : 100% ( 3/3 )\nLines        : 100% ( 29/29 )\n```\n\n## Features\n\n- Supports keys with escaped `.` characters (as of v3.0.0)\n- Supports nested paths\n  - Including keys of objects inside arrays! (as of v2.0.0)\n- Same common path specification as other programs such as MongoDB\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrodrig%2Fdoc-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrodrig%2Fdoc-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrodrig%2Fdoc-path/lists"}