{"id":14964326,"url":"https://github.com/gkshi/nuxt-models","last_synced_at":"2025-06-16T14:08:49.160Z","repository":{"id":52348946,"uuid":"228923364","full_name":"gkshi/nuxt-models","owner":"gkshi","description":"JS model controller for your Nuxt.js project","archived":false,"fork":false,"pushed_at":"2021-04-30T15:49:26.000Z","size":560,"stargazers_count":4,"open_issues_count":5,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-20T02:53:43.919Z","etag":null,"topics":["data-validation","entities","models","nuxt","nuxtjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkshi.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-12-18T21:19:30.000Z","updated_at":"2023-02-20T14:53:34.000Z","dependencies_parsed_at":"2022-09-07T19:41:36.696Z","dependency_job_id":null,"html_url":"https://github.com/gkshi/nuxt-models","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gkshi/nuxt-models","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkshi%2Fnuxt-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkshi%2Fnuxt-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkshi%2Fnuxt-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkshi%2Fnuxt-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkshi","download_url":"https://codeload.github.com/gkshi/nuxt-models/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkshi%2Fnuxt-models/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260173984,"owners_count":22969870,"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":["data-validation","entities","models","nuxt","nuxtjs"],"created_at":"2024-09-24T13:32:59.486Z","updated_at":"2025-06-16T14:08:49.138Z","avatar_url":"https://github.com/gkshi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nuxt-models\n\n\u003e JS model controller for your Nuxt.js project.\n\nPlugin use cases:\n* Keep common data standart.\n* Complement incomplete data getting by API.\n* Control data validity.\n\n\u0026nbsp;\n\n### Installation\n\n1. Install plugin via npm or yarn  \n\n```yarn add --dev nuxt-models```\n\n2. Include plugin in nuxt.config.js\n\n```javascript\nexport default {\n  plugins: [\n    'nuxt-models'\n  ]\n}\n```\n\n\n\u0026nbsp;\n\n\n### Basic usage\n\n1. Describe a model. Create /models/person.js\n\n```javascript\nexport default {\n  name: String,\n  surname: String,\n  age: {\n    type: Number,\n    validation: value =\u003e value \u003e 0\n  },\n  gender: {\n    type: String,\n    validation: value =\u003e ['male', 'female', 'other'].includes(value)\n  }\n}\n```\n\n2. Create an entity in Vue-component\n\n```javascript\nconst Person = this.$models.create('person', {\n  name: 'Jack',\n  age: 25\n})\n\n// returns an entity\n// {\n//   name: 'Jack',\n//   surname: '',\n//   age: 25,\n//   gender: ''\n// }\n```\n\n\n\u0026nbsp;\n\n\n### Model describing\n\nModel is an object with described options. There is a simple model example:\n\n```javascript\n// Simple person model with name only\nexport default {\n  name: {\n    type: String,\n    default: 'Jack',\n    required: true,\n    hidden: false,\n    validation: value =\u003e value.length \u003e 1\n  }\n}\n```\n\n`Option.type`  \nDefines an option type  \nString, Number, Array, Object, Boolean\n\n`Option.default`  \nDefault option value, when entity creates.\n\n`Option.required`  \nTrue/false state. If it's true, Entity.validation will return false if there is no value.\n\n`Option.hidden`  \nTrue/false state. If it's true, Entity.values method won't include this option to return.\n\n`Option.validation`  \nA function. Describes condition for correct option value.  \nIf all validation rules of options return true, Entity.validation returns true.\n\n\n\u0026nbsp;\n\n\n### Nested models\n\nYou may create entities with nested entities.\n\n```javascript\nimport Department from '@/models/department'\n\n// Person model\nexport default {\n  name: String,\n  age: Number,\n  department: {\n    model: Department,\n    value: 'title',\n    hidden: false\n  }\n}\n```\n\n`Option.model`  \nOption with nested model.\n\n`Option.value`  \nOption name of nested model. Entity.department will return its value.  \nCannot be combined with \"hidden\" option.\n\n`Option.hidden`  \nTrue/false state. If it's true, Entity.department will be added as hidden property.  \nCannot be combined with \"value\" option.\n\n\u0026nbsp;  \n\n\n### Plugin methods\n\n`this.$models.create`  \nCreates an entity by described model\n\n```javascript\nconst Person = this.$models.create('person', {\n  name: 'Jack',\n  age: 25\n})\n\n// returns an entity\n// {\n//   name: 'Jack',\n//   surname: '',\n//   age: 25,\n//   gender: ''\n// }\n```\n\u0026nbsp;\n\n`this.$models.get`  \nReturns a model object\n\n```javascript\nconst PersonModel = this.$models.get('person')\n\n// returns a model\n// {\n//   name: {\n//     type: String,\n//     required: true\n//   },\n//   surname: {\n//     type: String\n//   },\n//   age: {\n//     type: Number,\n//     validation: value =\u003e value \u003e= 0,\n//     default: 0\n//   },\n//   gender: {\n//     type: String,\n//     validation: value =\u003e ['male', 'female', 'other'].includes(value)\n//   }\n// }\n```\n\u0026nbsp;\n\n`this.$models.clone`  \nCreates a copy of existing entity with all values\n\n```javascript\nconst Person = this.$models.create('person', { name: 'Jack'} )\nconst AnotherPerson = this.$models.clone(Person)\n\nconsole.log(Person.name) // Jack\nconsole.log(AnotherPerson.name) // Jack\n\nAnotherPerson.name = 'Mary'\n\nconsole.log(Person.name) // Jack\nconsole.log(AnotherPerson.name) // Mary\n```\n\n\n\u0026nbsp;\n\n\n### Entity methods\n\n`Entity.modelName`  \nReturns a model name, entity was created by\n\n```javascript\nconst Person = this.$models.create('person')\n\nconsole.log(Person.modelName) // person\n```\n\u0026nbsp;\n\n`Entity.model`  \nReturns a model, entity was created by\n\n```javascript\nconst Person = this.$models.create('person')\n\nconsole.log(Person.model)\n\n// returns a model\n// {\n//   name: {\n//     type: String,\n//     required: true\n//   },\n//   surname: {\n//     type: String\n//   },\n//   age: {\n//     type: Number,\n//     validation: value =\u003e value \u003e= 0,\n//     default: 0\n//   },\n//   gender: {\n//     type: String,\n//     validation: value =\u003e ['male', 'female', 'other'].includes(value)\n//   }\n// }\n```\n\u0026nbsp;\n\n`Entity.validation`  \nReturns true/false state.  \nIf it's true, all entity values are correct.  \nIf it's false, some of entity values hasn't passed validation.  \nValues without validation returns true in any case.\n\n```javascript\nconst Person = this.$models.create('person')\n\nconsole.log(Person.validation)\n// return false\n// because \"gender\" value hasn't passed validation\n\nPerson.gender = 'male'\n\nconsole.log(Person.validation)\n// return true\n// all values have passed validation\n```\n\u0026nbsp;\n\n`Entity.values`  \nReturns an object with all options and values.  \nOptions with hidden property won't be included in object.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkshi%2Fnuxt-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkshi%2Fnuxt-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkshi%2Fnuxt-models/lists"}