{"_id":"@basementuniverse/simple-state-machine","_rev":"2-1110ed226b38d995d3708bbce80469fa","name":"@basementuniverse/simple-state-machine","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@basementuniverse/simple-state-machine","version":"1.0.0","description":"Define finite state machines and validate state transitions","main":"build/index.js","scripts":{"build":"tsc","test":"npx jest ./test"},"keywords":["fsm","finite","state","machine","transition"],"author":{"name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com","url":"https://gordonlarrigan.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/basementuniverse/simple-state-machine.git"},"devDependencies":{"@types/jest":"^26.0.24","@types/node":"^16.4.1","jest":"^27.0.6","ts-jest":"^27.0.4","typescript":"^4.3.5"},"jest":{"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":"tsconfig.jest.json"}}},"gitHead":"c599db881ec8b51c30b887a3e568fff677db4133","bugs":{"url":"https://github.com/basementuniverse/simple-state-machine/issues"},"homepage":"https://github.com/basementuniverse/simple-state-machine#readme","_id":"@basementuniverse/simple-state-machine@1.0.0","_nodeVersion":"16.7.0","_npmVersion":"7.20.3","dist":{"integrity":"sha512-jRE0mWLM0P2C6cAr78jGDcXjGz3r7Zv90PAItsjCEBk/WwErJEdA+3/M3GhnEjv3vodN9HqfJLyn6u7DWzUaDQ==","shasum":"254d0e7b0d869f130ec126f85a6a737b8af746ac","tarball":"https://registry.npmjs.org/@basementuniverse/simple-state-machine/-/simple-state-machine-1.0.0.tgz","fileCount":10,"unpackedSize":10988,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiD8H5ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrfrg/8CILl8rNQv4k2j6J0F3utsKMY4AGZ1FJA4WKo7DtqeZeWM4na\r\nJZYRNYE3qlZdIZHUy+2t5DduA5WepZDRnIeB5xpvXatVQMZZIZNA4+OOrSr1\r\nlDQ47pkzh15ceceuW/KyXdYm+dRJKApv7cBvOsG3bRfJeib+sa94XNPgjT+Z\r\nntXUinZzDwmw5za6zLTDXSBAuFm+ppw1fYABVoNIKGv0n8JixpdZouxIyoQg\r\nevK5C/qzHYtxcCnlo/FfA7/fHmmsOpjqsuUw+MdO9E7SLd+LG3Zuhno3OUkE\r\nM9prkzeoKtYGDrc60DJSDzea0puyqMzGLea9nzTYvEUSTOjBqQ4fqEk+R4Ug\r\nE3CU/qcOaronAQC4FLy5cIW1tmEvy5goEg+s5N8r5kNojSYFQAoj6jwmnNM5\r\nwyPrFAxUjsiEcC7qqMA9dMgPX8BLVFBPTRAPuWmK8HccEkQYTIpQNivO+2jk\r\nsfV35/EpZSWt/2RWvCggMJdK7+q3RD0v0ZgmJtdj+OWM8wz2ZlCVKLLEJK8H\r\nXEM6zGx3SIM5oak4x8D2TSLgUk6Bu0dNcM3BarwRHEAVTTwKYKsSPBrYEoSV\r\nlpWvD+V/RN0d8neq673ndNUjsAzHpbDJ2eijyjDlFdgc/kgUDKfY5c4kmlBU\r\n7Q+Rfw21eBmAl9GZgNC5DnAZqFRPczqBIFs=\r\n=UT7f\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCWVKWG5CzKs1+cu1VZN3JFJqxOwtzM5NjiZrSceBw+pAIhAJmrH2DK+BIHFDEbtpI5vht20uj98YvTtJLubfK5kUNe"}]},"_npmUser":{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"},"directories":{},"maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-state-machine_1.0.0_1645199865504_0.9256924445793364"},"_hasShrinkwrap":false},"2.0.0":{"name":"@basementuniverse/simple-state-machine","version":"2.0.0","description":"Define finite state machines and validate state transitions","main":"build/index.js","scripts":{"build":"tsc","test":"npx jest ./test"},"keywords":["fsm","finite","state","machine","transition"],"author":{"name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com","url":"https://gordonlarrigan.com"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/basementuniverse/simple-state-machine.git"},"devDependencies":{"@types/jest":"^26.0.24","@types/node":"^16.4.1","jest":"^27.0.6","ts-jest":"^27.0.4","typescript":"^4.3.5"},"jest":{"preset":"ts-jest","testEnvironment":"node","globals":{"ts-jest":{"tsConfig":"tsconfig.jest.json"}}},"types":"./build/index.d.ts","gitHead":"c4a5f6e5f49b9d98cf1033d31682b55383184507","bugs":{"url":"https://github.com/basementuniverse/simple-state-machine/issues"},"homepage":"https://github.com/basementuniverse/simple-state-machine#readme","_id":"@basementuniverse/simple-state-machine@2.0.0","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-sqrQ+BuG0DJIkkHWzaycs5gq3Z9k/klrVRrpb2okFgXG9en3BNeUxjxQKWQpWyGiCqxe1VK/IlNwoXifrc2F2w==","shasum":"35d27386089ddd554c301825e1c76d512556b1a8","tarball":"https://registry.npmjs.org/@basementuniverse/simple-state-machine/-/simple-state-machine-2.0.0.tgz","fileCount":10,"unpackedSize":13846,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCEd5N2imq8vrNTZAkRmJ5tNDNe/3gYko+oUEo17UFP7QIgNHAb4dJJe33awh5TEnuHcJjNtTmaEBzGqf9URvx61RU="}]},"_npmUser":{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"},"directories":{},"maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/simple-state-machine_2.0.0_1698236572445_0.09573859735771606"},"_hasShrinkwrap":false}},"time":{"created":"2022-02-18T15:57:45.453Z","1.0.0":"2022-02-18T15:57:45.626Z","modified":"2023-10-25T12:22:52.803Z","2.0.0":"2023-10-25T12:22:52.631Z"},"maintainers":[{"name":"basementuniverse","email":"gordonlarrigan@gmail.com"}],"description":"Define finite state machines and validate state transitions","homepage":"https://github.com/basementuniverse/simple-state-machine#readme","keywords":["fsm","finite","state","machine","transition"],"repository":{"type":"git","url":"git+https://github.com/basementuniverse/simple-state-machine.git"},"author":{"name":"Gordon Larrigan","email":"gordonlarrigan@gmail.com","url":"https://gordonlarrigan.com"},"bugs":{"url":"https://github.com/basementuniverse/simple-state-machine/issues"},"license":"MIT","readme":"# Simple State Machine\n\nDefine finite state machines and validate state transitions.\n\nThis library doesn't currently provide state-change events or methods for transitioning between states; all it does is provide a format for defining state machines, and a method for checking that a given transition is valid.\n\n## Installation\n\n```\nnpm install @basementuniverse/simple-state-machine\n```\n\n## Usage\n\n```typescript\nimport {\n  StateMachine,\n  validateTransition,\n} from '@basementuniverse/simple-state-machine';\n\n// Define a finite state machine\nconst myStateMachine: StateMachine = {\n  open: [\n    'closedAndUnlocked',\n  ],\n  closedAndUnlocked: [\n    'open',\n    'closedAndLocked',\n  ],\n  closedAndLocked: [\n    'closedAndUnlocked',\n  ],\n};\n\n// Let's validate some transitions...\nlet result: boolean = false;\n\n// Test #1\nresult = validateTransition(\n  myStateMachine,\n  'open',\n  'closedAndUnlocked'\n);\n\n// result will be true (this is a valid transition)\nconsole.assert(result);\n\n\n// Test #2\nresult = validateTransition(\n  myStateMachine,\n  'closedAndLocked',\n  'open'\n);\n\n// result will be false (this is not a valid transition)\nconsole.assert(!result);\n\n\n// Test #3\nresult = validateTransition(\n  myStateMachine,\n  'open',\n  'closedAndLocked',\n  {\n    throwErrors: true,\n  }\n);\n// this will throw an error with the message:\n// \"Invalid state transition: unable to transition from 'open' to 'closedAndLocked'.\"\n\n// Test #4\nresult = validateTransition(\n  myStateMachine,\n  'open',\n  'open',\n  {\n    allowSelfTransition: true,\n  }\n);\n\n// result will be true (this is a valid transition even though it's not explicitly defined)\nconsole.assert(result);\n```\n\n## Options\n\nThe `validateTransition` function accepts an optional `options` object as its fourth argument. The following options are available:\n\n| Option | Type | Default | Description |\n| --- | --- | --- | --- |\n| `allowSelfTransition` | `boolean` | `true` | If `true`, a transition from a state to itself will be considered valid. |\n| `throwErrors` | `boolean` | `false` | If `true`, an error will be thrown if the transition is invalid. |\n","readmeFilename":"README.md"}