Files
passport/lib/utils/base64.ts
Дмитрий be1e21e699
Some checks failed
Publish / Publish Job (push) Failing after 37s
first commit
2026-03-27 10:38:23 +03:00

18 lines
401 B
TypeScript

export function base64UrlEncode(buf: Buffer | string) {
const s = typeof buf === 'string' ? Buffer.from(buf) : buf
return s
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '')
}
export function base64UrlDecode(str: string) {
str = str.replace(/-/g, '+').replace(/_/g, '/')
while (str.length % 4) str += '='
return Buffer.from(str, 'base64').toString()
}