{"id":23613659,"url":"https://github.com/freckle/maybe-js","last_synced_at":"2026-03-01T19:01:46.644Z","repository":{"id":42688071,"uuid":"455670252","full_name":"freckle/maybe-js","owner":"freckle","description":"Package for handling maybe operations","archived":false,"fork":false,"pushed_at":"2026-01-22T09:55:49.000Z","size":253,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":7,"default_branch":"main","last_synced_at":"2026-01-23T00:25:58.785Z","etag":null,"topics":["ghvm-managed"],"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/freckle.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-02-04T19:24:01.000Z","updated_at":"2026-01-22T09:54:45.000Z","dependencies_parsed_at":"2024-06-21T16:44:40.576Z","dependency_job_id":"b98522ff-1fb0-4f20-ac59-d925d93f8195","html_url":"https://github.com/freckle/maybe-js","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/freckle/maybe-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fmaybe-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fmaybe-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fmaybe-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fmaybe-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freckle","download_url":"https://codeload.github.com/freckle/maybe-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freckle%2Fmaybe-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29980792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["ghvm-managed"],"created_at":"2024-12-27T17:18:37.785Z","updated_at":"2026-03-01T19:01:46.639Z","avatar_url":"https://github.com/freckle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @freckle/maybe\n\nProvides a collection of helper functions for operations on maybe types.\n\n## Motivation\n\nThis package seeks to recreate idioms common in strongly typed functional programming languages, with heavy influence from the [Data.Maybe Haskell package][Data.Maybe].\n\n## Usage\n\nOperations are used to refine an input from being possibly `null` or `undefined`:\n\n```js\nimport {fromJust, fromMaybe, maybe} from '@freckle/maybe'\n\n// Return input from a user, if any:\ndeclare function getUserInput(): ?string\n\nconst mUserInput = getUserInput()\n\n// Go from ?string -\u003e string:\nconst input = fromMaybe(() =\u003e 'No input', mUserInput)\n\n// Run a function on ?string with a default:\nconst capitalized = maybe(() =\u003e 'No input to capitalize', capitalize, mUserInput)\n\n// Or produce an error on null | undefined to make future execution more predictable:\nconst userInput = fromJust(mUserInput, 'No input was given!')\n```\n\nOther operations carry the possibly `null` value after applying a function:\n\n```js\nimport {mmap, mthen} from '@freckle/maybe'\n\n// Return input from a user, if any:\ndeclare function getUserInput(): ?string\n\n// Function that does not handle a null | undefined value:\ndeclare function transform(input: string): string\n\nconst mUserInput = getUserInput()\n\nconst mTransformed = mmap(transform, mUserInput)\n// =\u003e null | undefined | transform(mUserInput)\n\n// Alternate form that is more helpful for control flow:\nmthen(mTransformed, (transformedUserInput: string) =\u003e {\n  // Process value\n})\n```\n\nFor dealing with Arrays that may contain `null` or `undefined` elements:\n\n```js\nimport {catMaybes, mapMaybes} from '@freckle/maybe'\n\nconst arr = [\n  null,\n  'foo',\n  undefined,\n  'bar'\n]\n\nconst out = catMaybes(arr)\n\nconsole.log(out) // =\u003e ['foo', 'bar']\n\nconst padString = (input: string) =\u003e `  ${input}`\n\nconst mapped = mapMaybes(arr, padString)\n\nconsole.log(mapped) // =\u003e ['  foo', '  bar']\n```\n\nTwo operations are tailored to use with React:\n\n```js\nimport {mEffect, asHTMLAttributeValue} from '@freckle/maybe'\n\ntype Props = {\n  myInput: ?string\n}\n\nconst MyComponent = (props: Props): React.Node =\u003e {\n  // This prop may be string | undefined | null\n  const possibleInput = props.myInput\n\n  React.useEffect(() =\u003e {\n    mEffect(possibleInput, input =\u003e\n      // Call a side effect that does not handle a null value:\n      sideEffect(input)\n    )\n  }, [possibleInput])\n\n  // Rendering an element with an attribute from a maybe value:\n  const attrObj = {'my-attribute': asHTMLAttributeValue(possibleInput)}\n\n  // If input is not a string, \u003cdiv\u003e is rendered;\n  // otherwise: \u003cdiv my-attribute=\"...\" /\u003e\n  return \u003cdiv {...attrObj} /\u003e\n}\n```\n\n\n[Data.Maybe]: https://hackage.haskell.org/package/base-4.16.0.0/docs/Data-Maybe.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Fmaybe-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreckle%2Fmaybe-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreckle%2Fmaybe-js/lists"}