@turbowarp/sb3fix 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/sb3fix.js +36 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turbowarp/sb3fix",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Fix corrupted Scratch projects",
5
5
  "main": "src/sb3fix.js",
6
6
  "scripts": {
package/src/sb3fix.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  sb3fix - https://github.com/TurboWarp/sb3fix
3
3
 
4
- Copyright (C) 2023-2024 Thomas Weber
4
+ Copyright (C) 2023-2025 Thomas Weber
5
5
 
6
6
  This Source Code Form is subject to the terms of the Mozilla Public
7
7
  License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -143,7 +143,29 @@ const fixJSON = (data, options = {}) => {
143
143
  if (typeof type !== 'number') {
144
144
  throw new Error('native type is not a number');
145
145
  }
146
+
146
147
  switch (type) {
148
+ // Number primitive: [4, string|number]
149
+ // Positive number primitive: [5, string|number]
150
+ // Whole number primitive: [6, string|number]
151
+ // Integer primitive: [7, string|number]
152
+ // Angle primitive: [8, string|number]
153
+ case 4:
154
+ case 5:
155
+ case 6:
156
+ case 7:
157
+ case 8: {
158
+ if (native.length !== 2) {
159
+ throw new Error(`Number native is of unexpected length: ${native.length}`);
160
+ }
161
+ const value = native[1];
162
+ if (typeof value !== 'string' && typeof value !== 'number') {
163
+ log('number native had invalid value');
164
+ native[1] = String(value);
165
+ }
166
+ break;
167
+ }
168
+
147
169
  // Color: [9, hex color]
148
170
  case 9: {
149
171
  if (native.length !== 2) {
@@ -157,6 +179,19 @@ const fixJSON = (data, options = {}) => {
157
179
  break;
158
180
  }
159
181
 
182
+ // Text: [10, string|number]
183
+ case 10: {
184
+ if (native.length !== 2) {
185
+ throw new Error(`Text native is of unexpected length: ${native.length}`);
186
+ }
187
+ const value = native[1];
188
+ if (typeof value !== 'string' && typeof value !== 'number') {
189
+ log('text native had invalid value');
190
+ native[1] = String(value);
191
+ }
192
+ break;
193
+ }
194
+
160
195
  // Variable: [12, variable name, variable id, x?, y?]
161
196
  // List: [13, list name, list id, x?, y?]
162
197
  // x and y only present if the native is a top-level block