New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

bit-marker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bit-marker

二进制位标记处理,无位数限制

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

功能

使用二进制位来标记 bool 状态,位数可无限扩展,因为标记位的可扩展性,你需要通过一个数组而不是整数来初始化 BitMarker。 数组中的每个元素可以表示 32 个 bool 状态,当标记数超过 32 时,会自动扩展。

用法

安装

npm install bit-marker

示例

import BitMarker from 'bit-marker';

// 有新功能上线时,出现功能引导,每个功能仅出现一次,使用 BitMarker 对出现过的引导状态进行标记

enum FunctionGuide {
    A = 0, // 功能 A
    B = 1, // 功能 B
    C = 2,
    D = 3,
}

// 1. 初始化
const initStatus = []; // 初始标记,从数据库读出或者初始化
const bitMarker = new BitMarker(initStatus);

// 2. 设置标记
// 功能 A 已引导
bitMarker.set(FunctionGuide.A, true);

// 3. 获取标记
const isGuideA = bitMarker.get(FunctionGuide.A);
console.log(isGuideA); // true
const isGuideB = bitMarker.get(FunctionGuide.B);
console.log(isGuideB); // false

API

constructor(initStatus: number[])

初始化,initStatus 为初始标记,从数据库读出或者初始化

set(bit: number, value: boolean)

设置标记,bit 为标记位,value 为标记值,true 为已标记,false 为未标记。

get(bit: number)

获取标记,bit 为标记位

setValues(values: number[])

接收一个整数数组,每个元素有效值为 [0, 2 ^ 32 - 1],每个数字表示 32 个标记位,当标记数超过 32 时,会自动扩展。

getValues()

获取所有标记组成的数组。

clear()

清空所有标记

欢迎反馈

  • 提交 issue
  • 提 PR

作者

牛书书 Github

Keywords

BitMarker

FAQs

Package last updated on 16 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts