@colibri-engine/string v2.0.5
String library
Presentation
The engine is based on incremental computation algorithms. When a calculation is submitted to the engine, all the computed values are memorized. So, if you change some variable and query an evaluation, the engine is able to compute the result very fast because it recomputes only what has changed.
Libraries
The API provides several libraries that each comes with dozens of operators.
- @colibri-engine/boolean
- @colibri-engine/number
- @colibri-engine/date
- @colibri-engine/dictionary
- @colibri-engine/math
- @colibri-engine/structural
Imports
Typescript
import {/* required operators */} from '@colibri-engine/string';
Javascript
const {/* required operators */} = require('@colibri-engine/string');
Operators
string
string(value) ➜ xstring
string() ➜ xstring
The string operator allows you to create a string expression which evals to the given value. If no value is provided the expression is a variable of the model
import {string} from "@colibri-engine/string"
const x = string('Hello world') | string();
x.affect('World Hello');
is
is(xstring, ystring) ➜ zboolean
xstring.is(ystring) ➜ zboolean
The is operator allows to create a boolean expression which evals to true
if x equals y
import {string, is} from "@colibri-engine/string"
const x = string();
const y = string();
const z = is(x, y) | x.is(y);
const value = z.eval();
isNot
isNot(xstring, ystring) ➜ zboolean
xstring.isNot(ystring) ➜ zboolean
The isNot operator allows to create a boolean expression which evals to true
if x is not y
import {string, isNot} from "@colibri-engine/string"
const x = string();
const y = string();
const z = isNot(x, y) | x.isNot(y);
const value = z.eval();
chatAt
charAt(xstring, ynumber) ➜ zstring
xstring.charAt(ynumber) ➜ zstring
The charAt operator allows to create a string expression which evals to the character fo x at the y position
import {number} from "@colibri-engine/number";
import {string, charAt} from "@colibri-engine/string"
const x = string();
const y = number();
const z = charAt(x, y) | x.charAt(y);
const value = z.eval();
indexOf
indexOf(xstring, ystring) ➜ znumber
xstring.indexOf(ystring) ➜ znumber
The indexOf operator allows to create a number expression which evals to the position of y in x
import {string, indexOf} from "@colibri-engine/string"
const x = string();
const y = string();
const z = indexOf(x, y) | x.indexOf(y)
const value = z.eval();
concat
concat(x0string, x1string, ..., xnstring) ➜ ystring
x0string.concat(x1string, ..., xnstring) ➜ yboolean
The concat operator allows to create a string expression which evals to the concatenation of the given expressions
import {string, concat} from "@colibri-engine/string"
const x0 = string();
const x1 = string();
// ...
const xn = string();
const y = concat(x0, x1, ..., xn) | x0.concat(x1, ..., xn);
const value = y.eval();
include
include(xstring, ystring) ➜ zboolean
xstring.include(ystring) ➜ zboolean
The include operator allows to create a boolean expression which evals to true
if x includes y
import {string, include} from "@colibri-engine/string"
const x = string();
const y = string();
const z = include(x, y) | x.include(y);
const value = z.eval();
startsWith
startsWith(xstring, ystring) ➜ zboolean
xstring.startsWith(ystring) ➜ zboolean
The startsWith operator allows to create a boolean expression which evals to true
if x starts with y
import {string, startsWith} from "@colibri-engine/string"
const x = string();
const y = string();
const z = startsWith(x, y) | x.startsWith(y);
const value = z.eval();
endsWith
endsWith(xstring, ystring) ➜ zboolean
xstring.endsWith(ystring) ➜ zboolean
The endsWith operator allows to create a boolean expression which evals to true
if x ends with y
import {string, endsWith} from "@colibri-engine/string"
const x = string();
const y = string();
const z = endsWith(x, y) | x.endsWith(y);
const value = z.eval();
padStart
padStart(xstring, y1string, y2number) ➜ zstring
xstring.padStart(y1string, y2number) ➜ zstring
The start operator allows to create a string expression which evals to x with y1 repetated by the start until the size reach y2
import {string, include} from "@colibri-engine/string"
import {number} from "@colibri-engine/number";
const x = string();
const y1 = string();
const y2 = number();
const z = padStart(x, y1, y2) | x.padStart(y1, y2);
const value = z.eval();
padEnd
padEnd(xstring, y1string, y2number) ➜ zstring
xstring.padEnd(y1string, y2number) ➜ zstring
The padEnd operator allows to create a string expression which evals to x with y1 repetated by the end until the size reach y2
import {string, include} from "@colibri-engine/string"
import {number} from "@colibri-engine/number";
const x = string();
const y1 = string();
const y2 = number();
const z = padEnd(x, y1, y2) | x.padEnd(y1, y2);
const value = z.eval();
length
length(xstring) ➜ ynumber
xstring.length() ➜ ynumber
The length operator allows to create a number expression which evals to the length of x
import {string, length} from "@colibri-engine/string"
const x = string();
const y = length(x) | x.length();
const value = y.eval();
trim
trim(xstring) ➜ ystring
xstring.trim() ➜ ystring
The trim operator allows to create a string expression which evals to x where the left and right spaces has been removed
import {string, trim} from "@colibri-engine/string"
const x = string();
const y = trim(x) | x.trim();
const value = y.eval();
replace
replace(xstring, y1string, y2string) ➜ zstring
xstring.replace(y1string, y2string) ➜ zstring
The replace operator allows to create a string expression which evals to x where y1 has been replaced by y2
import {string, replace} from "@colibri-engine/string"
const x = string();
const y1 = string();
const y2 = string();
const z = replace(x, y1, y2) | x.replace(y1, y2);
const value = z.eval();
subString
subString(xstring, y1number, y2number) ➜ zstring
xstring.subString(y1number, y2number) ➜ zstring
The slice operator allows to create a string expression which evals to a substring of x where the starting index is y1 and the length is y2
import {number} from "@colibri-engine/number";
import {string, subString} from "@colibri-engine/string"
const x = string();
const y1 = number();
const y2 = number();
const y = subString(x, y1, y2) | x.subString(y1, y2);
const value = y.eval();
slice
slice(xstring, y1number, y2number) ➜ zstring
xstring.slice(y1number, y2number) ➜ zstring
The slice operator allows to create a string expression which evals to a substring of x where the starting index is y1 and the end is y2
import {number} from "@colibri-engine/number";
import {string, slice} from "@colibri-engine/string"
const x = string();
const y1 = number();
const y2 = number();
const y = slice(x, y1, y2) | x.slice(y1, y2);
const value = y.eval();
toUppercase
toUppercase(xstring) ➜ ystring
xstring.toUppercase() ➜ ystring
The toLowercase operator allows to create a string expression which evals to x uppercased
import {string, toUppercase} from "@colibri-engine/string"
const x = string();
const y = toUppercase(x) | x.toUppercase();
const value = y.eval();
toLowercase
toLowercase(xstring) ➜ ystring
xstring.toLowercase() ➜ ystring
The toLowercase operator allows to create a string expression which evals to x lowercased
import {string, toLowercase} from "@colibri-engine/string"
const x = string();
const y = toLowercase(x) | x.toLowercase();
const value = y.eval();