{"id":13394480,"url":"https://github.com/facebook/idx","last_synced_at":"2025-09-30T03:30:35.645Z","repository":{"id":38693337,"uuid":"83478722","full_name":"facebook/idx","owner":"facebook","description":"Library for accessing arbitrarily nested, possibly nullable properties on a JavaScript object.","archived":true,"fork":false,"pushed_at":"2024-01-10T18:53:12.000Z","size":1894,"stargazers_count":1686,"open_issues_count":0,"forks_count":52,"subscribers_count":29,"default_branch":"main","last_synced_at":"2025-09-16T00:39:39.630Z","etag":null,"topics":[],"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/facebook.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-02-28T21:01:36.000Z","updated_at":"2025-08-27T13:35:32.000Z","dependencies_parsed_at":"2023-02-08T17:32:05.817Z","dependency_job_id":"be44604c-1d72-44d8-b805-00afcc669793","html_url":"https://github.com/facebook/idx","commit_stats":{"total_commits":184,"total_committers":22,"mean_commits":8.363636363636363,"dds":0.5271739130434783,"last_synced_commit":"3ea94e28a21a81e9682d9df67710544592b2697d"},"previous_names":["facebookincubator/idx"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/facebook/idx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fidx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fidx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fidx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fidx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/facebook","download_url":"https://codeload.github.com/facebook/idx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/facebook%2Fidx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276019676,"owners_count":25571382,"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-09-19T02:00:09.700Z","response_time":108,"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":[],"created_at":"2024-07-30T17:01:21.142Z","updated_at":"2025-09-30T03:30:35.363Z","avatar_url":"https://github.com/facebook.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# idx\n\n**This module is deprecated and no longer maintained. Use [optional chaining](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Optional_chaining) instead.**\n\n`idx` is a utility function for traversing properties on objects and arrays,\nwhere intermediate properties may be null or undefined.\n\nOne notable difference between `idx` and optional chaining is what happens when\nan intermediate property is null or undefined. With `idx`, the null or undefined\nvalue is returned, whereas optional chaining would resolve to undefined.\n\n## Install\n\n```shell\n$ npm install idx babel-plugin-idx\n```\n\nor\n\n```shell\n$ yarn add idx babel-plugin-idx\n```\n\n[Configure Babel](https://babeljs.io/docs/en/configuration) to include the\n`babel-plugin-idx` Babel plugin.\n\n```javascript\n{\n  plugins: [['babel-plugin-idx']];\n}\n```\n\nThis is necessary for `idx` to behave correctly\nwith minimal performance impact.\n\n## Usage\n\nConsider the following type for `props`:\n\n```javascript\ntype User = {\n  user: ?{\n    name: string,\n    friends: ?Array\u003cUser\u003e,\n  },\n};\n```\n\nGetting to the friends of my first friend would resemble:\n\n```javascript\nprops.user \u0026\u0026\n  props.user.friends \u0026\u0026\n  props.user.friends[0] \u0026\u0026\n  props.user.friends[0].friends;\n```\n\nInstead, `idx` allows us to safely write:\n\n```javascript\nidx(props, _ =\u003e _.user.friends[0].friends);\n```\n\nThe second argument must be a function that returns one or more nested member\nexpressions. Any other expression has undefined behavior.\n\n## Static Typing\n\n[Flow](https://flow.org/) and [TypeScript](https://www.typescriptlang.org/)\nunderstand the `idx` idiom:\n\n```javascript\n// @flow\n\nimport idx from 'idx';\n\nfunction getName(props: User): ?string {\n  return idx(props, _ =\u003e _.user.name);\n}\n```\n\n**If you use `idx@3+`,** you may need to add the following to your `.flowconfig`:\n\n```\n[options]\nconditional_type=true\nmapped_type=true\n```\n\n## Babel Plugin\n\nThe `idx` runtime function exists for the purpose of illustrating the expected\nbehavior and is not meant to be executed. The `idx` function requires the use of\na Babel plugin that replaces it with an implementation that does not depend on\ndetails related to browser error messages.\n\nThis Babel plugin searches for requires or imports to the `idx` module and\nreplaces all its usages, so this code:\n\n```javascript\nimport idx from 'idx';\n\nfunction getFriends() {\n  return idx(props, _ =\u003e _.user.friends[0].friends);\n}\n```\n\ngets transformed to something like:\n\n```javascript\nfunction getFriends() {\n  return props.user == null\n    ? props.user\n    : props.user.friends == null\n    ? props.user.friends\n    : props.user.friends[0] == null\n    ? props.user.friends[0]\n    : props.user.friends[0].friends;\n}\n```\n\nNote that the original `import` gets also removed.\n\nIt's possible to customize the name of the import/require, so code that is not\ndirectly requiring the `idx` npm package can also get transformed:\n\n```javascript\n{\n  plugins: [\n    [\n      'babel-plugin-idx',\n      {\n        importName: './idx',\n      },\n    ],\n  ];\n}\n```\n\n## License\n\n`idx` is [MIT licensed](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebook%2Fidx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffacebook%2Fidx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffacebook%2Fidx/lists"}