{"id":16778909,"url":"https://github.com/jeasonnow/choicejs","last_synced_at":"2025-07-13T18:38:00.402Z","repository":{"id":57198181,"uuid":"160446557","full_name":"jeasonnow/choiceJs","owner":"jeasonnow","description":"Use choiceJs instead of if...else...","archived":false,"fork":false,"pushed_at":"2018-12-29T03:19:55.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-26T23:58:15.369Z","etag":null,"topics":["choice","else","if"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/jeasonnow.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}},"created_at":"2018-12-05T02:13:30.000Z","updated_at":"2024-10-27T02:30:10.000Z","dependencies_parsed_at":"2022-09-16T13:12:31.615Z","dependency_job_id":null,"html_url":"https://github.com/jeasonnow/choiceJs","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonnow%2FchoiceJs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonnow%2FchoiceJs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonnow%2FchoiceJs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jeasonnow%2FchoiceJs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jeasonnow","download_url":"https://codeload.github.com/jeasonnow/choiceJs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243922773,"owners_count":20369430,"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":["choice","else","if"],"created_at":"2024-10-13T07:29:00.580Z","updated_at":"2025-03-16T19:43:33.496Z","avatar_url":"https://github.com/jeasonnow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#### choicejs\n[![Build Status](https://travis-ci.org/jeasonnow/choiceJs.svg?branch=master)](https://travis-ci.org/jeasonnow/choiceJs)\n[![Build version](https://img.shields.io/badge/npm-v1.1.1-green.svg)](https://github.com/jeasonnow/choiceJs)\n\n##### install\n你可以通过`yarn`或者`npm`安装`choicejs`\n```\n$ npm install choicejs\n$ yarn add choicejs\n```\n\n#### require or import\n```\nconst choicejs = require('choicejs').Choice;\n\nimport { Choice } from 'choicejs'\n```\n\n####  usage\n\n\u003e add(description: string, condition: boolean, callback: any, extend?: string)\n\n该方法是用来增加你的选择的，有四个参数，`description`代表你对当前选择的描述，该项千万不要重复，否则后面增加的选择会覆盖之前的，第二个选项就是判断条件，第三个代指满足判断条件时的回调方法，最后一个参数为可选参数，代指继承于某项描述，就好比嵌套的`if...else`嵌套于某个条件一样。\n\n一个栗子：\n```\nconst judgeTree = new Choice();\n\nconst logAisBiggerThan1() {\n  console.log('a \u003e 1')\n};\n\nconst logAisSmallerThan9() {\n  console.log('a \u003c 9');\n}\n\nconst a = 3;\n\njudgeTree\n  .add('biggerThan1', a \u003e 1, logAisBiggerThan1)\n  .add('smallerThan9', a \u003c 9, logAisSmallerThan9, 'biggerThan1')\n```\n\n\u003e use()\n\n简单暴力的方法，`add`用来定义，而`use`就是用来执行。如果没有`use`，那么定义好的决策树就像是一个定义好的函数，没有`()`它就毫无卵用~\n\n栗子：\n```\njudgeTree.use();\n\n// 注意，judgeTree 是支持链式调用的，所以放心大胆地将 use() 接在 add() 之后使用吧~\n```\n\n\u003e destroy()                                 \n\n简单的销毁方法，使用完之后可以选择清空当前实例中的所有信息，通常作为最后一步使用，在此就不举例啦~\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeasonnow%2Fchoicejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeasonnow%2Fchoicejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeasonnow%2Fchoicejs/lists"}