Skip to content

Commit f53c66f

Browse files
committed
Chore: remove unnecessary wrapper
1 parent 3b7c681 commit f53c66f

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

.eslintrc.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"browser": false
1616
},
1717
"globals": {
18+
"atob": false,
19+
"btoa": false,
1820
"console": false,
1921
"document": false,
2022
"location": false,

src/app-state.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,6 @@ import defaultCode from "./app-state/default-code.js"
33
import defaultConfig from "./app-state/default-config.js"
44
import { linter, ruleCategories } from "./app-state/eslint.js"
55

6-
/**
7-
* Convert an Unicode string to base64.
8-
* @param {string} text The string to convert.
9-
* @returns {string} Base64 string.
10-
* @see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa#Unicode_strings
11-
*/
12-
function encodeToBase64(text) {
13-
return window.btoa(unescape(encodeURIComponent(text)))
14-
}
15-
16-
/**
17-
* Convert a base64 string to Unicode.
18-
* @param {string} base64 The string to convert.
19-
* @returns {string} Unicode string.
20-
* @see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa#Unicode_strings
21-
*/
22-
function decodeFromBase64(base64) {
23-
return decodeURIComponent(escape(window.atob(base64)))
24-
}
25-
266
/**
277
* The state object for this application.
288
*/
@@ -101,7 +81,7 @@ export default class PlaygroundState {
10181
})
10282
const compressedString = pako.deflate(jsonString, { to: "string" })
10383

104-
return encodeToBase64(compressedString)
84+
return btoa(compressedString)
10585
}
10686

10787
/**
@@ -116,7 +96,7 @@ export default class PlaygroundState {
11696
try {
11797
// For backward compatibility, it can address non-compressed data.
11898
const compressed = !serializedString.startsWith("eyJj")
119-
const decodedText = decodeFromBase64(serializedString)
99+
const decodedText = atob(serializedString)
120100
const jsonText = compressed ? pako.inflate(decodedText, { to: "string" }) : decodedText
121101
const json = JSON.parse(jsonText)
122102
let changed = false

0 commit comments

Comments
 (0)