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

use-bit-flag

v2.0.1

Published

通过位运算管理状态,开发审核系统时灵光乍现,想到了linux文件系统,从而诞生。

Readme

use-bit-flag

通过位运算来管理状态,提供了更好的语义化开发体验,可随意加减flag,在与原flag不冲突的情况下不影响原有逻辑。

需注意数据库的字段类型,由于采用位运算,数字上限会指数级增长:2^n,n=状态数量-1。

支持链式调用,参数自由度较高,建议ts项目使用,可以获得很好的开发体验,代码提示完善。

目前仅支持主流浏览器,不侵入框架,react/vue/angular均可使用。

安装

pnpm install use-bit-flag
npm install use-bit-flag
yarn add use-bit-flag

用法1(推荐)

import useBitFlag from 'use-bit-flag'

const obj = {
    id: 1,
    name: 'audit flow of lijiahui',
    form: {},
    files: [],
    status: 0,
}
const STATUS_FLAGS = {
    // NOT_START: 0, // 如果需要0状态的话,0不要进行位运算
    COMPLETED_FORM: 1 << 0, // 从0开始
    UPLOADED_FILE: 1 << 1,
    FIRST_AUDIT_FINISHED: 1 << 2, // 初审是否完成,发起了审核流程,就认为发起了初审
    SECOND_AUDIT_STARTED: 1 << 3, // 复审是否开启(需要用户手动开启)
    SECOND_AUDIT_FINISHED: 1 << 3, // 复审办结
    ID_RECOGNIZE_FINISHED: 1 << 4, // 身份认证是否完成,贯穿整个审核流程
} as const
const bitFlag = useBitFlag(STATUS_FLAGS, obj, 'status')
// 传参可选择逗号分割字符串、字符串数组、字符串与字符串数组混用、多个字符串数组,非常自由,看您喜好
bitFlag.add('COMPLETED_FORM') // 完成表单填写
bitFlag.remove(['COMPLETED_FORM']).add('UPLOADED_FILE') // 发现表单填错,重新填,上传文件
if(bitFlag.notAll('COMPLETED_FORM', ['UPLOADED_FILE'])) { // 没有完成表单填写,没有上传文件,不允许结束初审
    return false
}
const auditFinishedFlags = ['FIRST_AUDIT_FINISHED', 'SECOND_AUDIT_FINISHED', 'ID_RECOGNIZE_FINISHED']
if (bitFlag.isAll(auditFinishedFlags)){ // 完成了初审、复审、身份认证,视为完成整个审核流程
    return true
}

用法2:js项目

通过一个额外的常量来实现ts的提示及降低开发的心智负担,其他与用法1一致

const STATUS_FLAGS_KEYS = {
    // NOT_START: 'NOT_START',
    COMPLETED_FORM: 'COMPLETED_FORM',
    UPLOADED_FILE: 'UPLOADED_FILE',
    FIRST_AUDIT_FINISHED: 'FIRST_AUDIT_FINISHED',
    SECOND_AUDIT_STARTED: 'SECOND_AUDIT_STARTED',
    SECOND_AUDIT_FINISHED: 'SECOND_AUDIT_FINISHED',
    ID_RECOGNIZE_FINISHED: 'ID_RECOGNIZE_FINISHED',
}
bitFlag.add(STATUS_FLAGS_KEYS.COMPLETED_FORM) // 完成表单填写