Skip to content

Commit f09535c

Browse files
authored
Merge pull request #33 from arnav-kr/raw-unicode-escapes
fix+feat: unicode escape sequences in formatted output, setting config
2 parents 7dc895c + ec893e4 commit f09535c

File tree

9 files changed

+62
-18
lines changed

9 files changed

+62
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# CHANGELOG V2.1.8
2-
* 🐞 Fix [[#29](https://github.com/arnav-kr/json-formatter/issues/29)]
1+
# CHANGELOG V2.1.9
2+
* 🐞 Fix [[#32](https://github.com/arnav-kr/json-formatter/issues/32)]
3+
* New option to Enable/Disable Raw Unicode Escapes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![GitHub](https://img.shields.io/github/license/arnav-kr/json-formatter?style=flat-square&logo=github&logoColor=white&label=GitHub&labelColor=%233d3d3d&color=%234285F4)](https://github.com/arnav-kr/json-formatter)
1313

1414

15-
**[V2.1.8.0 CHANGELOG](CHANGELOG.md)**
15+
**[V2.1.9.0 CHANGELOG](CHANGELOG.md)**
1616

1717
## Features:
1818
* 60+ Themes for both Light and Dark Mode

extension/css/UI.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:root {
2-
min-width: 400px;
2+
min-width: 428px;
33
min-height: 400px;
44
}
55

extension/css/content.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ body.JF_dark .JF_context_menu {
376376

377377
.JF_context_menu .JF_context_menu_item {
378378
display: flex;
379+
align-items: center;
379380
gap: 8px;
380381
padding: 8px 24px;
381382
cursor: pointer;

extension/js/content.js

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ SOFTWARE.
4040
isToolbarOpen = false,
4141
options = Object.assign({}, globalThis.sharedData.defaultOptions),
4242
bucket = "JSON_FORMATTER_OPTIONS",
43-
wordWrap = false;
44-
45-
let IS_PREPARE_SCRIPT_RUN = false;
43+
wordWrap = false,
44+
IS_PREPARE_SCRIPT_RUN = false;
4645

4746
if (document.readyState === "complete" && !IS_PREPARE_SCRIPT_RUN) {
4847
_();
@@ -72,7 +71,7 @@ SOFTWARE.
7271
}
7372
else {
7473
// legacy support
75-
if (!data[bucket].hasOwnProperty("themes") || !data[bucket].hasOwnProperty("colorScheme") || !data[bucket].hasOwnProperty("wordWrap") || !data[bucket].hasOwnProperty("sortingOrder")) {
74+
if (!data[bucket].hasOwnProperty("themes") || !data[bucket].hasOwnProperty("colorScheme") || !data[bucket].hasOwnProperty("wordWrap") || !data[bucket].hasOwnProperty("sortingOrder") || !data[bucket].hasOwnProperty("rawUnicodeEscapes")) {
7675
// still has old data format, update it to new format
7776
let newDataFormat = Object.assign({}, globalThis.sharedData.defaultOptions);
7877
if (data[bucket].themeMode == "auto") {
@@ -86,7 +85,14 @@ SOFTWARE.
8685
newDataFormat.colorScheme = "light";
8786
}
8887
}
89-
newDataFormat.tab = data[bucket].defaultTab;
88+
if (data[bucket].defaultTab) {
89+
newDataFormat.tab = data[bucket].defaultTab;
90+
}
91+
delete data[bucket].themeMode;
92+
delete data[bucket].currentTheme;
93+
delete data[bucket].defaultTab;
94+
95+
newDataFormat = { ...newDataFormat, ...data[bucket] };
9096

9197
Object.assign(options, newDataFormat);
9298
await chrome.storage.local.set({ [bucket]: newDataFormat });
@@ -167,7 +173,10 @@ SOFTWARE.
167173
sortingFuncton = normalize();
168174
}
169175
formattedRawCode.innerHTML =
170-
JSON.stringify(JSON.parse(code.replace(/\\u/g, "\u")), sortingFuncton, 2);
176+
JSON.stringify(JSON.parse(
177+
options.rawUnicodeEscapes === true ?
178+
code.replace(/\\u/g, "\u") : code
179+
), sortingFuncton, 2);
171180

172181
globalThis.code = code;
173182

@@ -177,18 +186,26 @@ SOFTWARE.
177186
leadingLine.style = 'margin-left: 0px; height: 18px;';
178187
formattedRawCode.appendChild(leadingLine);
179188

180-
rawCode.innerHTML = JSON.stringify(JSON.parse(code.replace(/\\u/g, "\u")), sortingFuncton);
189+
rawCode.innerHTML = JSON.stringify(JSON.parse(
190+
options.rawUnicodeEscapes === true ?
191+
code.replace(/\\u/g, "\u") : code
192+
), sortingFuncton);
181193

182194
let leadingLine1 = document.createElement('div');
183195
leadingLine1.className = 'line emptyLine';
184196
leadingLine1.textContent = '';
185197
leadingLine1.style = 'margin-left: 0px; height: 18px;';
186198
rawCode.appendChild(leadingLine1);
187-
188-
tree = createTree(JSON.parse(code
189-
.replace(/\\/g, "\\\\")
190-
.replace(/\\\\\"/g, "\\\\\\\""),
191-
sortingFuncton));
199+
tree = createTree(
200+
JSON.parse(
201+
code
202+
.replace(/\\/g, "\\\\")
203+
.replace(/\\\\\"/g, "\\\\\\\"")
204+
.replace(/\\\\u/g,
205+
options.rawUnicodeEscapes === true ? "\\\\u" : "\\u"
206+
),
207+
sortingFuncton)
208+
);
192209
var thme = isDark ? "dark" : "light";
193210
var renderedCode = render(tree, parsedCode, { theme: thme, string: true });
194211
expandChildren(tree);

extension/js/globals.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const defaultOptions = {
1010
"tab": "parsed",
1111
"colorScheme": "auto",
1212
"wordWrap": false,
13+
"rawUnicodeEscapes": false,
1314
"sortingOrder": "unchanged",
1415
"hotkeys": {
1516
"parsed": "p",

extension/js/options.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var tabEl,
44
darkThemeEl,
55
wordWrapEl,
66
sortingOrderEl,
7+
rawUnicodeEscapesEl,
78
options = {},
89
bucket = "JSON_FORMATTER_OPTIONS";
910

@@ -15,6 +16,7 @@ window.addEventListener("load", async () => {
1516
darkThemeEl = document.getElementById("dark_theme");
1617
wordWrapEl = document.getElementById("word_wrap");
1718
sortingOrderEl = document.getElementById("sorting_order");
19+
rawUnicodeEscapesEl = document.getElementById("raw_unicode_escapes");
1820

1921
await fetchExtensionSettings();
2022
console.log(options);
@@ -43,6 +45,7 @@ window.addEventListener("load", async () => {
4345
darkThemeEl.value = options.themes.current.dark.id;
4446
wordWrapEl.value = options.wordWrap;
4547
sortingOrderEl.value = options.sortingOrder;
48+
rawUnicodeEscapesEl.value = options.rawUnicodeEscapes;
4649
}
4750
async function fetchExtensionSettings() {
4851
// Get Options
@@ -137,4 +140,10 @@ window.addEventListener("load", async () => {
137140
options.sortingOrder = e.target.value;
138141
await chrome.storage.local.set({ [bucket]: options });
139142
});
143+
144+
rawUnicodeEscapesEl.addEventListener("input", async (e) => {
145+
if (options.rawUnicodeEscapes == e.target.value) return;
146+
options.rawUnicodeEscapes = e.target.value == "true" ? true : false;
147+
await chrome.storage.local.set({ [bucket]: options });
148+
});
140149
});

extension/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "JSON Formatter",
33
"short_name": "JSON Formatter",
4-
"version": "2.1.8",
5-
"version_name": "Version 2.1.8 Beta",
4+
"version": "2.1.9",
5+
"version_name": "Version 2.1.9 Beta",
66
"manifest_version": 3,
77
"description": "Formats JSON automatically! Open Source, Available with 60+ Themes, Syntax Highlighting, automatically linkifies links and more.",
88
"author": "Arnav",

extension/options.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ <h2 id="header" class="title">Settings</h2>
140140
</select>
141141
</div>
142142
</div>
143+
144+
<!-- Raw Unicode Escapes -->
145+
<div class="item" title="Enable/Disable Raw Unicode Escapes">
146+
<div class="item-inner">
147+
<div class="label">
148+
<span>Raw Unicode Escapes</span>
149+
</div>
150+
<select class="md-select" id="raw_unicode_escapes" aria-label="Enable/Disable Raw Unicode Escapes"
151+
title="Enable/Disable Raw Unicode Escapes">
152+
<option value="true">Enabled</option>
153+
<option value="false" selected>Disabled</option>
154+
</select>
155+
</div>
156+
</div>
157+
<div class="hr"></div>
143158
</div>
144159
</div>
145160
</body>

0 commit comments

Comments
 (0)