@aardpro/time-id
v1.0.0
Published
一个根据时间戳产生唯一id的方法,并且能够自定义后缀,用来取代uuid和数字自增id。A method that generates a unique id based on the current timestamp in milliseconds, and can also be used to generate a unique id with a suffix, which can be used to replace uuid and numeric auto-increment id
Maintainers
Readme
@aardpro/time-id
一个根据时间戳产生唯一ID的方法,并且能够自定义后缀,用来取代uuid和数字自增id。
A method that generates a unique ID based on the current timestamp in milliseconds, with support for custom suffixes. Can be used to replace UUID and numeric auto-increment IDs.
在线演示 | Playground
中文文档 | English
Features
- Compact: Only 7-10 characters typically, compared to UUID v4's 36 characters
- Roughly Sortable: Based on timestamp, similar generation times produce similar IDs
- High Performance: Uses base26 encoding (a-z), more compact than hexadecimal
- Flexible: Supports custom suffix length and accumulator for distributed scenarios
Installation
# pnpm
pnpm i @aardpro/time-id
# npm
npm i @aardpro/time-id
# yarn
yarn add @aardpro/time-id
# bun
bun i @aardpro/time-idQuick Start
import { timeId } from '@aardpro/time-id';
const id = timeId();
// Example output: 'lgskjwabc'
// Format: {timestamp_base26}{3_char_suffix}Publishing to npm
For maintainers who want to publish this package:
# 1. Install dependencies
npm install
# 2. Run tests
npm test
# 3. Build the package
npm run build
# 4. Check the dist directory
ls dist
# 5. Login to npm (if not already logged in)
npm login
# 6. Publish to npm (for scoped packages, use --access public)
npm publish --access public
# 7. Or publish a beta version
npm publish --tag betaNote: This package uses the scoped name @aardpro/time-id, which requires --access public flag during publish.
