0.0.6 • Published 2 years ago

colorid.js v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

ColorID

license npm downloads

Color as Identify - The unique 4-colors-ID string generator in JavaScript

The performance of ColorID is better than UUID and NanoID (The algorithm of ColorID is actually very similar to the UUID.V4)

If we use ColorID to represent identities in social networks, we can easily generate personalized social information for users, such as avatars, NFTs, etc.

The ColorID is consisted by 4 colors in the RGB channel from 12 unsigned 8 bits numbers (u8), so the theoretical total of ColorID is (2^8)^12 = 2^967*10^28, which means that even if the ColorID is generated for every 7.8 billion people in the world every second, it will take 300 billion years to use up all ColorIDs. And ColorID provides safety by using hardware random generator, can also be used in clusters.

Because the Four color theorem, if we need to color the regions of any avatars or NFTs so that no two adjacent regions have the same color, four colors are enough!

一款基于 4 种颜色来表示身份的 JavaScript 随机 ID 生成器。

在性能表现上 ColorIDUUIDNanoID 等库表现更好 (虽然 ColorID 的生成算法实际上和 UUID.V4 非常相似)。

如果我们用 ColorID 表示社交网络中的身份,可以轻松地为用户生成个性化的社交信息:如头像、数字藏品等。

实际上 ColorID 是由 4 种颜色在 RGB 通道内的 12 个 8 位无符号整型数字 (u8) 组成,故 ColorID 理论上的总数为 (2^8)^12 = 2^967*10^28,也就是说即使每秒都为全球 78 亿人中的每个人都生成一个 ColorID,也要花 3000 亿年才会将所有 ColorID 用完。此外 ColorID 使用强随机函数来生成随机数,故也可在集群使用中提供安全性。

因为四色定理的原因,如果我们想要为头像或者数字藏品涂色且不会出现邻接区域颜色相同, 有四种颜色就足够了!

Install

$ npm i colorid.js

Usage

import colorid from "colorid.js";

colorid(); // #5B34F9-#34F9DF-#F9DF4E-#DF4EB5

#5B34F9-#34F9DF-#F9DF4E-#DF4EB5

Performance

crypto.randomUUID    8,829,532 ops/sec
colorid              3,252,649 ops/sec
nanoid               2,925,204 ops/sec
uuid v4                910,855 ops/sec

Benchmark configuration: Ubuntu, Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz, Node.js 18.9.0

(runs: 3045998209)

License

MIT

ColorID in Other Languages

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0-dev.10

2 years ago

0.0.0-dev.9

2 years ago

0.0.0-dev.8

2 years ago

0.0.0-dev.7

2 years ago

0.0.0-dev.6

2 years ago

0.0.0-dev.5

2 years ago

0.0.0-dev.4

2 years ago

0.0.0-dev.3

2 years ago

0.0.0-dev.2

2 years ago

0.0.0-dev.1

2 years ago

0.0.0-dev.0

2 years ago