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 🙏

© 2026 – Pkg Stats / Ryan Hefner

atcon

v1.0.4

Published

atom conditions

Downloads

17

Readme

atcon

atcon是什么

  1. con即condition条件,atcon,指为条件而生;
  2. at也来源atom,代表它是一个原子操作;
  3. 把复杂的if else逻辑转变为简单的原子操作,就在atcon。

atcon的目标

和复杂的 if else 说再见

为什么

具体见使用atcon告别混乱的if else

使用方式

npm install --save atcon
const atcon = require('atcon');
atcon(conditions, states, predicate);

执行逻辑

  1. 根据states数组项元素,依次查找condtions对象(也可以是数组)的state0属性,得到conditons1对象,再查找conditons1state1属性...... 其实相当于一个reduce
  2. predicate接收reduce传进来的每一项的conditon[state],如果满足条件,predicate函数 return true 就退出查找,得到该值
  3. 如果conditon[state]不存在,则重新回到上层查找,层层回溯,并获取该层对象的__DEFAULT__属性,传递给predicate,同样的,如果return true,退出查找,得到该值。其实相当于 switch内的default

具体例子

const imgMap = {
    online: {
        '2': {
            a: 'img_b',
            b: 'img_o'
        },
        '3': {
            a: 'img_b',
            b: 'img_p'
        },
        '4': 'img_c',
        '5': 'img_d',
        '6': 'img_e'
    },
    offline: {
        '2': 'img_h',
        '3': 'img_i',
        '4': 'img_j',
        '5': 'img_k',
        '6': 'img_l'
    },
    __DEFAULT__: 'img_a'
};

const noticeMap = {
    b: {
        '3': 'text3',
        '5': 'text5'
    },
    a: 'textaaa',
    __DEFAULT__: 'textdefault'
};

const isString = obj => Object.prototype.toString.call(obj) === '[object String]';

atcon(imgMap, ['online', 3, 'a'], isString); // 'img_b'
atcon(imgMap, ['online', 3, 'c'], isString); // 'img_a'
atcon(imgMap, ['offline', 3, 'v'], isString); // 'img_i'
atcon(imgMap, ['noline'], isString); // 'img_a'

atcon(noticeMap, ['b', 1], isString); // 'textdefault'
atcon(noticeMap, ['a', 6, 1, 5, 6], isString); // 'textaaa'

注意

atcon(noticeMap, ['b'], isString); // undefined

返回的是 undefined,因为走进了 switch case b的逻辑,但是switch case b是一个对象,没有满足isString的条件,而这里没有指定下一层状态的话,循环就会在这一层戛然而止,而不再做回溯。

更多例子可直接参考mocha test

最后

希望大家用得开心。