File tree Expand file tree Collapse file tree 5 files changed +109
-0
lines changed Expand file tree Collapse file tree 5 files changed +109
-0
lines changed Original file line number Diff line number Diff line change
1
+ # migrate legacy ` buffer.atob() ` and ` buffer.btoa() ` APIs
2
+
3
+ Migrates usage of the legacy APIs ` buffer.atob() ` and ` buffer.btoa() ` to the current recommended approaches.
4
+
5
+ ## Example
6
+
7
+ ### Migrating buffer.atob(data)
8
+
9
+ ** Before:**
10
+ ```
11
+ const buffer = require('node:buffer');
12
+ const data = 'SGVsbG8gV29ybGQh'; // "Hello World!" in base64
13
+ const decodedData = buffer.atob(data);
14
+ console.log(decodedData); // Outputs: Hello World!
15
+ ```
16
+
17
+ ** After:**
18
+ ```
19
+ const data = 'SGVsbG8gV29ybGQh'; // "Hello World!" in base64
20
+ const decodedData = Buffer.from(data, 'base64').toString('binary');
21
+ console.log(decodedData); // Outputs: Hello World!
22
+ ```
23
+
24
+ ### Migrating buffer.btoa(data)
25
+
26
+ ** Before:**
27
+ ```
28
+ const buffer = require('node:buffer');
29
+ const data = 'Hello World!';
30
+ const encodedData = buffer.btoa(data);
31
+ console.log(encodedData); // Outputs: SGVsbG8gV29ybGQh
32
+ ```
33
+
34
+ ** After:**
35
+ ```
36
+ const data = 'Hello World!';
37
+ const encodedData = Buffer.from(data, 'binary').toString('base64');
38
+ console.log(encodedData); // Outputs: SGVsbG8gV29ybGQh
39
+ ```
Original file line number Diff line number Diff line change
1
+ schema_version : " 1.0"
2
+ name : " @nodejs/buffer-atob-btoa"
3
+ version : " 1.0.0"
4
+ description : Migrates usage of the legacy APIs `buffer.atob()` and `buffer.btoa()` to the current recommended approaches
5
+ author : nekojanai (Jana)
6
+ license : MIT
7
+ workflow : workflow.yaml
8
+ category : migration
9
+
10
+ targets :
11
+ languages :
12
+ - javascript
13
+ - typescript
14
+
15
+ keywords :
16
+ - transformation
17
+ - migration
18
+
19
+ registry :
20
+ access : public
21
+ visibility : public
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " @nodejs/buffer-atob-btoa" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " Migrates usage of the legacy APIs `buffer.atob()` and `buffer.btoa()` to the current recommended approaches" ,
5
+ "type" : " module" ,
6
+ "scripts" : {
7
+ "test" : " npx codemod jssg test -l typescript ./src/workflow.ts ./"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/nodejs/userland-migrations.git" ,
12
+ "directory" : " recipes/buffer-atob-btoa" ,
13
+ "bugs" : " https://github.com/nodejs/userland-migrations/issues"
14
+ },
15
+ "author" : " nekojanai (Jana)" ,
16
+ "license" : " MIT" ,
17
+ "homepage" : " https://github.com/nodejs/userland-migrations/blob/main/recipes/buffer-atob-btoa/README.md" ,
18
+ "dependencies" : {
19
+ "@nodejs/codemod-utils" : " *"
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ // TODO: implement
Original file line number Diff line number Diff line change
1
+ # yaml-language-server: $schema=https://raw.githubusercontent.com/codemod-com/codemod/refs/heads/main/schemas/workflow.json
2
+
3
+ version : " 1"
4
+
5
+ nodes :
6
+ - id : apply-transforms
7
+ name : Apply AST Transformations
8
+ type : automatic
9
+ runtime :
10
+ type : direct
11
+ steps :
12
+ - name : Migrates usage of the legacy APIs `buffer.atob()` and `buffer.btoa()` to the current recommended approaches
13
+ js-ast-grep :
14
+ js_file : src/workflow.ts
15
+ base_path : .
16
+ include :
17
+ - " **/*.cjs"
18
+ - " **/*.js"
19
+ - " **/*.jsx"
20
+ - " **/*.mjs"
21
+ - " **/*.cts"
22
+ - " **/*.mts"
23
+ - " **/*.ts"
24
+ - " **/*.tsx"
25
+ exclude :
26
+ - " **/node_modules/**"
27
+ language : typescript
You can’t perform that action at this time.
0 commit comments