{"id":24081487,"url":"https://github.com/beh01der/node-easy-flow","last_synced_at":"2025-04-30T16:26:54.397Z","repository":{"id":65460456,"uuid":"39116254","full_name":"Beh01der/node-easy-flow","owner":"Beh01der","description":"Simple and easy to use Finite State Machine for Node.js (similar to EasyFlow for Java)","archived":false,"fork":false,"pushed_at":"2016-11-30T05:46:44.000Z","size":24,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-18T06:51:38.692Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Beh01der.png","metadata":{"files":{"readme":"README-v1.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}},"created_at":"2015-07-15T04:29:49.000Z","updated_at":"2021-10-28T02:46:45.000Z","dependencies_parsed_at":"2023-01-24T14:45:19.756Z","dependency_job_id":null,"html_url":"https://github.com/Beh01der/node-easy-flow","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beh01der%2Fnode-easy-flow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beh01der%2Fnode-easy-flow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beh01der%2Fnode-easy-flow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Beh01der%2Fnode-easy-flow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Beh01der","download_url":"https://codeload.github.com/Beh01der/node-easy-flow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233270923,"owners_count":18650866,"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":[],"created_at":"2025-01-09T23:16:59.018Z","updated_at":"2025-01-09T23:16:59.489Z","avatar_url":"https://github.com/Beh01der.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-easy-flow\n\nSimple and easy to use Finite State Machine (FSM) for Node.js (similar to EasyFlow for Java).\n\nThis library greatly simplifies development of asynchronous event-driven applications. \n\nThanks to its convenient hierarchical transition builder, logic of complex applications remains clear and application itself manageable.\n\nUsecase for `node-easy-flow` is somehow similar to `async.series()` or `async.waterfall()` (see [here](https://github.com/caolan/async)), only `node-easy-flow` is more suitable for handling complex, non-linear logic.\n     \n## Install\nInstall locally\n```\nnpm install node-easy-flow\n```\n\n## Quick start\nFSM is defined with `node-easy-flow` through combination of transitions and handlers\n```javascript\nvar EasyFlow = require('node-easy-flow/lib/easy-flow-v1');\n\nvar flow = EasyFlow.create(function (from, on, to, finish, trigger, whenEnter) {\n    // states\n    var SHOWING_WELCOME = 'SHOWING_WELCOME',\n        WAITING_FOR_PIN = 'WAITING_FOR_PIN',\n        CHECKING_PIN = 'CHECKING_PIN',\n        SHOWING_MAIN_MENU = 'SHOWING_MAIN_MENU',\n        SHOWING_BALANCE = 'SHOWING_BALANCE',\n        ...\n\n    // events\n    var cardPresent = 'cardPresent',\n        pinProvided = 'pinProvided',\n        pinValid = 'pinValid',\n        cancel = 'cancel',\n        menuShowBalance = 'menuShowBalance',\n        ...\n\n    // transition definitions\n    from(SHOWING_WELCOME,\n        on(cardPresent, to(WAITING_FOR_PIN,\n            on(pinProvided, to(CHECKING_PIN,\n                on(pinValid, to(SHOWING_MAIN_MENU,\n                    on(menuShowBalance, to(SHOWING_BALANCE,\n                        on(cancel, to(SHOWING_MAIN_MENU))\n                    )),\n                    ...\n                ))\n                ...\n            ))\n            ...\n        ))\n        ...\n    );\n\n    // handler definitions\n    whenEnter(SHOWING_WELCOME, function (context) {\n        console.log('\\n\\n*** Welcome ***\\n');\n        context.invalidPinCounter = 0;\n        rl.question('Select your option and press [Enter]...\\n 1 Insert card\\n 2 Terminate ATM\\n', function (option) {\n            trigger(option == 1 ? cardPresent : switchOff, context);\n        });\n    });\n\n    whenEnter(WAITING_FOR_PIN, function (context) {\n        console.log('\\n\\n*** Waiting for PIN ***\\n');\n        rl.question('Please enter your PIN and press [Enter] or just press [Enter] to cancel (current PIN is 1234)...\\n', function (pin) {\n            if (pin.length === 4) {\n                context.pin = pin;\n                trigger(pinProvided, context);\n            } else {\n                trigger(cancel, context);\n            }\n        });\n    });\n    ...\n});\n    \n```\n\nThen it can be started using `context` object\n```javascript\n\nflow.start({ balance: 1000 });\n\n```\nSee full example [here](https://github.com/Beh01der/node-easy-flow/blob/master/lib/atm-example-v1.js)\n\n## See also\n[EasyFlow for Java](https://github.com/Beh01der/EasyFlow)\n\n## License \n**ISC License (ISC)**\n\nCopyright (c) 2015, Andrey Chausenko \u003candrey.chausenko@gmail.com\u003e\n\nPermission to use, copy, modify, and/or distribute this software for any\npurpose with or without fee is hereby granted, provided that the above\ncopyright notice and this permission notice appear in all copies.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\nWITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\nANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\nWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\nACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\nOR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeh01der%2Fnode-easy-flow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeh01der%2Fnode-easy-flow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeh01der%2Fnode-easy-flow/lists"}