{"id":18292327,"url":"https://github.com/jay-es/nano-match","last_synced_at":"2026-02-02T04:38:43.093Z","repository":{"id":219943648,"uuid":"749852171","full_name":"jay-es/nano-match","owner":"jay-es","description":"`nano-match` is a tiny utility simplifying key-based matching in TypeScript, bringing elegance to your code.","archived":false,"fork":false,"pushed_at":"2024-01-30T14:25:09.000Z","size":25,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-04T22:32:15.478Z","etag":null,"topics":["pattern-matching","switch-case","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@jay-es/nano-match","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/jay-es.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-01-29T14:26:22.000Z","updated_at":"2024-02-01T04:54:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"f88b257d-1b9c-4675-9619-26161e7d4a12","html_url":"https://github.com/jay-es/nano-match","commit_stats":null,"previous_names":["jay-es/nano-match"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jay-es/nano-match","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-es%2Fnano-match","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-es%2Fnano-match/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-es%2Fnano-match/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-es%2Fnano-match/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jay-es","download_url":"https://codeload.github.com/jay-es/nano-match/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-es%2Fnano-match/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29005541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T04:25:24.522Z","status":"ssl_error","status_checked_at":"2026-02-02T04:24:51.069Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["pattern-matching","switch-case","typescript"],"created_at":"2024-11-05T14:17:44.350Z","updated_at":"2026-02-02T04:38:43.085Z","avatar_url":"https://github.com/jay-es.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nano-match 🎯\n\n`nano-match` is a tiny utility simplifying key-based matching in TypeScript, bringing elegance to your code.\n\n## Installation 🚀\n\n```bash\nnpm install @jay-es/nano-match\n```\n\n## Usage 🛠\n\n### match ✨\n\n```typescript\nimport { match } from '@jay-es/nano-match';\n\ntype Language = 'en' | 'es' | 'fr';\n\nconst lang: Language = 'en';\n\n// Strict matching, only allows valid keys of type 'Language'.\nconst greeting = match(lang, {\n  en: \"Hello.\",\n  es: \"Hola.\",\n  fr: \"Bonjour.\",\n});\n\nconsole.log(greeting); // Output: Hello. (Type: \"Hello.\" | \"Hola.\" | \"Bonjour.\")\n```\n\n## Type Safety 🛡\n\n- `match` enforces type safety by allowing only valid keys. It ensures that the provided key is of the specified type.\n\n```typescript\n// Compilation error: 'de' is not a valid key of type 'Language'.\nconst strictGreeting = match('de', {\n  en: \"Hello.\",\n  es: \"Hola.\",\n  fr: \"Bonjour.\",\n});\n```\n\n### Additional Example 🚀\n\n```typescript\n// Using `match` with numeric keys\nconst message = match(200, {\n  200: \"OK\",\n  404: \"Not Found\",\n  500: \"Internal Server Error\",\n});\n\nconsole.log(message); // Output: OK (Type: \"OK\" | \"Not Found\" | \"Internal Server Error\")\n```\n\n## Additional Feature 🌟\n\n`nano-match` also provides the following function:\n\n### looseMatch 🎈\n\nAs an additional feature, `looseMatch` allows for more flexible matching that accepts keys outside the specified type, returning `undefined` for keys that do not match.\n\n```typescript\nimport { looseMatch } from '@jay-es/nano-match';\n\n// Loose matching, allows keys outside the specified type, returning undefined for non-matching keys.\nconst nonMatchingKey: string = 'de';\nconst looseGreeting = looseMatch(nonMatchingKey, {\n  en: \"Hello.\",\n  es: \"Hola.\",\n  fr: \"Bonjour.\",\n});\n\nconsole.log(looseGreeting); // Output: undefined (Type: \"Hello.\" | \"Hola.\" | \"Bonjour.\" | undefined)\n```\n\n## License 📄\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjay-es%2Fnano-match","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjay-es%2Fnano-match","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjay-es%2Fnano-match/lists"}