MCPcopy Index your code
hub / github.com/Effect-TS/effect / decode

Function decode

packages/effect/src/internal/encoding/base64Url.ts:11–29  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

9
10/** @internal */
11export const decode = (str: string): Either.Either<Uint8Array, Encoding.DecodeException> => {
12 const stripped = Base64.stripCrlf(str)
13 const length = stripped.length
14 if (length % 4 === 1) {
15 return Either.left(
16 DecodeException(stripped, `Length should be a multiple of 4, but is ${length}`)
17 )
18 }
19
20 if (!/^[-_A-Z0-9]*?={0,2}$/i.test(stripped)) {
21 return Either.left(DecodeException(stripped, "Invalid input"))
22 }
23
24 // Some variants allow or require omitting the padding '=' signs
25 let sanitized = length % 4 === 2 ? `${stripped}==` : length % 4 === 3 ? `${stripped}=` : stripped
26 sanitized = sanitized.replace(/-/g, "+").replace(/_/g, "/")
27
28 return Base64.decode(sanitized)
29}

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.80
DecodeExceptionFunction · 0.70

Tested by

no test coverage detected