{"id":15059678,"url":"https://github.com/eeue56/adeilad","last_synced_at":"2025-04-10T05:41:21.218Z","repository":{"id":57110726,"uuid":"372566564","full_name":"eeue56/adeilad","owner":"eeue56","description":"Ensure JSON has the correct structure at runtime","archived":false,"fork":false,"pushed_at":"2022-07-22T12:21:06.000Z","size":71,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T06:54:38.043Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eeue56.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}},"created_at":"2021-05-31T16:22:24.000Z","updated_at":"2022-07-22T12:21:09.000Z","dependencies_parsed_at":"2022-08-21T06:31:04.189Z","dependency_job_id":null,"html_url":"https://github.com/eeue56/adeilad","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeue56%2Fadeilad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeue56%2Fadeilad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeue56%2Fadeilad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eeue56%2Fadeilad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eeue56","download_url":"https://codeload.github.com/eeue56/adeilad/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166207,"owners_count":21058475,"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":[],"created_at":"2024-09-24T22:46:32.960Z","updated_at":"2025-04-10T05:41:21.199Z","avatar_url":"https://github.com/eeue56.png","language":"TypeScript","readme":"# adeilad\n\nEnsure JSON has the correct structure at runtime, inspired by Elm's [decoders](https://package.elm-lang.org/packages/elm/json/latest/Json-Decode) and the [pipeline decoder](https://package.elm-lang.org/packages/NoRedInk/elm-json-decode-pipeline/latest) package.\n\nThese functions are best used at the surface points where JSON comes into your program: either via an API call, user input, or some untyped library.\n\nPart of the [Hiraeth](https://github.com/eeue56/hiraeth) collection.\n\n## Installation\n\n```\nnpm install --save @eeue56/adeilad\n```\n\n## Example usage\n\nImagine you have some API that gives you JSON, for example:\n\n```typescript\nimport { decode, pipeline, required, string, number, array } from \"@eeue56/adeilad\";\n\n\n// fetched via a http request\nconst someExampleData = {\n    name: \"Noah\",\n    age: 28,\n    pets: [\n        { name: \"Frodo\", age: 8 },\n        { name: \"Fiver\", age: 3 },\n    ]\n};\n\ntype Pet = {\n    name: string;\n    age: number;\n}\n\nfunction Pet(name: string, age: number): Pet {\n    return {\n        name,\n        age\n    }\n}\n\ntype Person = {\n    name: string;\n    age: number;\n    pets: Pet[]\n}\n\nfunction Person(name: string, age: number, pets: Pet[]): Person{\n    return {\n        name,\n        age,\n        pets\n    }\n}\n\nconst petDecoder = pipeline([\n    required(\"name\", string()),\n    required(\"age\", number())\n])\n\nconst personDecoder = pipeline([\n    required(\"name\", string()),\n    required(\"age\", number()),\n    required(pets, array(petDecoder))\n]))\n\nconst result = decode(personDecoder, person);\n\nswitch (result.kind) {\n    \"ok\": {\n        console.log(\"Got a valid person:\", result.value);\n    },\n    \"err\": {\n        console.error(\"Invalid person:\", res.error);\n    }\n}\n```\n\n## Docs\n\nSee [docs](./docs/src/adeilad.md)\n\nYou may also want to see the Result type from [coed](https://github.com/eeue56/coed)\n\n## Name\n\nAdeilad is the Welsh word for buildings. For English speakers it'd be pronounced similar to \"ah-dey-lad\".\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feeue56%2Fadeilad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feeue56%2Fadeilad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feeue56%2Fadeilad/lists"}