From 3094434326d30afd67a4f4368a46efd9f8a83a73 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sun, 26 May 2019 11:56:41 +0900 Subject: [PATCH] Simplified urlBase64ToUint8Array --- scripts/PushManager.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/PushManager.ts b/scripts/PushManager.ts index 4d7046ee..56c9bc21 100644 --- a/scripts/PushManager.ts +++ b/scripts/PushManager.ts @@ -100,18 +100,12 @@ export default class PushManager { } } -function urlBase64ToUint8Array(base64String) { +function urlBase64ToUint8Array(base64String: string) { const padding = "=".repeat((4 - base64String.length % 4) % 4) const base64 = (base64String + padding) .replace(/\-/g, "+") .replace(/_/g, "/") const rawData = window.atob(base64) - const outputArray = new Uint8Array(rawData.length) - - for(let i = 0; i < rawData.length; ++i) { - outputArray[i] = rawData.charCodeAt(i) - } - - return outputArray + return Uint8Array.from([...rawData].map(char => char.charCodeAt(0))) } \ No newline at end of file