{"id":15295275,"url":"https://github.com/ikasparov/tsmodels","last_synced_at":"2025-04-13T15:59:14.792Z","repository":{"id":57179663,"uuid":"100241143","full_name":"ikasparov/tsmodels","owner":"ikasparov","description":"An implementation of models for TypeScript","archived":false,"fork":false,"pushed_at":"2019-05-10T09:42:29.000Z","size":71,"stargazers_count":53,"open_issues_count":10,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T06:51:20.704Z","etag":null,"topics":["angular","angular2","angular5","models","mvc","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/tsmodels","language":"JavaScript","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/ikasparov.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":"2017-08-14T07:38:19.000Z","updated_at":"2024-10-29T14:27:12.000Z","dependencies_parsed_at":"2022-09-14T02:31:36.932Z","dependency_job_id":null,"html_url":"https://github.com/ikasparov/tsmodels","commit_stats":null,"previous_names":["ikasparov/angular2-models"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikasparov%2Ftsmodels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikasparov%2Ftsmodels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikasparov%2Ftsmodels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikasparov%2Ftsmodels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikasparov","download_url":"https://codeload.github.com/ikasparov/tsmodels/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741198,"owners_count":21154252,"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":["angular","angular2","angular5","models","mvc","typescript"],"created_at":"2024-09-30T17:09:17.576Z","updated_at":"2025-04-13T15:59:14.773Z","avatar_url":"https://github.com/ikasparov.png","language":"JavaScript","readme":"# tsmodels\nImplementation of the model system for the TypeScript language\n\n## Features\n- Convert format fields from server to client and back\n- Creates instances of models rather than typing (with conversion)\n- Perceives both nested (connected) models and collections of any depth\n\n## Installation\nInstall `tsmodels` from `npm` or `yarn`:\n```bash\n# from `npm`\nnpm i tsmodels --save\n\n# from `yarn`\nyarn add tsmodels --save\n```\n\n## Usage\nIt is necessary to inherit the model from the class `Model`:\n```typescript\nimport { Alias, Model } from 'tsmodels';\n\nexport class User extends Model {\n  // ...\n}\n```\nFor the model instance, methods will be available `_fromJSON(value)` and `_toJSON()` methods\n\n### Model clear static methods\n\n- `Model.new\u003cmodeType\u003e(\u003cmodel-type\u003e, \u003cdata\u003e)` - Creates an instance of pass model class with data\n- `Model.newCollection\u003cmodeType\u003e(\u003cmodel-type\u003e, \u003cdata[]\u003e)` - Creates an instances collection of pass model class with data array\n\n### @Alias(...)\nDecorator of fields for model\n\n- Optional param `field_name` - Name of server format field\n- Optional param `type` - Optional. Type of related model\n\n### _toJSON()\n\nConvert model to object using Alias's metadata\n\nParameters:\n  {string[]} only - Array of field's aliases to export\n\n## Example\n\n##### Town model\n```typescript\n// ...\n\nexport class Town extends Model {\n  @Alias('main_title') public mainTitle: string;\n}\n```\n\n##### User model\n```typescript\n// ...\n\nexport class User extends AppnModel {\n  @Alias() public name: string;\n  @Alias('last_name') public lastName: string;\n  @Alias('towns', Town) public towns: Town[];\n  @Alias('main_town', Town) public townMain: Town;\n}\n```\n\n```typescript\n// ...\n\nconst townMock = { main_title: 'Sulonia' };\nconst townMock2 = { main_title: 'Sulon' };\n\nconst userMock = {\n  name: 'Kyle Katarn',\n  last_name: 'Katarn',\n  towns: [townMock, townMock2],\n  main_town: [townMock2],\n};\n\nclass ModelExample {\n  public user: User = new User();\n  \n  constructor() {\n    this.user._fromJSON(userMock);\n    this.user._toJSON();\n  }\n}\n```\n\n##### _fromJSON()\nUser will be:\n```json\n{\n  \"name\": \"Kyle Katarn\", \n  \"lastName\": \"Katarn\", \n  \"towns\": [\n    {\n      \"mainTitle\": \"Sulonia\"\n    },\n    {\n      \"mainTitle\": \"Sulon\"\n    }\n  ],\n  \"townMain\": {\n    \"mainTitle\": \"Suloniaaaa3\"\n  }\n}\n```\n\n##### _toJSON()\nUser will be:\n```json\n{\n  \"name\": \"Kyle Katarn\", \n  \"last_name\": \"Katarn\", \n  \"towns\": [\n    {\n      \"main_title\": \"Sulonia\"\n    },\n    {\n      \"main_title\": \"Sulon\"\n    }\n  ],\n  \"main_town\": {\n    \"main_title\": \"Suloniaaaa3\"\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikasparov%2Ftsmodels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikasparov%2Ftsmodels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikasparov%2Ftsmodels/lists"}