From 0702834d688eeb09dcc03d388fc0645374a35120 Mon Sep 17 00:00:00 2001 From: Lemon <165233560+BludIsAnLemon@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:19:10 +0800 Subject: [PATCH 1/3] more blocks --- extensions/text.js | 95 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/extensions/text.js b/extensions/text.js index e03c7705a9..cc9c3e5da2 100644 --- a/extensions/text.js +++ b/extensions/text.js @@ -1,7 +1,8 @@ // Name: Text // ID: strings // Description: Manipulate characters and text. -// Original: CST1229 +// By: CST1229 +// By: BludIsAnLemon // License: MIT AND MPL-2.0 (function (Scratch) { @@ -372,12 +373,79 @@ }, }, }, + + "---", + + { + opcode: 'endsAt', + blockType: Scratch.BlockType.BOOLEAN, + text: Scratch.translate('[STRING] ends with [SUBSTRING]?'), + arguments: { + STRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'apple' + }, + SUBSTRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'banana' + } + } + }, + + "---", + + { + opcode: 'backwards', + blockType: Scratch.BlockType.REPORTER, + text: Scratch.translate('[STRING] backwards'), + arguments: { + STRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'apple' + } + } + }, + + "---", + + { + opcode: 'trim', + blockType: Scratch.BlockType.REPORTER, + text: Scratch.translate('trim [STRING] at [METHOD]'), + arguments: { + STRING: { + type: Scratch.ArgumentType.STRING, + defaultValue: ' apple ' + }, + METHOD: { + type: Scratch.ArgumentType.STRING, + menu: "trimMethod" + } + } + } ], menus: { textCase: { acceptReporters: true, items: this._initCaseMenu(), }, + trimMethod: { + acceptReporters: true, + items: [ + { + text: Scratch.translate('both sides'), + value: 'both' + }, + { + text: Scratch.translate('the end'), + value: 'front' + }, + { + text: Scratch.translate('the start'), + value: 'back' + } + ] + } }, }; } @@ -613,6 +681,31 @@ return string; } } + endsAt(args) { + let STRING = args.STRING + return STRING.endsWith(args.SUBSTRING); + } + backwards(args) { + let backwardsText = Array.from(args.STRING); + backwardsText.reverse(); + return backwardsText.join(''); + } + trim(args) { + let method = args.METHOD; + let STRING = args.STRING; + if(method == "both") { + return STRING.trim(); + } + else if(method == "front") { + return STRING.trimEnd(); + } + else if(method == "back") { + return STRING.trimStart(); + } + else { + return 'Please select a valid method!'; + } + } } Scratch.extensions.register(new StringsExt()); From d72a5c40a5b80bb3a0d983e5908864bfde370a15 Mon Sep 17 00:00:00 2001 From: Lemon <165233560+BludIsAnLemon@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:25:38 +0800 Subject: [PATCH 2/3] code run through prettier --- extensions/text.js | 83 ++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 43 deletions(-) diff --git a/extensions/text.js b/extensions/text.js index cc9c3e5da2..7d94080832 100644 --- a/extensions/text.js +++ b/extensions/text.js @@ -75,7 +75,7 @@ opcode: "letters_of", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate( - "letters [LETTER1] to [LETTER2] of [STRING]" + "letters [LETTER1] to [LETTER2] of [STRING]", ), arguments: { LETTER1: { @@ -155,7 +155,7 @@ opcode: "replace", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate( - "replace [SUBSTRING] in [STRING] with [REPLACE]" + "replace [SUBSTRING] in [STRING] with [REPLACE]", ), arguments: { SUBSTRING: { @@ -218,7 +218,7 @@ opcode: "replaceRegex", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate( - "replace regex /[REGEX]/[FLAGS] in [STRING] with [REPLACE]" + "replace regex /[REGEX]/[FLAGS] in [STRING] with [REPLACE]", ), arguments: { REGEX: { @@ -377,52 +377,52 @@ "---", { - opcode: 'endsAt', + opcode: "endsAt", blockType: Scratch.BlockType.BOOLEAN, - text: Scratch.translate('[STRING] ends with [SUBSTRING]?'), + text: Scratch.translate("[STRING] ends with [SUBSTRING]?"), arguments: { STRING: { type: Scratch.ArgumentType.STRING, - defaultValue: 'apple' + defaultValue: "apple", }, SUBSTRING: { type: Scratch.ArgumentType.STRING, - defaultValue: 'banana' - } - } + defaultValue: "banana", + }, + }, }, "---", { - opcode: 'backwards', + opcode: "backwards", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate('[STRING] backwards'), + text: Scratch.translate("[STRING] backwards"), arguments: { STRING: { type: Scratch.ArgumentType.STRING, - defaultValue: 'apple' - } - } + defaultValue: "apple", + }, + }, }, "---", { - opcode: 'trim', + opcode: "trim", blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate('trim [STRING] at [METHOD]'), + text: Scratch.translate("trim [STRING] at [METHOD]"), arguments: { STRING: { type: Scratch.ArgumentType.STRING, - defaultValue: ' apple ' + defaultValue: " apple ", }, METHOD: { type: Scratch.ArgumentType.STRING, - menu: "trimMethod" - } - } - } + menu: "trimMethod", + }, + }, + }, ], menus: { textCase: { @@ -433,19 +433,19 @@ acceptReporters: true, items: [ { - text: Scratch.translate('both sides'), - value: 'both' + text: Scratch.translate("both sides"), + value: "both", }, { - text: Scratch.translate('the end'), - value: 'front' + text: Scratch.translate("the end"), + value: "front", }, { - text: Scratch.translate('the start'), - value: 'back' - } - ] - } + text: Scratch.translate("the start"), + value: "back", + }, + ], + }, }, }; } @@ -508,7 +508,7 @@ STRING: args.STRING, ITEM: 0, }, - util + util, ); return splitCache.arr.length - 1 || 0; } @@ -553,7 +553,7 @@ return args.STRING.replace( new RegExp(args.REGEX, args.FLAGS), - args.REPLACE + args.REPLACE, ); } catch (e) { console.error(e); @@ -658,7 +658,7 @@ case CaseParam.MIXEDCASE: return Array.from(string) .map((char, index) => - index % 2 === 0 ? char.toUpperCase() : char.toLowerCase() + index % 2 === 0 ? char.toUpperCase() : char.toLowerCase(), ) .join(""); case CaseParam.TITLECASE: @@ -682,28 +682,25 @@ } } endsAt(args) { - let STRING = args.STRING + let STRING = args.STRING; return STRING.endsWith(args.SUBSTRING); } backwards(args) { let backwardsText = Array.from(args.STRING); backwardsText.reverse(); - return backwardsText.join(''); + return backwardsText.join(""); } trim(args) { let method = args.METHOD; let STRING = args.STRING; - if(method == "both") { + if (method == "both") { return STRING.trim(); - } - else if(method == "front") { + } else if (method == "front") { return STRING.trimEnd(); - } - else if(method == "back") { + } else if (method == "back") { return STRING.trimStart(); - } - else { - return 'Please select a valid method!'; + } else { + return "Please select a valid method!"; } } } From bb405af8f6866ae076a0b0c44b33cd1ca2a5530c Mon Sep 17 00:00:00 2001 From: Lemon <165233560+BludIsAnLemon@users.noreply.github.com> Date: Thu, 5 Sep 2024 10:29:15 +0800 Subject: [PATCH 3/3] Update text.js --- extensions/text.js | 78 +++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/extensions/text.js b/extensions/text.js index 7d94080832..d1ec10dd70 100644 --- a/extensions/text.js +++ b/extensions/text.js @@ -75,7 +75,7 @@ opcode: "letters_of", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate( - "letters [LETTER1] to [LETTER2] of [STRING]", + "letters [LETTER1] to [LETTER2] of [STRING]" ), arguments: { LETTER1: { @@ -155,7 +155,7 @@ opcode: "replace", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate( - "replace [SUBSTRING] in [STRING] with [REPLACE]", + "replace [SUBSTRING] in [STRING] with [REPLACE]" ), arguments: { SUBSTRING: { @@ -218,7 +218,7 @@ opcode: "replaceRegex", blockType: Scratch.BlockType.REPORTER, text: Scratch.translate( - "replace regex /[REGEX]/[FLAGS] in [STRING] with [REPLACE]", + "replace regex /[REGEX]/[FLAGS] in [STRING] with [REPLACE]" ), arguments: { REGEX: { @@ -377,52 +377,52 @@ "---", { - opcode: "endsAt", + opcode: 'endsAt', blockType: Scratch.BlockType.BOOLEAN, - text: Scratch.translate("[STRING] ends with [SUBSTRING]?"), + text: Scratch.translate('[STRING] ends with [SUBSTRING]?'), arguments: { STRING: { type: Scratch.ArgumentType.STRING, - defaultValue: "apple", + defaultValue: 'apple' }, SUBSTRING: { type: Scratch.ArgumentType.STRING, - defaultValue: "banana", - }, - }, + defaultValue: 'banana' + } + } }, "---", { - opcode: "backwards", + opcode: 'backwards', blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("[STRING] backwards"), + text: Scratch.translate('[STRING] backwards'), arguments: { STRING: { type: Scratch.ArgumentType.STRING, - defaultValue: "apple", - }, - }, + defaultValue: 'apple' + } + } }, "---", { - opcode: "trim", + opcode: 'trim', blockType: Scratch.BlockType.REPORTER, - text: Scratch.translate("trim [STRING] at [METHOD]"), + text: Scratch.translate('trim [STRING] at [METHOD]'), arguments: { STRING: { type: Scratch.ArgumentType.STRING, - defaultValue: " apple ", + defaultValue: ' apple ' }, METHOD: { type: Scratch.ArgumentType.STRING, - menu: "trimMethod", - }, - }, - }, + menu: "trimMethod" + } + } + } ], menus: { textCase: { @@ -433,19 +433,19 @@ acceptReporters: true, items: [ { - text: Scratch.translate("both sides"), - value: "both", + text: Scratch.translate('both sides'), + value: 'both' }, { - text: Scratch.translate("the end"), - value: "front", + text: Scratch.translate('the end'), + value: 'front' }, { - text: Scratch.translate("the start"), - value: "back", - }, - ], - }, + text: Scratch.translate('the start'), + value: 'back' + } + ] + } }, }; } @@ -508,7 +508,7 @@ STRING: args.STRING, ITEM: 0, }, - util, + util ); return splitCache.arr.length - 1 || 0; } @@ -553,7 +553,7 @@ return args.STRING.replace( new RegExp(args.REGEX, args.FLAGS), - args.REPLACE, + args.REPLACE ); } catch (e) { console.error(e); @@ -658,7 +658,7 @@ case CaseParam.MIXEDCASE: return Array.from(string) .map((char, index) => - index % 2 === 0 ? char.toUpperCase() : char.toLowerCase(), + index % 2 === 0 ? char.toUpperCase() : char.toLowerCase() ) .join(""); case CaseParam.TITLECASE: @@ -682,25 +682,25 @@ } } endsAt(args) { - let STRING = args.STRING; + let STRING = args.STRING return STRING.endsWith(args.SUBSTRING); } backwards(args) { let backwardsText = Array.from(args.STRING); backwardsText.reverse(); - return backwardsText.join(""); + return backwardsText.join(''); } trim(args) { let method = args.METHOD; let STRING = args.STRING; - if (method == "both") { + if(method == "both") { return STRING.trim(); - } else if (method == "front") { + } else if(method == "front") { return STRING.trimEnd(); - } else if (method == "back") { + } else if(method == "back") { return STRING.trimStart(); } else { - return "Please select a valid method!"; + return 'Please select a valid method!'; } } }