Sprites.Text
String operations over reactive values. Each function reads its arguments and returns a reactive value that follows them, so a label or a parsed number assembled from several values stays live and composes with the reactive structure.
- Sprites.Text.At
- Sprites.Text.Concat
- Sprites.Text.Length
- Sprites.Text.Lower
- Sprites.Text.ParseInt
- Sprites.Text.Replace
- Sprites.Text.Slice
- Sprites.Text.Upper
Sprites.Text.At Sprites.Reactive.Value
Sprites.Text.At(str, index)
The character at an index, or an empty string past the ends. Either argument may be a constant or a reactive value, so the result follows both.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to read from, read with Get. |
index | Number or Sprites.Reactive.Value | The position of the character, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the character at the index, empty past the ends.
const word = Sprites.Reactive.Value('sprite');
const index = Sprites.Reactive.Value(0);
const letter = Sprites.Text.At(word, index);
Sprites.Ui.Input.Text(word);
Sprites.Ui.Input.Number(index);
Sprites.Ui.Dom.Text(' letter = ', letter);
Sprites.Text.Concat Sprites.Reactive.Value
Sprites.Text.Concat(...parts)
Join the parts into one string, each turned to a string and joined with nothing between. Each part is a constant, a number or a reactive value, so the result follows every one.
| Input | Type | Description |
|---|---|---|
...parts | Any or Sprites.Reactive.Value | The pieces to join, each read with Get and turned to a string. |
Returns a read-only Sprites.Reactive.Value holding the joined string.
const first = Sprites.Reactive.Value('Ada');
const last = Sprites.Reactive.Value('Lovelace');
const full = Sprites.Text.Concat(first, ' ', last);
Sprites.Ui.Input.Text(first);
Sprites.Ui.Input.Text(last);
Sprites.Ui.Dom.Text(' full = ', full);
Sprites.Text.Length Sprites.Reactive.Value
Sprites.Text.Length(str)
The length of a string. The argument may be a constant or a reactive value, so the result follows it.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to measure, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the number of characters.
const word = Sprites.Reactive.Value('sprite');
const count = Sprites.Text.Length(word);
Sprites.Ui.Input.Text(word);
Sprites.Ui.Dom.Text(' count = ', count);
Sprites.Text.Lower Sprites.Reactive.Value
Sprites.Text.Lower(str)
A string lower cased. The argument may be a constant or a reactive value, so the result follows it.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to lower case, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the lower cased string.
const word = Sprites.Reactive.Value('SPRITE');
const lower = Sprites.Text.Lower(word);
Sprites.Ui.Input.Text(word);
Sprites.Ui.Dom.Text(' lower = ', lower);
Sprites.Text.ParseInt Sprites.Reactive.Value
Sprites.Text.ParseInt(str, radix)
The whole number a string spells in the given base, ten by default. Either argument may be a constant or a reactive value, so the result follows both.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to read a number from, read with Get. |
radix | Number or Sprites.Reactive.Value | The base to read in, ten by default, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the parsed whole number.
const digits = Sprites.Reactive.Value('42');
const number = Sprites.Text.ParseInt(digits);
Sprites.Ui.Input.Text(digits);
Sprites.Ui.Dom.Text(' number = ', number);
Sprites.Text.Replace Sprites.Reactive.Value
Sprites.Text.Replace(str, find, replace)
A copy of a string with every occurrence of find replaced by replace. Each argument may be a constant or a reactive value, so the result follows them.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to copy, read with Get. |
find | String or Sprites.Reactive.Value | The text to look for, read with Get. |
replace | String or Sprites.Reactive.Value | The text to put in its place, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the string with every match replaced.
const phrase = Sprites.Reactive.Value('red red red');
const painted = Sprites.Text.Replace(phrase, 'red', 'blue');
Sprites.Ui.Input.Text(phrase);
Sprites.Ui.Dom.Text(' painted = ', painted);
Sprites.Text.Slice Sprites.Reactive.Value
Sprites.Text.Slice(str, start, end)
A slice of a string, from start up to end. Leave end out for the rest. Each argument may be a constant or a reactive value, so the result follows them.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to slice, read with Get. |
start | Number or Sprites.Reactive.Value | The index to start from, read with Get. |
end | Number or Sprites.Reactive.Value | The index to stop before, or left out for the rest, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the slice of the string.
const word = Sprites.Reactive.Value('sprites');
const start = Sprites.Reactive.Value(0);
const end = Sprites.Reactive.Value(3);
const part = Sprites.Text.Slice(word, start, end);
Sprites.Ui.Input.Text(word);
Sprites.Ui.Input.Number(start);
Sprites.Ui.Input.Number(end);
Sprites.Ui.Dom.Text(' part = ', part);
Sprites.Text.Upper Sprites.Reactive.Value
Sprites.Text.Upper(str)
A string upper cased. The argument may be a constant or a reactive value, so the result follows it.
| Input | Type | Description |
|---|---|---|
str | String or Sprites.Reactive.Value | The string to upper case, read with Get. |
Returns a read-only Sprites.Reactive.Value holding the upper cased string.
const name = Sprites.Reactive.Value('sprite');
const loud = Sprites.Text.Upper(name);
Sprites.Ui.Input.Text(name);
Sprites.Ui.Dom.Text(' loud = ', loud);