fakejson match subscription id.
This commit is contained in:
parent
4485c8ed5e
commit
b5c8255b2f
|
@ -33,3 +33,17 @@ test('match kind', () => {
|
|||
)
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
test('match subscription id', () => {
|
||||
expect(fj.getSubscriptionId('["EVENT","",{}]')).toEqual('')
|
||||
expect(fj.getSubscriptionId('["EVENT","_",{}]')).toEqual('_')
|
||||
expect(fj.getSubscriptionId('["EVENT","subname",{}]')).toEqual('subname')
|
||||
expect(fj.getSubscriptionId('["EVENT", "kasjbdjkav", {}]')).toEqual(
|
||||
'kasjbdjkav'
|
||||
)
|
||||
expect(
|
||||
fj.getSubscriptionId(
|
||||
' [ \n\n "EVENT" , \n\n "y4d5ow45gfwoiudfÇA VSADLKAN KLDASB[12312535]SFMZSNJKLH" , {}]'
|
||||
)
|
||||
).toEqual('y4d5ow45gfwoiudfÇA VSADLKAN KLDASB[12312535]SFMZSNJKLH')
|
||||
})
|
||||
|
|
15
fakejson.ts
15
fakejson.ts
|
@ -13,6 +13,21 @@ export function getInt(json: string, field: string): number {
|
|||
return parseInt(sliced.slice(0, end), 10)
|
||||
}
|
||||
|
||||
export function getSubscriptionId(json: string): string | null {
|
||||
let idx = json.slice(0, 22).indexOf(`"EVENT"`)
|
||||
if (idx === -1) return null
|
||||
|
||||
let pstart = json.slice(idx + 7 + 1).indexOf(`"`)
|
||||
if (pstart === -1) return null
|
||||
let start = idx + 7 + 1 + pstart
|
||||
|
||||
let pend = json.slice(start + 1, 80).indexOf(`"`)
|
||||
if (pend === -1) return null
|
||||
let end = start + 1 + pend
|
||||
|
||||
return json.slice(start + 1, end)
|
||||
}
|
||||
|
||||
export function matchEventId(json: string, id: string): boolean {
|
||||
return id === getHex64(json, 'id')
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue