Skip to content

feat: Migrate legacy buffer.atob(data) and buffer.btoa(data) APIs #98

@AugustinMauroy

Description

@AugustinMauroy

Description

This codemod should migrate the legacy buffer.atob(data) and buffer.btoa(data) APIs to the current recommended approaches. Specifically, it should replace buffer.atob(data) with Buffer.from(data, 'base64').toString('binary') and buffer.btoa(data) with Buffer.from(data, 'binary').toString('base64'). This migration is useful for updating codebases to use the current Node.js APIs.

If buffer is only use for these api the importation/requiring must be removed.

Examples

Migrating buffer.atob(data)

Before:

const buffer = require('node:buffer');
const data = 'SGVsbG8gV29ybGQh'; // "Hello World!" in base64
const decodedData = buffer.atob(data);
console.log(decodedData); // Outputs: Hello World!

After:

const data = 'SGVsbG8gV29ybGQh'; // "Hello World!" in base64
const decodedData = Buffer.from(data, 'base64').toString('binary');
console.log(decodedData); // Outputs: Hello World!

Migrating buffer.btoa(data)

Before:

const buffer = require('node:buffer');
const data = 'Hello World!';
const encodedData = buffer.btoa(data);
console.log(encodedData); // Outputs: SGVsbG8gV29ybGQh

After:

const data = 'Hello World!';
const encodedData = Buffer.from(data, 'binary').toString('base64');
console.log(encodedData); // Outputs: SGVsbG8gV29ybGQh

REFS

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    🔖 Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions