mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-27 04:17:51 -07:00
d2b5b67b44
将来ESMに移行しやすいように Related: #7658 なんかmochaが起動しなくなってるけど理由不明 すぐ直したい
21 lines
669 B
TypeScript
21 lines
669 B
TypeScript
import { ulid } from 'ulid';
|
|
import { genAid } from './id/aid.js';
|
|
import { genMeid } from './id/meid.js';
|
|
import { genMeidg } from './id/meidg.js';
|
|
import { genObjectId } from './id/object-id.js';
|
|
import config from '@/config/index.js';
|
|
|
|
const metohd = config.id.toLowerCase();
|
|
|
|
export function genId(date?: Date): string {
|
|
if (!date || (date > new Date())) date = new Date();
|
|
|
|
switch (metohd) {
|
|
case 'aid': return genAid(date);
|
|
case 'meid': return genMeid(date);
|
|
case 'meidg': return genMeidg(date);
|
|
case 'ulid': return ulid(date.getTime());
|
|
case 'objectid': return genObjectId(date);
|
|
default: throw new Error('unrecognized id generation method');
|
|
}
|
|
}
|