{"id":16286350,"url":"https://github.com/sravan-s/control-tree","last_synced_at":"2025-06-10T17:38:41.636Z","repository":{"id":98933948,"uuid":"79902541","full_name":"sravan-s/control-tree","owner":"sravan-s","description":"Javascript library to convert your control flow into a data structure :deciduous_tree:","archived":false,"fork":false,"pushed_at":"2017-01-28T07:29:38.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T05:14:36.054Z","etag":null,"topics":["control-flow","control-tree","javascript-library"],"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/sravan-s.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":"2017-01-24T10:46:37.000Z","updated_at":"2017-01-29T05:53:00.000Z","dependencies_parsed_at":"2023-04-01T03:38:22.003Z","dependency_job_id":null,"html_url":"https://github.com/sravan-s/control-tree","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/sravan-s%2Fcontrol-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sravan-s%2Fcontrol-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sravan-s%2Fcontrol-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sravan-s%2Fcontrol-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sravan-s","download_url":"https://codeload.github.com/sravan-s/control-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sravan-s%2Fcontrol-tree/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259118732,"owners_count":22808041,"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":["control-flow","control-tree","javascript-library"],"created_at":"2024-10-10T19:42:54.721Z","updated_at":"2025-06-10T17:38:41.567Z","avatar_url":"https://github.com/sravan-s.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# control-tree\nJavascript library to convert your control flow into a data structure\n\n[![Build Status](https://travis-ci.org/sravan-s/control-tree.svg?branch=master)](https://travis-ci.org/sravan-s/control-tree)\n[![codecov](https://codecov.io/gh/sravan-s/control-tree/branch/master/graph/badge.svg)](https://codecov.io/gh/sravan-s/control-tree)\n\nBased on https://hackernoon.com/you-might-not-need-if-statements-a-better-approach-to-branching-logic-59b4f877697f#.ls40q37si\n\nThe decision tree could be a function or an object with a specific structure\n```\n{\n  type: 'ASYNC', // Type can be ASYNC or undefined\n  action: () =\u003e {}, // always get executed first\n  test: cb =\u003e {\n    asyncFn // cb is only avaiable with ASYNC functions\n      .then((err, data) =\u003e {\n        if (err) { cb(false) }\n        if (data) { cb(true) }\n      });\n  },\n  true: () =\u003e {}, // what to with when test is true\n  false: {\n    action: () =\u003e {},\n    test: () =\u003e {},\n    true: () =\u003e {},\n    false: () =\u003e {} // true and false could be objects or functions\n  }\n}\n```\n\nexample:\n\n```\nfunction testTree(param) {\n  return {\n    action: () =\u003e {\n      console.log('Tree init');\n    },\n    test: () =\u003e {\n      return param.a \u003e param.b;\n    },\n    true: () =\u003e {\n      return {\n        action: () =\u003e {\n          console.log('a \u003e b is true')\n        }\n      }\n    },\n    false: () =\u003e {\n      return {\n        type: 'ASYNC',\n        action: () =\u003e {\n          console.log('a \u003e b is false');\n        },\n        test: cb =\u003e {\n          setTimeout(() =\u003e {\n            if (param.b \u003e param.a) {\n              cb(true);\n            } else {\n              cb(false);\n            }\n          }, 2000);\n        },\n        true: () =\u003e {\n          console.log('b \u003e a is true');\n        },\n        false: () =\u003e {\n          console.log('b \u003e a is false');\n        }\n      }\n    }\n  }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsravan-s%2Fcontrol-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsravan-s%2Fcontrol-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsravan-s%2Fcontrol-tree/lists"}