{"id":21701400,"url":"https://github.com/ktsn/vuex-assert","last_synced_at":"2025-04-12T13:36:39.655Z","repository":{"id":66221673,"uuid":"72965267","full_name":"ktsn/vuex-assert","owner":"ktsn","description":"Assertion for Vuex state","archived":false,"fork":false,"pushed_at":"2016-11-12T07:48:32.000Z","size":66,"stargazers_count":54,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T02:01:40.031Z","etag":null,"topics":["assert","vue","vuex"],"latest_commit_sha":null,"homepage":null,"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/ktsn.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-06T02:20:44.000Z","updated_at":"2022-12-01T02:19:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"8d2500ad-f797-4116-ac5f-9300c8be503e","html_url":"https://github.com/ktsn/vuex-assert","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsn%2Fvuex-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsn","download_url":"https://codeload.github.com/ktsn/vuex-assert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248574006,"owners_count":21126939,"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":["assert","vue","vuex"],"created_at":"2024-11-25T20:19:39.354Z","updated_at":"2025-04-12T13:36:39.636Z","avatar_url":"https://github.com/ktsn.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vuex-assert\n[![npm version](https://badge.fury.io/js/vuex-assert.svg)](https://badge.fury.io/js/vuex-assert)\n[![Build Status](https://travis-ci.org/ktsn/vuex-assert.svg?branch=master)](https://travis-ci.org/ktsn/vuex-assert)\n\nAssertion for Vuex state\n\n## Examples\n\nJust add `assertions` into your Vuex modules.\n\n```js\n// modules/users.js\nimport {\n  boolean,\n  number,\n  string,\n  object,\n  array\n} from 'vuex-assert'\n\nexport default {\n  state: {\n    isLoading: false,\n    error: null,\n    users: []\n  },\n\n  assertions: {\n    isLoading: boolean,\n    error: object({\n      code: number,\n      message: string\n    }).optional,\n    users: array(object({\n      id: number.assert(id =\u003e id \u003e 0, 'id should be unsigned'),\n      name: string\n    }))\n  },\n\n  // ... module getters, actions and mutations ...\n}\n```\n\nAdd `assertPlugin` to plugins option of `Vuex.Store` with your modules.\n\n```js\nimport Vuex from 'vuex'\nimport modules from './modules'\nimport { assertPlugin } from 'vuex-assert'\n\nconst store = new Vuex.Store({\n  modules,\n  plugins: [\n    assertPlugin({ modules })\n  ]\n})\n```\n\nThen, the store state will be validated for every mutation. Like following message will be printed if the assertion is failed.\n\n```\nstate.users.error.code == null\n\tnumber is expected\n```\n\n## API\n\n- class Assertion\n  - `optional: Assertion`\n\n    Get assertion for optional type of this assertion.\n\n  - `assert(fn: (value: any) =\u003e boolean, message?: string): Assertion`\n\n    Include additional assertion for this assertion.\n\n- `assertPlugin(options): VuexPlugin`\n\n  Create Vuex plugin with options.\n\n  - `options.assertions: { [key: string]: Assertion }`\n  - `options.modules: { [key: string]: VuexModule }`\n\n- `assert(fn: (value: any) =\u003e boolean, message?: string): Assertion`\n\n  Create new assertion.\n\n- `number: Assertion`\n\n  Assertion for number.\n\n- `string: Assertion`\n\n  Assertion for string.\n\n- `boolean: Assertion`\n\n  Assertion for boolean.\n\n- `optional: Assertion`\n\n  Assertion for null or undefined.\n\n- `object(assertions?: { [key: string]: Assertion }, message?: string): Assertion`\n\n  Create assertion for object with properties assertions.\n\n- `array(assertion?: Assertion, message?: string): Assertion`\n\n  Create assertion for array with items assertions.\n\n- `and(assertions: Assertion[]): Assertion`\n\n  Intersect given assertions.\n\n- `or(assertions: Assertion[]): Assertion`\n\n  Union given assertions.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsn%2Fvuex-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsn%2Fvuex-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsn%2Fvuex-assert/lists"}