@apify/utilities
Advanced tools
Comparing version 2.6.0 to 2.7.0
22
index.js
@@ -1852,10 +1852,28 @@ "use strict"; | ||
// src/url_params_utils.ts | ||
function base64urlToBase64(input) { | ||
input = input.replace(/-/g, "+").replace(/_/g, "/"); | ||
const pad = input.length % 4; | ||
if (pad) { | ||
if (pad === 1) { | ||
throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding"); | ||
} | ||
input += new Array(5 - pad).join("="); | ||
} | ||
return input; | ||
} | ||
__name(base64urlToBase64, "base64urlToBase64"); | ||
function base64ToBase64Url(input) { | ||
return input.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/m, ""); | ||
} | ||
__name(base64ToBase64Url, "base64ToBase64Url"); | ||
function encodeInput(input) { | ||
const data = JSON.stringify(input); | ||
const buffer = Buffer.from(data, "utf8"); | ||
return buffer.toString("base64url"); | ||
const base64 = buffer.toString("base64"); | ||
return base64ToBase64Url(base64); | ||
} | ||
__name(encodeInput, "encodeInput"); | ||
function decodeInput(urlHash) { | ||
const buffer = Buffer.from(urlHash, "base64url"); | ||
const base64 = base64urlToBase64(urlHash); | ||
const buffer = Buffer.from(base64, "base64"); | ||
const decoded = buffer.toString("utf8"); | ||
@@ -1862,0 +1880,0 @@ return JSON.parse(decoded); |
{ | ||
"name": "@apify/utilities", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "Tools and constants shared across Apify projects.", | ||
@@ -52,3 +52,3 @@ "main": "./index.js", | ||
}, | ||
"gitHead": "509d178d6751d3af2aa1c6af7272c357ee522839" | ||
"gitHead": "7fe1e13d2ac58d19c3e886965564040b8167dc97" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
321956
4338