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

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe string to read from, read with Get.
indexNumber or Sprites.Reactive.ValueThe 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);
The character at the chosen position, live as you type.

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.

InputTypeDescription
...partsAny or Sprites.Reactive.ValueThe 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);
The two names joined with a space, live as you type.

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe 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);
The character count, live as you type.

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe 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);
The string in lower case, live as you type.

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe string to read a number from, read with Get.
radixNumber or Sprites.Reactive.ValueThe 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);
The whole number the digits spell, live as you type.

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe string to copy, read with Get.
findString or Sprites.Reactive.ValueThe text to look for, read with Get.
replaceString or Sprites.Reactive.ValueThe 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);
Every occurrence of red becomes blue, live as you type.

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe string to slice, read with Get.
startNumber or Sprites.Reactive.ValueThe index to start from, read with Get.
endNumber or Sprites.Reactive.ValueThe 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);
The slice between the two positions, live as you type.

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.

InputTypeDescription
strString or Sprites.Reactive.ValueThe 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);
The string in upper case, live as you type.