mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-25 01:29:46 +00:00
feat(shell): uix: extend EventEmitter
This commit is contained in:
parent
d645e264ff
commit
183bf7f911
@ -1,3 +1,5 @@
|
|||||||
|
import { EventEmitter } from 'node:events'
|
||||||
|
|
||||||
const uinRegex = /\d+/
|
const uinRegex = /\d+/
|
||||||
|
|
||||||
const isUin = (uin: unknown) =>
|
const isUin = (uin: unknown) =>
|
||||||
@ -7,33 +9,33 @@ const isUin = (uin: unknown) =>
|
|||||||
const isUid = (uid: unknown) =>
|
const isUid = (uid: unknown) =>
|
||||||
typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_')
|
typeof uid === 'string' && uid.length === 24 && uid.startsWith('u_')
|
||||||
|
|
||||||
const map: Record<string, string> = {}
|
export class Uix extends EventEmitter {
|
||||||
|
map: Record<string, string> = {}
|
||||||
|
|
||||||
const add = (uid: string, uin: string) => {
|
isUin = isUin
|
||||||
if (!uid || !uin) return
|
isUid = isUid
|
||||||
map[uid] = uin
|
|
||||||
map[uin] = uid
|
add = (uid: string, uin: string) => {
|
||||||
|
if (!isUid(uid) || !isUin(uin)) return
|
||||||
|
this.map[uid] = uin
|
||||||
|
this.map[uin] = uid
|
||||||
|
this.emit(uin, uid)
|
||||||
|
this.emit(uid, uin)
|
||||||
|
}
|
||||||
|
|
||||||
|
getUin = (uid: string) => {
|
||||||
|
if (!isUid(uid)) return undefined
|
||||||
|
const uin = this.map[uid]
|
||||||
|
if (!isUin(uin)) return undefined
|
||||||
|
return uin
|
||||||
|
}
|
||||||
|
|
||||||
|
getUid = (uin: string) => {
|
||||||
|
if (!isUin(uin)) return undefined
|
||||||
|
const uid = this.map[uin]
|
||||||
|
if (!isUid(uid)) return undefined
|
||||||
|
return uid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUin = (uid: string) => {
|
export const uix = new Uix()
|
||||||
if (!isUid(uid)) return undefined
|
|
||||||
const uin = map[uid]
|
|
||||||
if (!isUin(uin)) return undefined
|
|
||||||
return uin
|
|
||||||
}
|
|
||||||
|
|
||||||
const getUid = (uin: string) => {
|
|
||||||
if (!isUin(uin)) return undefined
|
|
||||||
const uid = map[uin]
|
|
||||||
if (!isUid(uid)) return undefined
|
|
||||||
return uid
|
|
||||||
}
|
|
||||||
|
|
||||||
export const uix = {
|
|
||||||
map,
|
|
||||||
add,
|
|
||||||
isUin,
|
|
||||||
isUid,
|
|
||||||
getUin,
|
|
||||||
getUid,
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user