{"id":16847518,"url":"https://github.com/fabiosantoscode/wentto","last_synced_at":"2026-06-18T23:32:04.049Z","repository":{"id":16038102,"uuid":"18781950","full_name":"fabiosantoscode/wentto","owner":"fabiosantoscode","description":"Some kind of goto using a sequence of functions. Can't break out of nested loops but you can use a labelled break for that.","archived":false,"fork":false,"pushed_at":"2015-02-26T18:17:47.000Z","size":157,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T07:17:17.888Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/fabiosantoscode.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":"2014-04-15T00:39:44.000Z","updated_at":"2021-03-14T20:40:27.000Z","dependencies_parsed_at":"2022-09-24T11:01:31.933Z","dependency_job_id":null,"html_url":"https://github.com/fabiosantoscode/wentto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fabiosantoscode/wentto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fwentto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fwentto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fwentto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fwentto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fabiosantoscode","download_url":"https://codeload.github.com/fabiosantoscode/wentto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fabiosantoscode%2Fwentto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34511617,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"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":[],"created_at":"2024-10-13T13:08:15.297Z","updated_at":"2026-06-18T23:32:04.027Z","avatar_url":"https://github.com/fabiosantoscode.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wentto [![Build Status](https://secure.travis-ci.org/fabiosantoscode/wentto.png?branch=master)](http://travis-ci.org/fabiosantoscode/wentto)\n\nGOTO in Javascripts. Considered harmful.\n\n## Getting Started\nInstall the module with: `npm install wentto`\n\n```javascript\nvar wentto = require('wentto');\n\nvar doSomethingComplicated = wentto([\n    function preCheck(go) {\n        if (something) { return go('fail') }\n        else if (somethingElse) { return go('fail') }\n    },\n    function doTheThing(go) {\n        // Do the thing...\n    },\n    ['fail', function fail(go) {\n        // Handle errors here\n    }]\n])\n```\n\n## Documentation\n\n### require('wentto')([func0, func1, func2, func3, ...])\nPass it an array of functions. Make sure all of them accept the function \"go\" as a parameter.\n\n`wentto` returns a function. That function will execute `func0`, then `func1`, etc. If one of these functions returns `go(\u003cindex\u003e)`, execution continues at `func\u003cindex\u003e`.\n\n### return go(index)\nGo to a function. The `index` argument is the index of the function in the array you passed to `wentto()`. So `return go(0)` to go back to the first function, `return go(2)` to go to the second function.\n\n### return go(label)\nGo to a function which has a name. See the example below, \"naming your goto labels\", to see how to give your functions a name.\n\n### return go(indexOrLabel, args...)\nCalls the next function (see the 2 above entries) with the arguments you passed.\n\n## Examples\n### achieving a loop\n```javascript\nvar a = 0;\nvar doSomethingUntil = wentto([\n    function doSomething(go) {\n        a += 1;\n    },\n    function until(go) {\n        if (a \u003c 3) {\n            return go(0);\n        }\n    }\n])\n\ndoSomethingUntil();\n\na // -\u003e 3\n```\n\n### accepting parameters\njust add them to every function after the \"go\" param\n\n```javascript\nvar justSum = wentto([\n    function (go, a, b) {\n        return a + b;\n    },\n])\n\njustSum(1, 2) // -\u003e 3\n```\n\n### returning early\nJust return anything which is not `undefined` or `go(somewhere)`\n\n```javascript\nvar dontGoFar = wentto([\n    function (go) { return 42 },\n    function neverExecuted(go) {}\n])\n```\n\n### naming your goto labels\nIt can become complicated to deal with numeric indices in a large wentto chain. \n\nTo give names to your functions, just wrap them in a pair (`[name, yourFunction]`). You don't have to give a name to every function.\n\n```javascript\nvar myFunc = wentto([\n    function (go) { if (something) return go('fail') },\n    ['fail', function (go) { throw something }]\n])\n```\n\n\n## How does it work?\nIt's just a for loop which executes the input functions one by one. `go` is actually a class which wraps the index of the function you want to go to. If one of the functions returns an instance of `go`, the loop variable is changed (`i = newIndex + 1; continue;`).\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n\n - 0.0.4 Passing arguments to the next function\n - 0.0.3 Documentation fix\n - 0.0.2 Adds the possibility of naming each function in the `wentto()` chain.\n - 0.0.1 Implemented core functionality: passing an array of functions and using go() to goto other functions.\n\n## License\nCopyright (c) 2014 Fábio Santos. Licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiosantoscode%2Fwentto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffabiosantoscode%2Fwentto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffabiosantoscode%2Fwentto/lists"}