All files / src/utils web-push-helpers.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 1315x             15x 3x 3x 3x    
import { decodeBase64 } from './nacl-util-wrapper';
 
/**
 * Converts a URL-safe base64 string to a Uint8Array.
 * @param base64String - The base64 string to convert.
 * @returns Uint8Array representation of the decoded string.
 */
export function urlBase64ToUint8Array(base64String: string): Uint8Array {
    const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
    const base64 = (base64String + padding).replace(/-/g, '+').replace(/_/g, '/');
    return decodeBase64(base64);
}