{"id":15484037,"url":"https://github.com/thadeu/nanomachine","last_synced_at":"2025-08-27T13:13:00.206Z","repository":{"id":97526008,"uuid":"193190135","full_name":"thadeu/nanomachine","owner":"thadeu","description":"🔐 nanomachine is a state machine for tiny JS","archived":false,"fork":false,"pushed_at":"2019-06-22T05:14:56.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-19T06:25:23.584Z","etag":null,"topics":["aasm-js","fsm","fsm-js","nanomachine","state-machine","state-machine-js"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/thadeu.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":"2019-06-22T04:16:53.000Z","updated_at":"2019-10-02T00:10:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"1b31b768-9cb8-4dcd-975c-e6d5de1b11bb","html_url":"https://github.com/thadeu/nanomachine","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"b6cdaf8b7a196db24bdcab7abe532fd457e54fef"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/thadeu/nanomachine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fnanomachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fnanomachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fnanomachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fnanomachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thadeu","download_url":"https://codeload.github.com/thadeu/nanomachine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thadeu%2Fnanomachine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272335164,"owners_count":24916388,"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","status":"online","status_checked_at":"2025-08-27T02:00:09.397Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["aasm-js","fsm","fsm-js","nanomachine","state-machine","state-machine-js"],"created_at":"2024-10-02T05:22:01.586Z","updated_at":"2025-08-27T13:13:00.166Z","avatar_url":"https://github.com/thadeu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nanomachine\n\n[![NPM package version](https://img.shields.io/npm/v/@thadeu/nanomachine.svg)](https://www.npmjs.com/package/@thadeu/nanomachine)\n[![Build Status](https://travis-ci.org/thadeu/nanomachine.svg?branch=master)](https://travis-ci.org/thadeu/nanomachine)\n![Size](https://img.shields.io/github/size/thadeu/nanomachine/dist/nanomachine.js.svg)\n![Issues](https://img.shields.io/github/issues/thadeu/nanomachine.svg)\n![License: MIT](https://img.shields.io/github/license/thadeu/nanomachine.svg)\n\n---\n\n🔐 nanomachine is a state machine for tiny JS\n\n# How to install\n\n```bash\nyarn add @thadeu/nanomachine\n```\n\nor\n\n```bash\nnpm i @thadeu/nanomachine\n```\n\nor unpkg load script\n\n```html\n\u003cscript src=\"https://unpkg.com/@thadeu/nanomachine\"\u003e\u003c/script\u003e\n```\n\n# Usage\n\n---\n\n```js\nconst machine = nanomachine({\n  initial: 'login',\n  transitions: [\n    { name: 'login', from: '*', to: 'login' },\n    { name: 'waiting', from: ['login', 'unpause'], to: 'waiting' },\n    { name: 'pause', from: ['waiting'], to: 'pause' },\n    { name: 'unpause', from: ['pause'], to: 'waiting' },\n  ],\n  events: {\n    login: () =\u003e null,\n    waiting: () =\u003e null,\n    pause: () =\u003e null,\n    unpause: () =\u003e null,\n  },\n})\n```\n\nWith a state machine started, you have access to dynamically created methods. Like for example.\n\nIf you want to leave login and go to waiting, you can use.\n\n```js\n// state is login, right?\nmachine.waiting()\n```\n\nEverything is based on the transition `from` to `to` was configured\n\n```js\n{ name: 'waiting', from: ['login', 'unpause'], to: 'waiting' }\n```\n\nIn the case above, we say, `waiting`, you can transition from `login` or `pause` to `waiting`\nOf course, it will only happen, if there is a method created in events.\n\nThe above transition must have a method to be triggered when moving, example:\n\n```js\nconst machine = nanomachine({\n  ......\n  events: {\n    waiting: () =\u003e console.log('fired waiting')\n  }\n  ......\n})\n\n```\n\nThe waiting event, will be invoked whenever the transition is approved in the state machine\n\n# Conditionals\n\nImagine the following situation, you need to change state, only after resolving something. So!\n\n```js\nconst machine = nanomachine({\n  ......\n  transitions: [\n    { name: 'login', from: '*', to: 'login' },\n    { name: 'waiting', from: ['login', 'unpause'], to: 'waiting', if: () =\u003e true | false },\n  ],\n  ......\n})\n```\n\nor use `unless`.\n\n```js\n{ name: 'waiting', from: ['login', 'unpause'], to: 'waiting', unless: () =\u003e true }\n```\n\n# On Any Transition\n\nYou can use observers, for example\n\n```js\nconst machine = nanomachine({\n  ....\n})\n\nmachine.on('waiting', function() {\n  console.log('onWaiting')\n})\n```\n\nWhenever a `waiting` transitions occurs, this observer receives a message\n\n# Contributing\n\nOnce you've made your great commits (include tests, please):\n\n1. Fork this repository\n2. Create a topic branch - `git checkout -b my_branch`\n3. Push to your branch - `git push origin my_branch`\n4. Create a pull request\n\nThat's it!\n\nPlease respect the indentation rules and code style. And use 2 spaces, not tabs. And don't touch the version thing or distribution files; this will be made when a new version is going to be released.\n\n## License\n\n(The MIT License)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Fnanomachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthadeu%2Fnanomachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthadeu%2Fnanomachine/lists"}