diff --git a/src/extensions/scratch3_pen/index.js b/src/extensions/scratch3_pen/index.js index 16c09dfb61..b1b8eace4a 100644 --- a/src/extensions/scratch3_pen/index.js +++ b/src/extensions/scratch3_pen/index.js @@ -298,6 +298,16 @@ class Scratch3PenBlocks { }), blockIconURI: blockIconURI, blocks: [ + // tw: additional message when on the stage for clarity + { + blockType: BlockType.LABEL, + text: formatMessage({ + id: 'tw.pen.stageSelected', + default: 'Stage selected: less pen blocks', + description: 'Label that appears in the Pen category when the stage is selected' + }), + filter: [TargetType.STAGE] + }, { opcode: 'clear', blockType: BlockType.COMMAND, diff --git a/src/util/base64-util.js b/src/util/base64-util.js index 1325291707..19165c980b 100644 --- a/src/util/base64-util.js +++ b/src/util/base64-util.js @@ -20,10 +20,13 @@ class Base64Util { /** * Convert a Uint8Array to a base64 encoded string. - * @param {Uint8Array} array - the array to convert. + * @param {Uint8Array|Array} array - the array to convert. * @return {string} - the base64 encoded string. */ static uint8ArrayToBase64 (array) { + if (Array.isArray(array)) { + array = new Uint8Array(array); + } let binary = ''; const len = array.byteLength; for (let i = 0; i < len; i++) { diff --git a/test/unit/util_base64.js b/test/unit/util_base64.js index c18c353333..f43aa14859 100644 --- a/test/unit/util_base64.js +++ b/test/unit/util_base64.js @@ -3,6 +3,7 @@ const Base64Util = require('../../src/util/base64-util'); test('uint8ArrayToBase64', t => { t.equal(Base64Util.uint8ArrayToBase64(new Uint8Array([0, 50, 80, 200])), 'ADJQyA=='); + t.equal(Base64Util.uint8ArrayToBase64([0, 50, 80, 200]), 'ADJQyA=='); t.end(); }); @@ -25,11 +26,13 @@ test('round trips', t => { new Uint8Array(0), new Uint8Array([10, 90, 0, 255, 255, 255, 10, 2]), new Uint8Array(10000), - new Uint8Array(1000000) + new Uint8Array(100000) ]; for (const uint8array of data) { const uint8ToBase64 = Base64Util.uint8ArrayToBase64(uint8array); + const arrayToBase64 = Base64Util.uint8ArrayToBase64(Array.from(uint8array)); const bufferToBase64 = Base64Util.arrayBufferToBase64(uint8array.buffer); + t.equal(uint8ToBase64, arrayToBase64); t.equal(uint8ToBase64, bufferToBase64); const decoded = Base64Util.base64ToUint8Array(uint8ToBase64); t.same(uint8array, decoded);