{"id":19560431,"url":"https://github.com/codelytv/typescript-primitives-type","last_synced_at":"2025-04-12T23:30:12.361Z","repository":{"id":38193226,"uuid":"496632782","full_name":"CodelyTV/typescript-primitives-type","owner":"CodelyTV","description":"🧩 TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects)","archived":false,"fork":false,"pushed_at":"2025-02-12T14:35:59.000Z","size":410,"stargazers_count":119,"open_issues_count":2,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-04T03:38:56.534Z","etag":null,"topics":["typescript","typescript-library","typescript-types","typescript-utilities","typescript-utility"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@codelytv/primitives-type","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodelyTV.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}},"created_at":"2022-05-26T13:32:47.000Z","updated_at":"2025-04-04T03:03:44.000Z","dependencies_parsed_at":"2024-06-21T19:09:29.746Z","dependency_job_id":"d808acf7-7f38-4135-98f0-1eca142a0b6d","html_url":"https://github.com/CodelyTV/typescript-primitives-type","commit_stats":{"total_commits":12,"total_committers":6,"mean_commits":2.0,"dds":0.5,"last_synced_commit":"3be4da4870be64ba309560c402e545f4ab18f692"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":"CodelyTV/typescript-basic-skeleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodelyTV%2Ftypescript-primitives-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodelyTV%2Ftypescript-primitives-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodelyTV%2Ftypescript-primitives-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodelyTV%2Ftypescript-primitives-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodelyTV","download_url":"https://codeload.github.com/CodelyTV/typescript-primitives-type/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647249,"owners_count":21139081,"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":["typescript","typescript-library","typescript-types","typescript-utilities","typescript-utility"],"created_at":"2024-11-11T05:07:32.650Z","updated_at":"2025-04-12T23:30:12.341Z","avatar_url":"https://github.com/CodelyTV.png","language":"TypeScript","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://codely.com\"\u003e\n    \u003cimg src=\"https://user-images.githubusercontent.com/10558907/170513882-a09eee57-7765-4ca4-b2dd-3c2e061fdad0.png\" width=\"300px\" height=\"92px\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n  🧩 TypeScript \u003ccode\u003ePrimitives\u003c/code\u003e type\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/CodelyTV\"\u003e\u003cimg src=\"https://img.shields.io/badge/CodelyTV-OS-green.svg?style=flat-square\" alt=\"Codely Open Source\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://pro.codely.com\"\u003e\u003cimg src=\"https://img.shields.io/badge/CodelyTV-PRO-black.svg?style=flat-square\" alt=\"CodelyTV Courses\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  TypeScript utility type in order to ensure to return only properties (not methods) containing values in primitive types such as number or boolean (not Value Objects).\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n  Take a look, play and have fun with this.\n  \u003ca href=\"https://github.com/CodelyTV/typescript-primitives-type/stargazers\"\u003eStars are welcome 😊\u003c/a\u003e\n\u003c/p\u003e\n\n# 👀 Usage example\n\nYou can have a domain entity such as the following `Course`:\n\n```typescript\nimport { CourseId } from \"./CourseId\";\nimport { CourseTitle } from \"./CourseTitle\";\n\nexport class Course {\n  constructor(public courseId: CourseId, public courseTitle: CourseTitle) {}\n\n  updateTitle(newCourseTitle: CourseTitle): void {\n    this.courseTitle = newCourseTitle;\n  }\n\n  someOtherMethodWithDomainLogic(): void {\n    // some algorithm\n  }\n}\n```\n\nWhen we want to have a `toPrimitives` method in order to pass an instance of the `Course` class between architectural layers, so the thing we want pass around should be to serialized/marshalled in a way that only containings primitive values such as:\n\n```json\n{\n  \"courseId\": \"25658f31-2da1-4942-8b58-88aeacc79860\",\n  \"courseTitle\": \"🚜 TypeScript Avanzado: Más allá de any\"\n}\n```\n\nThat is:\n\n- We want to **avoid including methods** such as the `thisFunctionShouldNotBeIncludedInTheToPrimitives` one, so the transformation should only include properties.\n- We want to **flatten or unwrap encapsulated properties** such as the `courseId` and `courseTitle` ones. They are modelled as Value Objects (`CourseId` and `CourseTitle` classes), so the transformation or flatten should only include properties in a recursive manner.\n\nThat is exactly what our `Primitives\u003cT\u003e` utility type guarantees. Let's add it! 💪\n\n```typescript\nimport { Primitives } from \"@codelytv/primitives-type\";\n\nimport { CourseId } from \"./CourseId\";\nimport { CourseTitle } from \"./CourseTitle\";\n\nexport class Course {\n  constructor(public courseId: CourseId, public courseTitle: CourseTitle) {}\n\n  updateTitle(newCourseTitle: CourseTitle): void {\n    this.courseTitle = newCourseTitle;\n  }\n\n  someOtherMethodWithDomainLogic(): void {\n    // some algorithm\n  }\n\n  toPrimitives(): Primitives\u003cCourse\u003e {\n    return {\n      courseId: this.courseId.value,\n      courseTitle: this.courseTitle.value,\n    };\n  }\n}\n```\n\nDone! ✌️\n\nThe `Primitives\u003cCourse\u003e` return type is ensuring all our restrictions in a very straightforward way! 🌈\n\n# 👍 How to install\n\n- Npm: `npm install --save-dev @codelytv/primitives-type`\n- Yarn: `yarn add -D @codelytv/primitives-type`\n\n# 👌 Codely Code Quality Standards\n\nPublishing this package we are committing ourselves to the following code quality standards:\n\n- 🤝 Respect **Semantic Versioning**: No breaking changes in patch or minor versions\n- 🤏 No surprises in transitive dependencies: Use the **bare minimum dependencies** needed to meet the purpose\n- 🎯 **One specific purpose** to meet without having to carry a bunch of unnecessary other utilities\n- ✅ **Tests** as documentation and usage examples\n- 📖 **Well documented ReadMe** showing how to install and use\n- ⚖️ **License favoring Open Source** and collaboration\n\n# 🔀 Related utilities and resources\n\n## ☝️ Learning resources\n\n- [🚜 TypeScript Avanzado: Más allá de any](https://pro.codely.com/library/typescript-avanzado-mas-alla-de-any-182513/418230/about/) (Spanish - Course)\n- [📂 DDD en TypeScript: Estructura de carpetas](https://youtu.be/AJJRk7qmVHg) (Spanish - YouTube video)\n- [🔖 Domain-Driven Design en TypeScript](https://pro.codely.com/library/ddd-en-typescript-modelado-y-arquitectura-172533/375662/about/) (Spanish - Course)\n- [🐥 JavaScript moderno: Buenas prácticas para empezar y refactorizar aplicaciones](https://pro.codely.com/library/javascript-moderno-buenas-practicas-para-empezar-y-refactorizar-aplicaciones-69571/208928/about/) (Spanish - Course)\n- [🏗️ De JavaScript a TypeScript](https://pro.codely.com/library/de-javascript-a-typescript-128106/347481/about/) (Spanish - Course)\n\n## 🔷 TypeScript skeletons\n\n- [🌱 TypeScript Basic Skeleton](https://github.com/CodelyTV/typescript-basic-skeleton): Bootstrap your new TypeScript frontend project\n- [🌍 TypeScript API Skeleton](https://github.com/CodelyTV/typescript-api-skeleton): Bootstrap your new TypeScript backend project\n\n## 🌈 TypeScript Domain-Driven Design repositories\n\n- [✨ TypeScript DDD Skeleton](https://github.com/CodelyTV/typescript-ddd-skeleton): Bootstrap your new TypeScript projects applying Hexagonal Architecture and Domain-Driven Design patterns\n- [🔖 TypeScript DDD Course](https://github.com/CodelyTV/typescript-ddd-course): Learn Domain-Driven Design in TS lesson by lesson\n- [🎯 TypeScript DDD Example](https://github.com/CodelyTV/typescript-ddd-example): Complete project applying Hexagonal Architecture and Domain-Driven Design patterns\n\n## 🎯 Other languages Domain-Driven Design repositories\n\n- [☕🎯 Java DDD Example](https://github.com/CodelyTV/java-ddd-example)\n- [🐘🎯 PHP DDD Example](https://github.com/CodelyTV/php-ddd-example)\n- [λ🎯 Scala DDD Example](https://github.com/CodelyTV/scala-ddd-example)\n- [🦈✨ C# DDD Skeleton](https://github.com/CodelyTV/csharp-ddd-skeleton)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodelytv%2Ftypescript-primitives-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodelytv%2Ftypescript-primitives-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodelytv%2Ftypescript-primitives-type/lists"}