{"id":27110104,"url":"https://github.com/jirufik/pathexists","last_synced_at":"2025-04-06T23:49:30.313Z","repository":{"id":36496908,"uuid":"227895871","full_name":"jirufik/pathExists","owner":"jirufik","description":"Get the value of an object along the path.","archived":false,"fork":false,"pushed_at":"2023-01-05T02:57:49.000Z","size":686,"stargazers_count":0,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T17:37:00.411Z","etag":null,"topics":["jrf","jrf-path-exists","object","path"],"latest_commit_sha":null,"homepage":"","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/jirufik.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":"2019-12-13T18:04:39.000Z","updated_at":"2019-12-26T15:43:42.000Z","dependencies_parsed_at":"2023-01-17T02:03:45.804Z","dependency_job_id":null,"html_url":"https://github.com/jirufik/pathExists","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/jirufik%2FpathExists","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirufik%2FpathExists/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirufik%2FpathExists/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirufik%2FpathExists/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jirufik","download_url":"https://codeload.github.com/jirufik/pathExists/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247569134,"owners_count":20959758,"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":["jrf","jrf-path-exists","object","path"],"created_at":"2025-04-06T23:49:29.822Z","updated_at":"2025-04-06T23:49:30.302Z","avatar_url":"https://github.com/jirufik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Does the object have a path\n\n`npm i jrf-path-exists`\n\nGet the value of an object along the path. \n\nIf the path does not exist, then `undefined` or the `default value` will be returned.\n\n```js\n/**\n  *  Get the value of an object along the path.\n  *  @param {object} obj - object\n  *  @param {string} path - path\n  *  @param {*} [defaultValue] - default value\n  */\npathExists(obj, path, defaultValue);\n```\n\n```js\nconst user = response \u0026\u0026 response.data \u0026\u0026 response.data.nodes \u0026\u0026 response.data.nodes[0] \u0026\u0026 response.data.nodes[0].builds \u0026\u0026 response.data.nodes[0].builds[0] \u0026\u0026 response.data.nodes[0].builds[0].user;\nconst user = pathExists(response, 'response.data.nodes[0].builds[0].user');\n\nlet user = response \u0026\u0026 response.data \u0026\u0026 response.data.nodes \u0026\u0026 response.data.nodes[0] \u0026\u0026 response.data.nodes[0].builds \u0026\u0026 response.data.nodes[0].builds[0] \u0026\u0026 response.data.nodes[0].builds[0].user;\nuser = user || {username: ''};\nconst user = pathExists(response, 'response.data.nodes[0].builds[0].user', {username: ''});\n```\n\n```js\nconst pathExists = require('jrf-path-exists');\n\nconst obj = {\n  a: {\n    b: {\n      c: 'hello world'\n    }\n  },\n  d: {\n    arr: ['hello', 'world', {a: 8, b: ['one', 'two', 'three']}, ['q', 'w', 'r', ['h', 'l', 'o']]]\n  },\n  e: ['one el', 'two el']\n};\n\nconst b = 'b';\n\nconsole.log(pathExists(obj, 'a.b.c', null));     // --\u003e 'hello world'\nconsole.log(pathExists(obj, `a[${b}].c`));       // --\u003e 'hello world'\nconsole.log(pathExists(obj, `a.${b}.c`));        // --\u003e 'hello world'\nconsole.log(pathExists(obj, 'a.b.c.d.s'));       // --\u003e undefined\nconsole.log(pathExists(obj, 'd.arr[2].b[1]'));   // --\u003e 'two'\nconsole.log(pathExists(obj, 'd.arr[3].3.2'));    // --\u003e 'o'\nconsole.log(pathExists(obj, 'd.arr[3][3][2]'));  // --\u003e 'o'\nconsole.log(pathExists(obj, 'e[1]'));            // --\u003e 'two el'\nconsole.log(pathExists(obj, 'e[4]'));            // --\u003e undefined\nconsole.log(pathExists(obj, 'e[4]', null));      // --\u003e null\nconsole.log(pathExists(obj, 'e[4]', false));     // --\u003e false\nconsole.log(pathExists(obj, 'e[4]', 0));         // --\u003e 0\nconsole.log(pathExists(obj, 'e[4]', []));        // --\u003e []\nconsole.log(pathExists(obj, 'e[4]', ''));        // --\u003e ''\nconsole.log(pathExists(obj, 'e[4]', {}));        // --\u003e {}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjirufik%2Fpathexists","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjirufik%2Fpathexists","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjirufik%2Fpathexists/lists"}