npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

choicejs

v1.1.1

Published

use choice make your if...else... beauty

Downloads

5

Readme

choicejs

Build Status Build version

install

你可以通过yarn或者npm安装choicejs

$ npm install choicejs
$ yarn add choicejs

require or import

const choicejs = require('choicejs').Choice;

import { Choice } from 'choicejs'

usage

add(description: string, condition: boolean, callback: any, extend?: string)

该方法是用来增加你的选择的,有四个参数,description代表你对当前选择的描述,该项千万不要重复,否则后面增加的选择会覆盖之前的,第二个选项就是判断条件,第三个代指满足判断条件时的回调方法,最后一个参数为可选参数,代指继承于某项描述,就好比嵌套的if...else嵌套于某个条件一样。

一个栗子:

const judgeTree = new Choice();

const logAisBiggerThan1() {
  console.log('a > 1')
};

const logAisSmallerThan9() {
  console.log('a < 9');
}

const a = 3;

judgeTree
  .add('biggerThan1', a > 1, logAisBiggerThan1)
  .add('smallerThan9', a < 9, logAisSmallerThan9, 'biggerThan1')

use()

简单暴力的方法,add用来定义,而use就是用来执行。如果没有use,那么定义好的决策树就像是一个定义好的函数,没有()它就毫无卵用~

栗子:

judgeTree.use();

// 注意,judgeTree 是支持链式调用的,所以放心大胆地将 use() 接在 add() 之后使用吧~

destroy()

简单的销毁方法,使用完之后可以选择清空当前实例中的所有信息,通常作为最后一步使用,在此就不举例啦~