Skip to content

Commit

Permalink
more blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
BludIsAnLemon committed Sep 5, 2024
1 parent 2646607 commit 0702834
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion extensions/text.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Name: Text
// ID: strings
// Description: Manipulate characters and text.
// Original: CST1229 <https://scratch.mit.edu/users/CST1229/>
// By: CST1229 <https://scratch.mit.edu/users/CST1229/>
// By: BludIsAnLemon <https://scratch.mit.edu/users/BludIsAnLemon/>
// License: MIT AND MPL-2.0

(function (Scratch) {
Expand Down Expand Up @@ -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'
}
]
}
},
};
}
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 0702834

Please sign in to comment.