{"id":13484978,"url":"https://github.com/lambdalisue/deno-unnullish","last_synced_at":"2025-05-06T22:10:47.267Z","repository":{"id":53576521,"uuid":"521477605","full_name":"lambdalisue/deno-unnullish","owner":"lambdalisue","description":"🦕 An opposite function of nullish coalescing operator","archived":false,"fork":false,"pushed_at":"2024-04-06T08:29:40.000Z","size":19,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-17T19:56:53.964Z","etag":null,"topics":["deno","jsr","nullish"],"latest_commit_sha":null,"homepage":"https://jsr.io/@lambdalisue/unnullish","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/lambdalisue.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":"2022-08-05T02:28:39.000Z","updated_at":"2025-01-17T04:40:03.000Z","dependencies_parsed_at":"2024-01-13T19:20:00.132Z","dependency_job_id":"7344c806-44d7-4a1c-b310-270772ec4cf8","html_url":"https://github.com/lambdalisue/deno-unnullish","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"8610de6fbd0c51d0de36b6d4cafa1376695f11aa"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-unnullish","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-unnullish/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-unnullish/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lambdalisue%2Fdeno-unnullish/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lambdalisue","download_url":"https://codeload.github.com/lambdalisue/deno-unnullish/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252776600,"owners_count":21802469,"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":["deno","jsr","nullish"],"created_at":"2024-07-31T17:01:41.318Z","updated_at":"2025-05-06T22:10:46.839Z","avatar_url":"https://github.com/lambdalisue.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# unnullish\n\n[![jsr](https://img.shields.io/jsr/v/%40lambdalisue/unnullish?logo=javascript\u0026logoColor=white)](https://jsr.io/@lambdalisue/unnullish)\n[![denoland](https://img.shields.io/github/v/release/lambdalisue/deno-unnullish?logo=deno\u0026label=denoland)](https://github.com/lambdalisue/deno-unnullish/releases)\n[![npm](http://img.shields.io/badge/available%20on-npm-lightgrey.svg?logo=npm\u0026logoColor=white)](https://www.npmjs.com/package/unnullish)\n[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/unnullish/mod.ts)\n[![Test](https://github.com/lambdalisue/deno-unnullish/workflows/Test/badge.svg)](https://github.com/lambdalisue/deno-unnullish/actions?query=workflow%3ATest)\n[![npm version](https://badge.fury.io/js/unnullish.svg)](https://badge.fury.io/js/unnullish)\n\n`unnullish` returns `undefined` if `value` is nullish, otherwise it executes\n`callback` and returns the result. It is an opposite function of the\n[nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator)\n(`??`).\n\n[nullish coalescing operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator\n\n## Usage\n\n### unnullish\n\n- `unnullish\u003cT, R\u003e(value: T | null | undefined, callback(v: T) =\u003e R): R | undefined`\n\nThe function is useful when you want to apply some transformation functions to\noptional values. For example,\n\n```typescript\nimport { unnullish } from \"https://deno.land/x/unnullish@$MODULE_VERSION/mod.ts\";\n\ntype Options = {\n  foo?: string;\n  bar?: number;\n};\n\nfunction sayHello(v: string): string {\n  return `Hello ${v}`;\n}\n\nconst options: Options = {\n  foo: unnullish(Deno.env.get(\"foo\"), (v) =\u003e sayHello(v)),\n  // instead of\n  //foo: Deno.env.get(\"foo\") != null\n  //  ? sayHello(Deno.env.get(\"foo\"))\n  //  : undefined,\n\n  bar: unnullish(Deno.env.get(\"bar\"), (v) =\u003e parseInt(v, 10)),\n  // instead of\n  //bar: Deno.env.get(\"bar\") != null\n  //  ? parseInt(Deno.env.get(\"bar\"), 10)\n  //  : undefined,\n};\n```\n\nNote that the function returns `undefined` even the input is `null`, mean that\nyou may need to use nullish coalescing operator to normalize the result. For\nexample,\n\n```typescript\nimport { unnullish } from \"https://deno.land/x/unnullish@$MODULE_VERSION/mod.ts\";\n\nconsole.log(unnullish(null, () =\u003e 0));\n// -\u003e undefined\nconsole.log(unnullish(undefined, () =\u003e 0));\n// -\u003e undefined\n\nconsole.log(unnullish(null, () =\u003e 0) ?? null);\n// -\u003e null\nconsole.log(unnullish(undefined, () =\u003e 0) ?? null);\n// -\u003e null\n```\n\n## License\n\nThe code follows MIT license written in [LICENSE](./LICENSE). Contributors need\nto agree that any modifications sent in this repository follow the license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-unnullish","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flambdalisue%2Fdeno-unnullish","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flambdalisue%2Fdeno-unnullish/lists"}