{"id":27535699,"url":"https://github.com/causaly/zod-non-empty-array","last_synced_at":"2025-09-07T02:42:57.977Z","repository":{"id":154888385,"uuid":"632337824","full_name":"causaly/zod-non-empty-array","owner":"causaly","description":"Make zod compatible with fp-ts NonEmptyArray","archived":false,"fork":false,"pushed_at":"2025-08-18T12:28:36.000Z","size":1654,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-08-18T14:26:03.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":false,"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/causaly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2023-04-25T07:49:06.000Z","updated_at":"2025-08-18T12:28:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"39492f35-344e-430e-8e8a-665aaa73c2cc","html_url":"https://github.com/causaly/zod-non-empty-array","commit_stats":{"total_commits":15,"total_committers":4,"mean_commits":3.75,"dds":0.4,"last_synced_commit":"8e83d7c42b59334c7999b7c439961bfa2e266aec"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/causaly/zod-non-empty-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/causaly%2Fzod-non-empty-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/causaly%2Fzod-non-empty-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/causaly%2Fzod-non-empty-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/causaly%2Fzod-non-empty-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/causaly","download_url":"https://codeload.github.com/causaly/zod-non-empty-array/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/causaly%2Fzod-non-empty-array/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273989449,"owners_count":25203263,"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-07T02:00:09.463Z","response_time":67,"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":[],"created_at":"2025-04-18T19:10:40.018Z","updated_at":"2025-09-07T02:42:57.940Z","avatar_url":"https://github.com/causaly.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zod-non-empty-array\n\nMake zod compatible with fp-ts non-empty constructs.\n\n[![Build Status](https://github.com/causaly/zod-non-empty-array/actions/workflows/ci.yml/badge.svg)](https://github.com/causaly/zod-non-empty-array/actions/workflows/ci.yml) [![npm version](https://img.shields.io/npm/v/zod-non-empty-array.svg?color=0c0)](https://www.npmjs.com/package/zod-non-empty-array)\n\n## Installation\n\n```bash\nnpm install zod-non-empty-array\n```\n\n#### Requirements\n\n- Node.js v.16+\n\n## Quick start\n\n```typescript\nimport { z as zod } from 'zod';\nimport { identity } from 'fp-ts/lib/function';\nimport * as NonEmptyArray from 'fp-ts/NonEmptyArray';\nimport { transformNonEmptyArray } from 'zod-non-empty-array';\n\n// create zod schema\nconst schema = zod.object({\n  id: zod.number().int().positive(),\n  title: zod.string(),\n  authors: zod\n    .array(zod.string())\n    // must have at least one author\n    .transform(transformNonEmptyArray),\n});\n\ntype Article = zod.infer\u003ctypeof schema\u003e;\n\n// parse some invalid value\nconst article = schema.parse({\n  id: 1,\n  title: 'A case-study of the use of fp-ts in a real-world project',\n  authors: ['John Doe', 'Jane Doe'],\n});\n\n// article.authors is now compatible with fp-ts\nconst principalAuthor = pipe(article.authors, NonEmptyArray.head);\n```\n\n## Motivation\n\nZod already supports [non-empty array validation](https://zod.dev/?id=nonempty). However, the generated type is incompatible with [fp-ts](https://gcanti.github.io/fp-ts/).\n\nSpecifically, fp-ts defines `NonEmptyArray` as follows...\n\n```typescript\ninterface NonEmptyArray\u003cT\u003e extends Array\u003cT\u003e {\n  0: T;\n}\n```\n\nWhile, zod defines `NonEmptyArray` as follows...\n\n```typescript\ntype ZodNonEmptyArray\u003cT\u003e = [T, ...T[]];\n```\n\nThis incompatibility makes it difficult to integrate zod with fp-ts.\n\nThe `zod-non-empty-array` library addresses the incompatibility issue by exposing zod transformers that return fp-ts constructs. Instead of `zod.array(...).nonempty()` use `zod.array(...).transform(transformNonEmptyArray)`.\n\n## API\n\n- transformNonEmptyArray\n- transformReadonlyNonEmptyArray\n\n## Contribute\n\nSource code contributions are most welcome. Please open a PR, ensure the linter is satisfied and all tests pass.\n\n#### We are hiring\n\nCausaly is building the world's largest biomedical knowledge platform, using technologies such as TypeScript, React and Node.js. Find out more about our openings at https://apply.workable.com/causaly/.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcausaly%2Fzod-non-empty-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcausaly%2Fzod-non-empty-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcausaly%2Fzod-non-empty-array/lists"}