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

switch-master

v0.3.2

Published

Switch Master, when you have many switch coupling logic, you need it! 开关管家,当你有许多开关逻辑耦合时,你需要它!

Downloads

5

Readme

switch-master

switch-master blog

Switch Master, when you have many switch coupling logic, you need it!

开关管家,当你有许多开关逻辑耦合时,你需要它!

中文文档

Run Simple Demo

$ git clone https://github.com/SuperYesifang/switch-master.git
$ cd switch-master
$ npm run serve

Usage

new SwitchMaster(configs:SwitchOption[]):SwitchMaster

1. Use CDN

<script src="https://raw.githubusercontent.com/SuperYesifang/switch-master/master/dist/SwitchMaster.cdn.js"></script>
<script>
let master = new SwitchMaster([
  { name: "panel1", status: true },
  { name: "panel2", status: false },
  { name: "panel3", status: false },
  { name: "panel4", status: false }
]);
</script>

2. Use ESM

import SwitchMaster from "switch-master";

let master = SwitchMaster([
  { name: "panel1", status: true },
  { name: "panel2", status: false },
  { name: "panel3", status: false },
  { name: "panel4", status: false }
]);

switchOption

| prop | type | description | | ---------- | ------ | -------------------------------------------------------------------- | | id | string | switch's unique id. default SwitchMaster will auto create random id. | | name | string | switch's name. default config.id | | status | string | switch's initial status. default false. |

API

new Switch()

new Switch(config:SwitchOption):Switch

Instantiation a switch.

new SwitchMaster()

new SwitchMaster(configs:SwitchOption[]):SwitchMaster

Instantiation a switch master.

switch.open()

switch.open()

Set the status of switch to true.

switch.close()

switch.close()

Set the status of switch to false.

switch.toggle()

switch.toggle(status:undefined | boolean)

Toggle switch's status. support custom status.

switch.onChange()

switch.onChange(listener, lazy):removeListener

Add a status change listener to switch. lazy Whether to enable lazy listening, default: false.

@types

type listener = (status:boolean):any => {}
type removeListener = () => {}
import SwitchMaster, { Switch } from "switch-master";

let s = new Switch({
  id: "panelx",
  status: true
});

let master = new SwitchMaster([
  { name: "panel1", status: true },
  { name: "panel2", status: false },
  { name: "panel3", status: false },
  { name: "panel4", status: false }
]);

master.addSwitch(s);
console.log(master.switchs);

master.switchs

master.switchs:{[id:string]:Switch}

all switchs collection of the master.

master.initialStatus

master.initialStaus:{[id:string]:boolean}

all switch's initial status collection of master.

master.addSwtich()

master.addSwtich(s:Switch|Swtich[])

add swtich(s) to master.

master.removeSwitch()

master.removeSwitch(s:Switch|Switch[])

remove switch(s) from master.

master.removeSwitchById()

master.removeSwitchById(id:string|string[])

remove switch(s) from master by id(s).

master.removeSwitchByName()

master.removeSwitchByName(name:string|string[])

remove switch(s) from master by name(s).

master.getSwitchById()

master.getSwitchById(id:string|string[]):Switch|Switch[]

get switch(s) from master by id(s).

master.getSwitchByName()

master.getSwitchByName(name:string|string[]):Switch|Array(Switch|Switch[])

get switch(s) from master by name(s).

getNameById()

master.getNameById(id:string|string[]):string|string[]

get switch's name(s) from master by id(s).

getIdByName()

master.getIdByName(name:string|string[]):string|Array<string|string[]>

get switch's id(s) from master by name(s).

openById()

master.openById(id:string|string[])

open switch by id(s).

openByName()

master.openByName(name:string|string[])

open switch by name(s).

closeById()

master.closeById(id:string|string[])

close switch by id(s).

closeByName()

master.closeByName(name:string|string[])

close switch by name(s).

toggleById()

master.toggleById(config)

toggle switch by id config.

master.toggleById('Switch__e76cfa8771c4'); // id
master.toggleById({
  'Switch__e76cfa8771c4': true,
  'Switch__10476415b997': false
}); // id:status config
master.toggleById([
  'Switch__e76cfa8771c4',
  'Switch__10476415b997'
]); // ids
master.toggleById([
  'Switch__e76cfa8771c4',
  { 'Switch__10476415b997': true }
]); // ids and id:status configs

reset()

master.reset(id?)

reset switch status to initial status by id(s)?.

@types

type config = {
  [id:string]: boolean;
}

toggleByName()

master.toggleByName(config)

toggle switch by name config.

master.toggleByName('panel1'); // name
master.toggleByName({
  'panel1': true,
  'panel3': false
}); // name:status config
master.toggleByName([
  'panel1',
  'panel3'
]); // names
master.toggleByName([
  'panel1',
  { 'panel3': true }
]); // names and name:status configs

@types

type config = {
  [name:string]: boolean;
}