Skip to content

This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.

TEXT_PACKAGE

const TEXT_PACKAGE: IEnginePackage;

Defined in: packages/engine/src/packages/text/TextPackage.ts:49

Text operations on String values (issues #236, #237). Measure text (length of, words in, characters in, lines in), test it (contains, starts with, ends with), and reshape it (trim, reverse, X repeated N times, as upper/lower/title/slug, and the replace(text, find, with) function). Every form also has a call spelling (length("hi")), and joining text with text is plain +.

On by default and removable, like the other utility packages. A non-text input to any operation is answered with a structured Error that names what it wanted, never a wrong value.

Two grammar boundaries worth stating, both because a word is already spoken for elsewhere in the language: replace is a function rather than the natural “replace A with B in C”, because “with” is the word form of ”+” (40 with 2 is 42); and “times” in X repeated N times is optional, because it is the word form of ”*” (8 times 9 is 72) and is recognised here only as a trailing flourish on the count.

It also reads values out of pasted text (issue #520): numbers in X and amounts in X list the numbers and the amounts of money a text holds, in the engine’s number format; total of numbers in X and the other aggregates read them directly; match, matches and matchcount take a regular expression, run by the package’s own linear-time matcher (see TextPattern.ts), never by RegExp; and field(json, "path") reads one value out of JSON.