{"name":"fsm-base","author":{"name":"Lloyd Brookes","email":"75pound@gmail.com"},"version":"0.8.0","description":"Finite state machine base class","repository":{"type":"git","url":"git+https://github.com/75lb/fsm-base.git"},"license":"MIT","type":"module","exports":{"import":"./index.js","require":"./dist/index.cjs"},"keywords":["finite","state","machine","base","class","isomorphic","load-anywhere"],"engines":{"node":">=14"},"scripts":{"test":"npm run dist && npm run test:ci","test:ci":"test-runner test.js","docs":"jsdoc2md -t README.hbs index.js > README.md","dist":"rollup -c"},"devDependencies":{"@rollup/plugin-node-resolve":"^15.0.1","jsdoc-to-markdown":"^8.0.0","rollup":"^3.19.1","test-runner":"^0.10.1"},"dependencies":{"array-back":"^6.2.2"},"standard":{"ignore":["dist"]},"gitHead":"feb64059eb6b166598a25ba72abe0f8587541a98","bugs":{"url":"https://github.com/75lb/fsm-base/issues"},"homepage":"https://github.com/75lb/fsm-base#readme","_id":"fsm-base@0.8.0","_nodeVersion":"19.7.0","_npmVersion":"9.6.0","dist":{"integrity":"sha512-isgmHo9C9QkcWjg2wEGxQ+c2810JzK6sZUrqcZyMr28s0Nxm73KI/JfhSB1/FNC8Tjq4Dh4Nsx8InLNyBmUFrg==","shasum":"3d3ed06711dddfc294efafe6a6e0c62f293cb614","tarball":"http://registry-npm.ywwl.com/fsm-base/download/fsm-base-0.8.0.tgz","fileCount":7,"unpackedSize":20018,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGanuneaa0NlJy51eO7yb+0KzTJUaa1auF221PelzFoyAiAmHcGMNBINmZJdo1swqYQE26bcSs2R6o/KdbW+C3zozg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkDGPxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoX7w//Zq0qtCrxo+Tl7VeJQGtPiimKEeuRQHbAo07+Yrm8VmxmokOw\r\nWpHTJrI1XWaHSyclTbTGnLdXcfbnq5o4EGGauR9Z5glmu4elIltz4ETsLHb7\r\n3sx0M6oDiCkHrMbEdmljLCeU3w3ZXcjvGd+k29ZjtC16nTten8z4oScJ403B\r\na1GZipHczbU1X8XVnamSWqClg/Ok+l19YQIAhWTpFPkmwze3gcvzI7zReiXY\r\nrPVAMWIjBGGDvBxNVE4F3ilKXA/liaZ/9y4p+F9/z0JsYPNraYynYUBPWA1U\r\nXIj75jIEcTLa0HxLLgVdSK1pbqIbwuTX3tPIPEtWpEWsgwxLqGuz013Q9XaP\r\nxGvSxF7M2VzQ6VktEc8MWhFuQfV2f6WyaS+dsQu/oE27TKZmQntlyt7GZEz7\r\njGh1a34wome7BkAFjlMIat0SOjMR7YsatF2rcPJSVzIOXGK83DgRZnRZecZC\r\n4xVu+XD+CQ/uPKr443HzRFKAMKrKDfRcUgkYd3NDGUR2JViJkjyiC3Do8wUb\r\n3eA/vb9CSKdagUr0tOYZz0pHaiR+pSdDZJGZoWTjqMHE1dJDRsJUjh2aad+K\r\nwEADAn6NMUoX+I3fikSMCj7kyLvuEgcfHKTgEIW7QfqqHsQrWfD0VEHxSsI1\r\n2VbgfmdkC9E6AkM59j9+aYdRuWWoVfIMjKA=\r\n=yo6V\r\n-----END PGP SIGNATURE-----\r\n","size":3955,"noattachment":false,"key":"/fsm-base/-/fsm-base-0.8.0.tgz"},"_npmUser":{"name":"75lb","email":"75pound@gmail.com"},"directories":{},"maintainers":[{"name":"75lb","email":"75pound@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fsm-base_0.8.0_1678533617771_0.5401513796339152"},"_hasShrinkwrap":false,"readme":"[![view on npm](https://badgen.net/npm/v/fsm-base)](https://www.npmjs.org/package/fsm-base)\n[![npm module downloads](https://badgen.net/npm/dt/fsm-base)](https://www.npmjs.org/package/fsm-base)\n[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/fsm-base)](https://github.com/75lb/fsm-base/network/dependents?dependent_type=REPOSITORY)\n[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/fsm-base)](https://github.com/75lb/fsm-base/network/dependents?dependent_type=PACKAGE)\n[![Node.js CI](https://github.com/75lb/fsm-base/actions/workflows/node.js.yml/badge.svg)](https://github.com/75lb/fsm-base/actions/workflows/node.js.yml)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](https://github.com/feross/standard)\n\n# fsm-base\n\nFinite state machine.\n\nEither mix it into an existing object:\n\n```js\nimport StateMachine from 'fsm-base'\n\nconst exampleClient = {}\n\nStateMachine.mixInto(exampleClient, 'offline', [\n  { from: 'offline', to: 'connecting' },\n  { from: 'connecting', to: 'online' },\n  { from: ['connecting', 'online'], to: 'offline' }\n])\n\nexampleClient._onStateChange = function (state, prevState) {\n  console.log(`Moved to ${state} from ${prevState}`)\n}\n\nconsole.log(exampleClient.state) // Prints 'offline' - the defined initial state\nexampleClient.state = 'connecting' // valid move\nexampleClient.state = 'online' // valid move\nexampleClient.state = 'offline' // valid move\nexampleClient.state = 'something unspecified' // invalid move, throws an exception.\n```\n\n..or define a class which extends it:\n\n```js\nclass AnotherClient extends StateMachine {}\n\nconst anotherClient = new AnotherClient()\nanotherClient._initStateMachine('offline', [\n  { from: 'offline', to: 'connecting' },\n  { from: 'connecting', to: 'online' },\n  { from: ['connecting', 'online'], to: 'offline' }\n])\n\nanotherClient.state = 'connecting'\n// etc\n```\n\n\n\n<a name=\"module_fsm-base\"></a>\n\n## fsm-base\n\n* [fsm-base](#module_fsm-base)\n    * [StateMachine](#exp_module_fsm-base--StateMachine) ⏏\n        * _instance_\n            * [.state](#module_fsm-base--StateMachine+state) : <code>string</code>\n            * [._initStateMachine(initialState, validMoves)](#module_fsm-base--StateMachine+_initStateMachine)\n            * [._onStateChange(state, prevState)](#module_fsm-base--StateMachine+_onStateChange)\n            * [.resetState()](#module_fsm-base--StateMachine+resetState)\n        * _static_\n            * [.mixInto(target, initialState, validMoves)](#module_fsm-base--StateMachine.mixInto)\n\n<a name=\"exp_module_fsm-base--StateMachine\"></a>\n\n### StateMachine ⏏\n**Kind**: Exported class  \n<a name=\"module_fsm-base--StateMachine+state\"></a>\n\n#### stateMachine.state : <code>string</code>\nThe current state\n\n**Kind**: instance property of [<code>StateMachine</code>](#exp_module_fsm-base--StateMachine)  \n**Throws**:\n\n- `INVALID_MOVE` if an invalid move made\n\n<a name=\"module_fsm-base--StateMachine+_initStateMachine\"></a>\n\n#### stateMachine.\\_initStateMachine(initialState, validMoves)\n**Kind**: instance method of [<code>StateMachine</code>](#exp_module_fsm-base--StateMachine)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| initialState | <code>string</code> | Initial state, e.g. 'pending'. |\n| validMoves | <code>Array.&lt;object&gt;</code> | Array of valid move rules. |\n\n<a name=\"module_fsm-base--StateMachine+_onStateChange\"></a>\n\n#### stateMachine.\\_onStateChange(state, prevState)\nInvoked on every state change\n\n**Kind**: instance method of [<code>StateMachine</code>](#exp_module_fsm-base--StateMachine)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| state | <code>string</code> | the new state |\n| prevState | <code>string</code> | the previous state |\n\n<a name=\"module_fsm-base--StateMachine+resetState\"></a>\n\n#### stateMachine.resetState()\nReset to initial state.\n\n**Kind**: instance method of [<code>StateMachine</code>](#exp_module_fsm-base--StateMachine)  \n<a name=\"module_fsm-base--StateMachine.mixInto\"></a>\n\n#### StateMachine.mixInto(target, initialState, validMoves)\n**Kind**: static method of [<code>StateMachine</code>](#exp_module_fsm-base--StateMachine)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| target | <code>object</code> | The target to receive the state machine behaviour. |\n| initialState | <code>string</code> | Initial state, e.g. 'pending'. |\n| validMoves | <code>Array.&lt;object&gt;</code> | Array of valid move rules. |\n\n\n* * *\n\n&copy; 2015-23 Lloyd Brookes \\<75pound@gmail.com\\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).\n","publish_time":1678533617872,"_cnpm_publish_time":1678533617872,"dist-tags":{"latest":"0.9.0"}}