{"id":23700956,"url":"https://github.com/armadacore/fnt","last_synced_at":"2026-02-08T22:03:31.802Z","repository":{"id":269749131,"uuid":"908232466","full_name":"armadacore/fnt","owner":"armadacore","description":"A collection of utility functions to make your TypeScript code more robust and safer.","archived":false,"fork":false,"pushed_at":"2025-01-04T15:42:02.000Z","size":179,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-20T11:38:41.407Z","etag":null,"topics":["functional-programming","typesafe","typescript","utilities"],"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/armadacore.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-12-25T14:20:16.000Z","updated_at":"2025-01-04T15:51:18.000Z","dependencies_parsed_at":"2024-12-25T21:32:51.255Z","dependency_job_id":null,"html_url":"https://github.com/armadacore/fnt","commit_stats":null,"previous_names":["armadacore/fnt"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/armadacore/fnt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armadacore%2Ffnt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armadacore%2Ffnt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armadacore%2Ffnt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armadacore%2Ffnt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/armadacore","download_url":"https://codeload.github.com/armadacore/fnt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/armadacore%2Ffnt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273391909,"owners_count":25097254,"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-03T02:00:09.631Z","response_time":76,"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":["functional-programming","typesafe","typescript","utilities"],"created_at":"2024-12-30T09:20:32.684Z","updated_at":"2026-02-08T22:03:31.538Z","avatar_url":"https://github.com/armadacore.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![GitHub package.json version](https://img.shields.io/github/package-json/v/armadacore/fnt)\n![GitHub License](https://img.shields.io/github/license/armadacore/fnt)\n[![codecov](https://codecov.io/gh/armadacore/fnt/graph/badge.svg?token=RKG5TLD6LJ)](https://codecov.io/gh/armadacore/fnt)\n![GitHub repo size](https://img.shields.io/github/repo-size/armadacore/fnt)\n\n\n# fnt - Functional TypeScript\n\n**fnt** (Functional TypeScript) is a collection of utility functions designed to make your code more robust and safer. The project is built with TypeScript and provides tools to effectively apply functional programming concepts in TypeScript.\n\n---\n\n## Installation\n\nYou can easily install fnt via npm:\n\n```bash\nnpm install @armadacore/fnt\n```\n\nImport the required functions directly into your TypeScript files:\n\n```typescript\nimport { ok, err } from '@armadacore/fnt';\n```\n\n---\n\n## Example: Result Pattern\n\nThe `Result` pattern is a powerful and explicit way to handle errors in your code, making functions safer and reducing reliance on exceptions. This pattern is inspired by the `Result` type from **[Rust](https://doc.rust-lang.org/std/result/)**.\n\nHere’s a simple example of how the `Result` pattern can be used:\n\n```typescript\nimport { Result, ok, err } from '@armadacore/fnt';\n\n// A function demonstrating the Result Pattern\nfunction divide(a: number, b: number): Result\u003cnumber, string\u003e {\n    if (b === 0) {\n        return err(\"Division by zero is not allowed.\");\n    }\n    return ok(a / b);\n}\n\n// Using the Result Pattern\nconst result = divide(10, 2);\n\nif (result.isOk) {\n    console.log(\"Result:\", result.unwrap()); // Output: Result: 5\n} else {\n    console.error(\"Error:\", result.unwrapErr()); // If b = 0\n}\n```\n\nIn this example, the result is returned as either `ok` (successful) or `err` (error). This allows you to explicitly distinguish between success and error cases and handle them safely.\n\n## Example: Option Pattern\n\nThe `Option` pattern is another useful concept inspired by **[Rust](https://doc.rust-lang.org/std/option/)**. It allows you to handle values that might be \"missing\" in an explicit and safe way, without relying on `null` or `undefined`.\n\nHere’s a simple example of how the `Option` pattern can be used:\n\n```typescript\nimport { Option, some, none } from '@armadacore/fnt';\n\n// A function demonstrating the Option Pattern\nfunction findElement\u003cT\u003e(array: T[], predicate: (item: T) =\u003e boolean): Option\u003cT\u003e {\n    const found = array.find(predicate);\n    return found !== undefined ? some(found) : none();\n}\n\n// Using the Option Pattern\nconst array = [1, 2, 3, 4, 5];\nconst result = findElement(array, (x) =\u003e x \u003e 3);\n\nif (result.isSome) {\n    console.log(\"Found value:\", result.unwrap()); // Output: Found value: 4\n} else {\n    console.log(\"No value found.\"); // If no value matches the predicate\n}\n```\n\nIn this example, the function returns either `some` (if a value is found) or `none` (if no value matches the condition). The `Option` pattern provides a type-safe and explicit way to handle optional values in your code, avoiding potential `null`-related errors.\n\n### `option` Function\n\nThe `option` function is designed to handle optional parameters or variables that might be `null` or `undefined`. It wraps a potential value safely using the `Option` type.\n\nHere’s an example of how the `option` function can be used:\n\n```typescript\nimport { option } from '@armadacore/fnt';\n\n// Using the option function with a null value\nconst userNameValue = null;\nconst userName = option\u003cstring\u003e(userNameValue); // Returns 'none()'\n\nif (userName.isSome) {\n    console.log(\"User name:\", userName.unwrap());\n} else {\n    console.log(\"No user name provided.\"); // This will be the output\n}\n\n// Using the option function with a valid value\nconst userAgeValue = 30;\nconst userAge = option(userAgeValue); // Returns 'some(30)'\n\nif (userAge.isSome) {\n    console.log(\"User age:\", userAge.unwrap()); // Output: User age: 30\n}\n```\n\n## Example: Match Pattern\n\nThe `match` pattern offers a concise, pattern-matching-style handling of various options or results, inspired by the `match` feature from **[Rust](https://doc.rust-lang.org/rust-by-example/flow_control/match.html)**. This allows for clear, exhaustive, and type-safe handling of cases.\n\nHere’s an example using `match` with a `Result`:\n\n```typescript\nimport { match, Result, ok, err } from '@armadacore/fnt';\n\n// A function with Result Pattern\nfunction fetchUserData(userId: number): Result\u003cstring, string\u003e {\n    if (userId \u003e 0) return ok(`User with ID ${userId}`);\n    return err(\"Invalid user ID\");\n}\n\n// Using the match pattern to handle Result\nconst userResult = fetchUserData(1);\n\nconst message = match(userResult, {\n    ok: (data) =\u003e `Success: ${data}`,\n    err: (error) =\u003e `Error: ${error}`,\n});\n\nconsole.log(message); // Output: Success: User with ID 1\n```\n\nIn this example, we use `match` to differentiate between success (`ok`) and error (`err`) cases. It's a powerful tool for handling the exhaustive nature of cases in TypeScript.\n\n### Important Note on Overloading and TypeScript Types\nCurrently, in TypeScript, when overloading `match` patterns with multiple types, some issues may arise, particularly with the second parameter `branch`. The TypeScript type resolution may not accurately enforce exhaustive cases in some scenarios. This is a known limitation and requires care when using `match` with complex type combinations.\n\nIf you encounter issues, consider checking your implementation for type safety or using explicit case handling as a workaround.\n\n---\n\n## License\n\nThis project is licensed under the **MIT License**. For more details, see the [LICENSE](./LICENSE) file.\n\n---\n\n## Notes\n\nThis project is still in an early development phase. Feedback and suggestions are welcome!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmadacore%2Ffnt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farmadacore%2Ffnt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farmadacore%2Ffnt/lists"}