{"id":13448582,"url":"https://github.com/micheleriva/mjn","last_synced_at":"2025-04-14T10:33:07.910Z","repository":{"id":57298711,"uuid":"162417414","full_name":"micheleriva/mjn","owner":"micheleriva","description":"⚡️Like loadash.get, but in ~200 bytes","archived":false,"fork":false,"pushed_at":"2023-01-05T16:50:39.000Z","size":6731,"stargazers_count":68,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T23:41:51.827Z","etag":null,"topics":["error-handling","exception-handling","javascript","js","lodash-get","objects","typescript","undefined-behavior","vanilla-js"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/micheleriva.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["MicheleRiva"],"patreon":"micheleriva","custom":"https://paypal.me/micheleriva"}},"created_at":"2018-12-19T09:53:01.000Z","updated_at":"2025-01-20T10:13:57.000Z","dependencies_parsed_at":"2023-02-04T07:46:28.446Z","dependency_job_id":null,"html_url":"https://github.com/micheleriva/mjn","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/micheleriva%2Fmjn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleriva%2Fmjn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleriva%2Fmjn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/micheleriva%2Fmjn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/micheleriva","download_url":"https://codeload.github.com/micheleriva/mjn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862718,"owners_count":21173867,"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":["error-handling","exception-handling","javascript","js","lodash-get","objects","typescript","undefined-behavior","vanilla-js"],"created_at":"2024-07-31T05:01:49.596Z","updated_at":"2025-04-14T10:33:07.869Z","avatar_url":"https://github.com/micheleriva.png","language":"TypeScript","funding_links":["https://github.com/sponsors/MicheleRiva","https://patreon.com/micheleriva","https://paypal.me/micheleriva","https://github.com/sponsors/micheleriva"],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/docs/mjn_logo.png\" width=\"150px\"\u003e\n\u003c/div\u003e\n\n\u003ch6 align=\"center\"\u003e\nSimple utility to check if a key or a value exists in an object.\n\u003c/h6\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/micheleriva/mjn\"\u003e\n    \u003cimg src=\"https://img.shields.io/travis/micheleriva/mjn.svg?style=for-the-badge\" alt=\"Build Status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/micheleriva/mjn\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/micheleriva/mjn.svg?style=for-the-badge\" alt=\"Coverage\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codeclimate.com/github/micheleriva/mjn\"\u003e\n    \u003cimg src=\"https://img.shields.io/codeclimate/maintainability/micheleriva/mjn.svg?style=for-the-badge\" alt=\"Maintainability\"\u003e\n  \u003c/a\u003e\n  \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dt/mjn?style=for-the-badge\"\u003e\n  \u003cbr /\u003e\n  \u003ca href=\"https://github.com/prettier/prettier\"\u003e\n     \u003cimg src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://img.shields.io/badge/speed-blazing%20%F0%9F%94%A5-brightgreen.svg?style=for-the-badge\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/speed-blazing%20%F0%9F%94%A5-brightgreen.svg?style=for-the-badge\" alt=\"Blazing Fast\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://bundlephobia.com/result?p=mjn@latest\"\u003e\n    \u003cimg src=\"https://img.shields.io/bundlephobia/minzip/mjn.svg?style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://beerpay.io/micheleriva/mjn\"\u003e\n    \u003cimg src=\"https://img.shields.io/beerpay/micheleriva/mjn.svg?style=for-the-badge\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"/docs/mjn.png\" align=\"center\" style=\"max-width:80%;\" /\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n# Sponsors\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://graphcms.com?utm_source=https://github.com/micheleriva/krabs\"\u003e\n    \u003cimg src=\"/docs/sponsor-graphcms.svg\" alt=\"GraphCMS\" target=\"_blank\" width=\"250px\" /\u003e\n  \u003c/a\u003e\n\n  \u003cbr /\u003e\n  \u003ca align=\"center\" href=\"https://github.com/sponsors/micheleriva\" target=\"_blank\"\u003e\n    \u003cb\u003eBecome a sponsor\u003c/b\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\u003cbr /\u003e\n\n\u003e No `cannot get property x of undefined`. Just returns `void 0` (undefined) if a value or a key does not exist. Highly inspired from Java's Optional Type.\n\n# Index\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Simple Example](#simple-example)\n  - [Real World React Example](#real-world-react-example)\n- [Demos](#demos)\n- [License](#license)\n\n# Installation\n\n**yarn**\n\n```sh\nyarn add mjn\n```\n\n**npm**\n\n```sh\nnpm install --save mjn\n```\n\n**cdn**\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/mjn@latest/dist/dist.min.js\"\u003e\u003c/script\u003e\n```\n\n# Usage\n\n### Simple Example\n\n```js\nimport maybe from \"mjn\"; // Or import the library as you wish using npm or CDN script tag!\n\nconst myObject = {\n  user: {\n    name: \"John\",\n    surname: \"Doe\",\n    birthday: \"1995-01-29\",\n    contacts: {\n      email: \"foo@bar.com\",\n      phone: \"000 0000000\"\n    },\n    languages: [\"english\", \"italian\"]\n  }\n};\n\nconst a = maybe(myObject, \"user.name\");\nconst b = maybe(myObject, \"user.languages[1]\");\nconst c = maybe(myObject, \"foo.bar.baz\");\nconst d = maybe(myObject, \"foo.bar.baz\", \"no value!\");\nconst e = maybe(myObject, \"foo.bar.baz\", () =\u003e \"I can be a function!\");\n\n\nconsole.log(a); // =\u003e John\nconsole.log(b); // =\u003e italian\nconsole.log(c); // =\u003e won't log anything!\nconsole.log(d); // =\u003e \"no value!\"\nconsole.log(e); // =\u003e \"I can be a function!\"\n```\n\n### Real World React Example\n\n```jsx\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport maybe from \"mjn\";\n\nconst user = {\n  name: {\n    first_name: \"John\",\n    last_name: \"Doe\"\n  },\n  contacts: {\n    phone: \"+00 000 0000000\",\n    email: \"john@doe.do\"\n  }\n};\n\nconst App = () =\u003e (\n  \u003cdiv className=\"App\"\u003e\n    \u003ch1\u003eHello {maybe(user, \"name.first_name\")}!\u003c/h1\u003e\n    \u003ch2\u003e {maybe(user, \"contacts.email\")} \u003c/h2\u003e\n\n    \u003cp\u003e\n      {maybe(user, \"contacts.phone.office\", \"You don't have an office phone.\")}\n    \u003c/p\u003e\n  \u003c/div\u003e\n);\n\nconst rootElement = document.getElementById(\"root\");\nReactDOM.render(\u003cApp /\u003e, rootElement);\n```\n\n# Demos\n\n### React.js\n\n[![React Example](/docs/react.png)](https://codesandbox.io/s/l71m022x99)\n[![Edit l71m022x99](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/l71m022x99)\n\n### Vue.js\n\n[![Vue Example](/docs/vue.png)](https://codesandbox.io/s/6j7438n7rr?module=%2Fsrc%2Fcomponents%2FHelloWorld.vue)\n[![Edit Vue Template](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/6j7438n7rr?module=%2Fsrc%2Fcomponents%2FHelloWorld.vue)\n\n### Vanilla JS\n\n[![Vanilla JS](/docs/vanillajs.png)](https://codesandbox.io/s/30w08xl6wq?module=%2Fsrc%2Findex.js)\n[![Vanilla JS](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/30w08xl6wq?module=%2Fsrc%2Findex.js)\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://www.micheleriva.it\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/14977595?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMichele Riva\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/micheleriva/mjn/commits?author=micheleriva\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#business-micheleriva\" title=\"Business development\"\u003e💼\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://www.iamoctod.com/\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/2328211?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ePaolo Roth\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/micheleriva/mjn/commits?author=OctoD\" title=\"Code\"\u003e💻\u003c/a\u003e\u003c/td\u003e\n    \u003ctd align=\"center\"\u003e\u003ca href=\"https://equinusocio.dev\"\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/10454741?v=4\" width=\"100px;\" alt=\"\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMattia Astorino\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#design-equinusocio\" title=\"Design\"\u003e🎨\u003c/a\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n# License\n\n[MIT](/LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicheleriva%2Fmjn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicheleriva%2Fmjn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicheleriva%2Fmjn/lists"}