{"id":22186065,"url":"https://github.com/rstuven/fsa-creator","last_synced_at":"2025-07-26T19:31:57.742Z","repository":{"id":57242395,"uuid":"43523526","full_name":"rstuven/fsa-creator","owner":"rstuven","description":"Flux Standard Action creation with schema validation.","archived":false,"fork":false,"pushed_at":"2016-08-18T14:32:39.000Z","size":103,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-13T12:19:11.632Z","etag":null,"topics":["action","flux","fsa","redux"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rstuven.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-01T22:00:10.000Z","updated_at":"2024-09-29T10:56:11.000Z","dependencies_parsed_at":"2022-09-09T04:00:29.738Z","dependency_job_id":null,"html_url":"https://github.com/rstuven/fsa-creator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Ffsa-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Ffsa-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Ffsa-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rstuven%2Ffsa-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rstuven","download_url":"https://codeload.github.com/rstuven/fsa-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227707776,"owners_count":17807557,"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":["action","flux","fsa","redux"],"created_at":"2024-12-02T10:19:55.882Z","updated_at":"2024-12-02T10:19:56.517Z","avatar_url":"https://github.com/rstuven.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"fsa-creator\n===========\n\n[![build status](https://img.shields.io/travis/rstuven/fsa-creator/master.svg?style=flat-square)](https://travis-ci.org/rstuven/fsa-creator)\n[![npm version](https://img.shields.io/npm/v/fsa-creator.svg?style=flat-square)](https://www.npmjs.com/package/fsa-creator)\n\n[Flux Standard Action](https://github.com/acdlite/flux-standard-action) creation with schema validation.\n\n```js\nnpm install --save fsa-creator\n```\n\nThis module started as a fork of [redux-actions](https://github.com/acdlite/redux-actions) by Andrew Clark.\nIt focuses in the creation of actions with handy specifications of mapping functions and schema validation.\n\n### `createAction(type, ?payloadSpec, ?metaSpec)`\n\n`payloadSpec` and `metaSpec` are *mapping function specifications* for `payload`and `meta` properties, respectively.\n\nReturns an action creator function with following signature:\n\n##### `function actionCreator(?payloadInput, ?metaInput)`\n\n`payloadInput` and `metaInput` are the input of the respective mapping function.\n\nA mapping function specification can be:\n\n#### – `undefined` or `false` (omission)\n\nThe property (`payload` or `meta`) will be omitted.\n\n#### – Function (mapping)\n\nA mapping function will be used.\n\nExample:\n\n```js\nlet actionCreator = createAction('ACTION', arg =\u003e '(u' + arg + 'u)');\n\nexpect(actionCreator('.')).to.deep.equal({\n  type: 'ACTION',\n  payload: '(u.u)'\n});\n```\n\n#### – `true` (identity mapping without validation)\n\nThe identity function will be used.\n\nExample:\n\n```js\nlet increment = createAction('INCREMENT', true);\n// same as\nincrement = createAction('INCREMENT', amount =\u003e amount);\n\nexpect(increment(42)).to.deep.equal({\n  type: 'INCREMENT',\n  payload: 42\n});\n```\n\n#### – Plain object (identity mapping with validation)\n\nA validated identity function will be used. [JSONSchema v4](http://json-schema.org/) validation powered by [is-my-json-valid](https://github.com/mafintosh/is-my-json-valid).\n\nExample:\n\n```js\n\nlet actionCreator = createAction('ACTION', {\n  required: true,\n  type: 'object',\n  properties: {\n    hello: {\n      required: true,\n      type: 'string',\n      description: 'A greeting'\n    }\n  }\n});\n\nexpect(actionCreator()).to.deep.equal({\n  type: 'ACTION',\n  error: true,\n  payload: new Error('payload is required')\n});\n\nexpect(actionCreator({})).to.deep.equal({\n  type: 'ACTION',\n  error: true,\n  payload: new Error('payload.hello is required')\n});\n\nexpect(actionCreator({hello: 123})).to.deep.equal({\n  type: 'ACTION',\n  error: true,\n  payload: new Error('payload.hello is the wrong type')\n});\n\nexpect(actionCreator({hello: 'world'})).to.deep.equal({\n  type: 'ACTION',\n  payload: {hello: 'world'}\n});\n```\n\n#### – Array (property extraction)\n\nA property extraction function will be used. This is thought to be used as a fast way of document expected properties, without defining a schema (yet).\n\nExample:\n\n```js\nlet actionCreator = createAction('ACTION', ['prop1', 'prop3']);\n\nexpect(actionCreator({prop1: 1, prop2: 2, prop3: 3})).to.deep.equal({\n  type: 'ACTION',\n  payload: {\n    prop1: 1,\n    prop3: 3\n  }\n});\n```\n\n---\n**NOTE:** The more correct name for `createAction` function probably is `createActionCreator()`, but that seems a bit redundant.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstuven%2Ffsa-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frstuven%2Ffsa-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frstuven%2Ffsa-creator/lists"}