{"id":16811269,"url":"https://github.com/gorhom/codable","last_synced_at":"2025-03-22T03:31:05.107Z","repository":{"id":57113949,"uuid":"200813922","full_name":"gorhom/codable","owner":"gorhom","description":"A strict json parser inspired by Swift Codable","archived":false,"fork":false,"pushed_at":"2020-04-18T07:58:42.000Z","size":1074,"stargazers_count":27,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T11:39:00.710Z","etag":null,"topics":["codable","decodable","encodable","json","parser","ts-codable","typescript"],"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/gorhom.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}},"created_at":"2019-08-06T08:54:09.000Z","updated_at":"2024-05-31T04:55:40.000Z","dependencies_parsed_at":"2022-08-22T08:31:27.819Z","dependency_job_id":null,"html_url":"https://github.com/gorhom/codable","commit_stats":null,"previous_names":["gorhom/ts-codable"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorhom%2Fcodable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorhom%2Fcodable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorhom%2Fcodable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gorhom%2Fcodable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gorhom","download_url":"https://codeload.github.com/gorhom/codable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244124951,"owners_count":20401817,"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":["codable","decodable","encodable","json","parser","ts-codable","typescript"],"created_at":"2024-10-13T10:18:13.597Z","updated_at":"2025-03-22T03:31:04.011Z","avatar_url":"https://github.com/gorhom.png","language":"TypeScript","readme":"# Codable [![npm](https://img.shields.io/npm/v/@gorhom/codable)](https://www.npmjs.com/package/@gorhom/codable) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/@gorhom/codable)](https://www.npmjs.com/package/@gorhom/codable) [![npm](https://badgen.net/npm/dependents/@gorhom/codable)](https://www.npmjs.com/package/@gorhom/codable)\n\nA strict json parser inspired by [Swift Codable](https://developer.apple.com/documentation/swift/codable/) ❤️\n\n![Alt text](docs/cover.png 'Cover')\n\n## Features\n\nWorks almost same as [Swift Codable](https://developer.apple.com/documentation/swift/codable), but with some extra implementation to fit `TypeScript` / `JavaScript` environment.\n\n- Decodes `JSON` payload with pre-defined scheme.\n  - Custom keys parsing.\n  - Strict types checking.\n  - Nested `Codable` parsing.\n\n## Supported Types\n\nTypes design was inspired by [MobX State Tree](https://github.com/mobxjs/mobx-state-tree#types-overview) ❤️\n\n- Primitives\n  - String\n  - Number\n  - Boolean\n- Complex\n  - Codable\n  - Optional\n  - Array\n  - Date\n\n## Installation\n\n```bash\nyarn add @gorhom/codable\n# or\nnpm install @gorhom/codable\n```\n\n## Usage\n\n```ts\nimport { BaseCodable, types, decode, encode } from '@gorhom/codable';\nimport dayjs from 'dayjs';\n\nclass Post extends BaseCodable {\n  title!: string;\n  isActive?: boolean;\n  date!: Date;\n}\n\nPost.CodingProperties = {\n  title: types.string,\n  isActive: {\n    type: types.optional(types.boolean),\n    key: 'active',\n  },\n  date: types.date(dayjs),\n};\n\nclass User extends BaseCodable {\n  id!: number;\n  username!: string;\n  posts!: Post[];\n}\n\nUser.CodingProperties = {\n  id: types.number,\n  username: types.string,\n  posts: types.array(Post),\n};\n\nconst jsonPayload = {\n  id: 123,\n  username: 'Gorhom',\n  posts: [\n    {\n      title: 'dummy post',\n      active: true,\n      date: '2020-02-15T16:00:00.000Z',\n    },\n    {\n      title: 'deleted post',\n      active: false,\n      date: '2020-02-10T16:00:00.000Z',\n    },\n  ],\n};\n\nconst user: User = decode(User, jsonPayload);\n\n// now encode it back 🙈\n// ⚠️ date encoding still in progress\n\nconst userJson = encode(user)\n```\n\n## TODO\n\n- [x] Add [Swift Decodable](https://developer.apple.com/documentation/swift/decodable) functionality.\n- [x] Add [Swift Encodable](https://developer.apple.com/documentation/swift/encodable) functionality.\n- [ ] Write API docs.\n\n## Built With\n\n- [TSdx](https://github.com/jaredpalmer/tsdx)\n- [TypeScript](https://github.com/Microsoft/TypeScript)\n\n## Author\n\n- [Mo Gorhom](https://twitter.com/gorhom)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgorhom%2Fcodable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgorhom%2Fcodable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgorhom%2Fcodable/lists"}