@agrozyme/flake

這是用 TypeScript 實作的一個全局全時的發號器,可以產生一個長度為 39 Bytes 的字串。

Usage no npm install needed!

<script type="module">
  import agrozymeFlake from 'https://cdn.skypack.dev/@agrozyme/flake';
</script>

README

@agrozyme/flake

這是用 TypeScript 實作的一個全局全時的發號器,可以產生一個長度為 39 Bytes 的字串。

該字串為 16 進位字串,其中包括 3 個連字號 (Dash: - )。

我參考了 flake 這個模組來改寫。

主要的差異在於:

  • 自動取得可能的 MAC Address
  • 參考各項目的最大可能值來調整各欄位的長度

字串格式

  • Format: [timestamp]-[count]-[pid]-[mac]
  • Bytes: 14 - 4 - 6 - 12
  • Total: 14 + 4 + 6 + 12 + 3 = 39

用法

JavaScript

const Flake = require('@agrozyme/flake');
const identity = Flake.makeOne();
const list = Flake.makeList(10);

TypeScript

import { Flake } from '@agrozyme/flake';
const identity = Flake.makeOne();
const list = Flake.makeList(10);