mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add "strictNullChecks"
This commit is contained in:
@@ -11,18 +11,23 @@ export type JidWithDevice = {
|
||||
device?: number
|
||||
}
|
||||
|
||||
export type FullJid = JidWithDevice & {
|
||||
server: JidServer | string
|
||||
agent?: number
|
||||
}
|
||||
|
||||
export const jidEncode = (user: string | number | null, server: JidServer, device?: number, agent?: number) => {
|
||||
return `${user || ''}${!!agent ? `_${agent}` : ''}${!!device ? `:${device}` : ''}@${server}`
|
||||
}
|
||||
|
||||
export const jidDecode = (jid: string) => {
|
||||
export const jidDecode = (jid: string | undefined): FullJid | undefined => {
|
||||
const sepIdx = typeof jid === 'string' ? jid.indexOf('@') : -1
|
||||
if(sepIdx < 0) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const server = jid.slice(sepIdx + 1)
|
||||
const userCombined = jid.slice(0, sepIdx)
|
||||
const server = jid!.slice(sepIdx + 1)
|
||||
const userCombined = jid!.slice(0, sepIdx)
|
||||
|
||||
const [userAgent, device] = userCombined.split(':')
|
||||
const [user, agent] = userAgent.split('_')
|
||||
@@ -36,7 +41,7 @@ export const jidDecode = (jid: string) => {
|
||||
}
|
||||
|
||||
/** is the jid a user */
|
||||
export const areJidsSameUser = (jid1: string, jid2: string) => (
|
||||
export const areJidsSameUser = (jid1: string | undefined, jid2: string | undefined) => (
|
||||
jidDecode(jid1)?.user === jidDecode(jid2)?.user
|
||||
)
|
||||
/** is the jid a user */
|
||||
@@ -49,6 +54,6 @@ export const isJidGroup = (jid: string) => (jid?.endsWith('@g.us'))
|
||||
export const isJidStatusBroadcast = (jid: string) => jid === 'status@broadcast'
|
||||
|
||||
export const jidNormalizedUser = (jid: string) => {
|
||||
const { user, server } = jidDecode(jid)
|
||||
const { user, server } = jidDecode(jid)!
|
||||
return jidEncode(user, server === 'c.us' ? 's.whatsapp.net' : server as JidServer)
|
||||
}
|
||||
Reference in New Issue
Block a user