-
Notifications
You must be signed in to change notification settings - Fork 538
Expand file tree
/
Copy pathstrings-1.js
More file actions
49 lines (48 loc) · 1.35 KB
/
strings-1.js
File metadata and controls
49 lines (48 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Strings1 {
getInfo() {
return {
id: 'strings1example',
name: Scratch.translate('Encoding'),
blocks: [
{
opcode: 'convert',
blockType: Scratch.BlockType.REPORTER,
text: Scratch.translate('convert [TEXT] to [FORMAT]'),
arguments: {
TEXT: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Apple'
},
// highlight-start
FORMAT: {
type: Scratch.ArgumentType.STRING,
menu: 'FORMAT_MENU'
}
// highlight-end
}
}
],
// highlight-start
menus: {
FORMAT_MENU: {
acceptReporters: true,
items: ['uppercase', 'lowercase']
}
}
// highlight-end
};
}
convert (args) {
if (args.FORMAT === 'uppercase') {
// Notice the toString() call: TEXT might be a number or boolean,
// so we have to make sure to convert it to a string first so that
// it has a toUpperCase() function, otherwise we will get an error!
// Remember: the argument's "type" is just a suggestion for the
// editor; it's never enforced.
return args.TEXT.toString().toUpperCase();
} else {
return args.TEXT.toString().toLowerCase();
}
}
}
Scratch.extensions.register(new Strings1());