BiString
- class BiString(original, modified, alignment)
A bidirectionally transformed string.
A BiString can be constructed from only a single string, which will give it identical original and modified strings and an identity alignment:
new BiString("test");
You can also explicitly specify both the original and modified strings. The inferred alignment will be as course as possible:
new BiString("TEST", "test");
Finally, you can specify the alignment explicitly, if you know it:
new BiString("TEST", "test", Alignment.identity(4));
- Arguments
original (
string()
) – The original string, before any modifications.modified (
string()
) – The modified string, after any modifications.alignment (
Alignment()
) – The alignment between the original and modified strings.
- BiString.alignment
type: Alignment
The sequence alignment between original and modified.
- BiString.length
type: number
The length of the modified string.
- BiString.modified
type: string
The current value of the string, after all modifications.
- BiString.original
type: string
The original string, before any modifications.
- BiString.[iterator]()
Iterates over the code points in the modified string.
- Returns
IterableIterator<string> –
- BiString.boundsOf(searchValue, fromIndex)
Like
indexOf()
, but returns both the start and end positions for convenience.- Arguments
searchValue (
string()
) –fromIndex (
number()
) –
- Returns
Bounds –
- BiString.charAt(pos)
Like
String.prototype.charAt()
, returns a code unit as a string from the modified string.- Arguments
pos (
number()
) –
- Returns
string –
- BiString.charCodeAt(pos)
Like
String.prototype.charCodeAt()
, returns a code unit as a number from the modified string.- Arguments
pos (
number()
) –
- Returns
number –
- BiString.codePointAt(pos)
Like
String.prototype.codePointAt()
, returns a code point from the modified string.- Arguments
pos (
number()
) –
- Returns
undefined|number –
- BiString.concat(...others)
Concatenate this string together with one or more others. The additional strings can be either BiStrings or normal strings.
- Arguments
others (
AnyString[]()
) –
- Returns
BiString –
- BiString.endsWith(searchString, position)
Like
String.prototype.endsWith()
, returns whether this string ends with the given prefix.- Arguments
searchString (
string()
) –position (
number()
) –
- Returns
boolean –
- BiString.equals(other)
- Arguments
other (
BiString()
) –
- Returns
boolean – Whether this BiString is equal to another.
- BiString.indexOf(searchValue, fromIndex)
Like
String.prototype.indexOf()
, finds the first occurrence of a substring.- Arguments
searchValue (
string()
) –fromIndex (
number()
) –
- Returns
number –
- BiString.inverse()
- Returns
BiString – The inverse of this string, swapping the original and modified strings.
- BiString.join(items)
Like
Array.prototype.join()
, joins a sequence together with this BiString as the separator.- Arguments
items (
Iterable
) –
- Returns
BiString –
- BiString.lastBoundsOf(searchValue, fromIndex)
Like
lastIndexOf()
, but returns both the start and end positions for convenience.- Arguments
searchValue (
string()
) –fromIndex (
number()
) –
- Returns
Bounds –
- BiString.lastIndexOf(searchValue, fromIndex)
Like
String.prototype.lastIndexOf()
, finds the last occurrence of a substring.- Arguments
searchValue (
string()
) –fromIndex (
number()
) –
- Returns
number –
- BiString.match(regexp)
Like
String.prototype.match()
, returns the result of a regular expression match.- Arguments
regexp (
RegExp()
) –
- Returns
null|RegExpMatchArray –
- BiString.matchAll(regexp)
Like
String.prototype.matchAll()
, returns an iterator over all regular expression matches.- Arguments
regexp (
RegExp()
) –
- Returns
IterableIterator<RegExpMatchArray> –
- BiString.normalize(form)
Like
String.prototype.normalize()
, applies a Unicode normalization form.- Arguments
form (
'NFC'|'NFD'|'NFKC'|'NFKD'()
) – The normalization form to apply, one of “NFC”, “NFD”, “NFKC”, or “NFKD”.
- Returns
BiString –
- BiString.padEnd(targetLength, padString=" ")
Like
String.prototype.padEnd()
, pads a string at the end to a target length.- Arguments
targetLength (
number()
) –padString (
string()
) –
- Returns
BiString –
- BiString.padStart(targetLength, padString=" ")
Like
String.prototype.padStart()
, pads a string at the beginning to a target length.- Arguments
targetLength (
number()
) –padString (
string()
) –
- Returns
BiString –
- BiString.replace(pattern, replacement)
Like
String.prototype.replace()
, returns a new string with regex or fixed-string matches replaced.- Arguments
pattern (
string|RegExp()
) –replacement (
string|Replacer()
) –
- Returns
BiString –
- BiString.search(regexp)
Like
String.prototype.search()
, finds the position of the first match of a regular expression.- Arguments
regexp (
RegExp()
) –
- Returns
number –
- BiString.searchBounds(regexp)
Like
search()
, but returns both the start and end positions for convenience.- Arguments
regexp (
RegExp()
) –
- Returns
Bounds –
- BiString.slice(start, end)
Extract a slice of this BiString, with similar semantics to
String.prototype.slice()
.- Arguments
start (
number()
) –end (
number()
) –
- Returns
BiString –
- BiString.split(separator, limit)
Like
String.prototype.split()
, splits this string into chunks using a separator.- Arguments
separator (
string|RegExp()
) –limit (
number()
) –
- Returns
BiString[] –
- BiString.startsWith(searchString, position)
Like
String.prototype.startsWith()
, returns whether this string starts with the given prefix.- Arguments
searchString (
string()
) –position (
number()
) –
- Returns
boolean –
- BiString.substring(start, end)
Extract a substring of this BiString, with similar semantics to
String.prototype.substring()
.- Arguments
start (
number()
) –end (
number()
) –
- Returns
BiString –
- BiString.toLowerCase()
Like
String.prototype.toLowerCase()
, converts a string to lowercase.- Returns
BiString –
- BiString.toUpperCase()
Like
String.prototype.toUpperCase()
, converts a string to uppercase.- Returns
BiString –
- BiString.trim()
Like
String.prototype.trim()
, returns a new string with leading and trailing whitespace removed.- Returns
BiString –
- BiString.trimEnd()
Like
String.prototype.trim()
, returns a new string with trailing whitespace removed.- Returns
BiString –
- BiString.trimStart()
Like
String.prototype.trim()
, returns a new string with leading whitespace removed.- Returns
BiString –
- BiString.from(str)
Create a BiString from a string-like object.
- Arguments
str (
AnyString()
) – Either a string or a BiString.
- Returns
BiString – The input coerced to a BiString.
- BiString.infer(original, modified)
Create a BiString, automatically inferring an alignment between the original and modified strings.
- Arguments
original (
string()
) – The original string.modified (
string()
) – The modified string.
- Returns
BiString –