spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / telemetry / tests / fixtures / base64-decoded.ts
23 lines · 681 BRaw
1import { BASE64_ALPHABET } from './base64-alphabet.js'
2import { BASE64_DIGIT_BITS } from './base64-digit-bits.js'
3
4/**
5 * The text a base64 string encodes, byte for byte (the rows carry ASCII
6 * JSON), so a test reads a batch's `additional_metadata` back.
7 *
8 * @param encoded the base64 text
9 * @returns the decoded text
10 */
11export const base64Decoded = (encoded: string): string =>
12 (
13 [...encoded.replace(/=+$/, '')]
14 .map(digit =>
15 BASE64_ALPHABET.indexOf(digit)
16 .toString(2)
17 .padStart(BASE64_DIGIT_BITS, '0'),
18 )
19 .join('')
20 .match(/[01]{8}/g) ?? []
21 )
22 .map(byte => String.fromCharCode(parseInt(byte, 2)))
23 .join('')