Uber 快速的独特 ID 生成,适用于 Node.js 和浏览器
Uber 快速的唯一 ID 生成,适用于 Node.js 和浏览器。 以下是基准:
…注: 使用 Apple M4 Max 和 Node.js v24.13.0 进行基准测试
npm i hyperid --save'use strict'
const hyperid = require('hyperid')
const instance = hyperid()
const id = instance()
console.log(id)
console.log(instance())
console.log(hyperid.decode(id))
console.log(hyperid.decode(instance()))返回一个生成唯一 ID 的函数。该函数可以接受以下参数之一: - fixedLength: Boolean 如果 fixedLength 为 true,该函数将始终生成长度为 33 个字符的 ID,默认为 false。 - options: Object 如果传入 { fixedLength: true },该函数将始终生成长度为 33 个字符的 ID,默认为 fixedLength 为 false。 如果传入 { urlSafe: true },该函数将根据 RFC4648 生成 URL 安全 ID。 如果传入 { startFrom: },第一个计数器将从该数字开始,该数字必须介于 0 和 2147483647 之间。小数部分将被丢弃,只需要整数部分。 如果传入 { maxInt: },一旦达到 maxInt,UUID 将重新生成。 maxInt 越小,性能越高,因为 SMI(V8 优化)。
返回唯一的 ID。
暂无开放 Issues,或尚未同步最近议题。