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

node-snowflake-es

v1.1.3

Published

支持时钟回拨的snowflake.js

Downloads

3

Readme

snowflake 变种

Install

pnpm install node-snowflake-es

Usage

import snowflake from 'node-snowflake-es';
console.log(snowflake());
import { createSnowflake } from 'node-snowflake-es';
const snowflake = createSnowflake({
  workerId: 0, // 机器编号, 默认0, 不能超过 workerBits 规定的取值范围
  randomSequence: 128, // 默认128, 随机序列号开始值, 用于分库分表
  workerBits: 7, // 机器编号占的位数, 默认7
  clockBits: 2, // 时钟编号占用位数, 默认2, 时钟编号会因为时钟回拨自动切换
  sequenceBits: 12, // 序列号占用位数, 默认12,
  twEpoch: 1451606400000, // 时间开始编号, 默认1451606400000, 对应时间为 '2016-01-01T00:00:00.000Z'
});

修改snowflake默认值

 SNOWFLAKE_WORKER_ID=1 SNOWFLAKE_RANDOM_SEQUENCE=8 SNOWFLAKE_WORKER_BITS=7 SNOWFLAKE_CLOCK_BITS=2 SNOWFLAKE_SEQUENCE_BITS=12 SNOWFLAKE_TW_EPOCH=1451606400000 node xxxx.js

命令行随机生成

  • npx node-snowflake-cli 随机生成1个
  • npx node-snowflake-cli 20 随机生成10个

默认BIT位说明

  • bit位说明: (timestamp | worker | clock | sequence)
  • 时间位(timestamp): 41bit 最大支持到 2155-05-15T07:35:11.104Z
  • 机器位(worker): 7bit 0 ~ 127
  • 时钟位(clock): 2bit 0 ~ 3
  • 序列号(sequence): 12bit 0 ~ 4095

支持特性

  • 支持128个不同的workerId
  • 最大id生成速度 4k/ms
  • 支持时钟回拨, 允许连续三次时钟回拨
  • 支持首个id位为随机数 (便于分表分库)

性能测试

pnpm build pnpm performance