BiString

class BiString(original, modified, alignment)

exported from bistring

Implements:
  • Iterable()

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 (undefined|string) – The modified string, after any modifications.

  • alignment (alignment.Alignment) – The alignment between the original and modified strings.

BiString.[Symbol.iterator]()

Iterates over the code points in the modified string.

Returns

IterableIterator

BiString.alignment

type: alignment.Alignment

The sequence alignment between original and modified.

BiString.boundsOf(searchValue, fromIndex)

Like indexOf(), but returns both the start and end positions for convenience.

Arguments
  • searchValue (string) –

  • fromIndex (undefined|number) –

Returns

alignment.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

number|undefined

BiString.concat(others)

Concatenate this string together with one or more others. The additional strings can be either BiStrings or normal strings.

Arguments
  • others (bistring.AnyString[]) –

Returns

bistring.BiString

BiString.endsWith(searchString, position)

Like String.prototype.endsWith(), returns whether this string ends with the given prefix.

Arguments
  • searchString (string) –

  • position (undefined|number) –

Returns

boolean

BiString.equals(other)
Arguments
  • other (bistring.BiString) –

Returns

boolean – Whether this BiString is equal to another.

BiString.from(str)

Create a BiString from a string-like object.

Arguments
  • str (bistring.AnyString) – Either a string or a BiString.

Returns

bistring.BiString – The input coerced to a BiString.

BiString.indexOf(searchValue, fromIndex)

Like String.prototype.indexOf(), finds the first occurrence of a substring.

Arguments
  • searchValue (string) –

  • fromIndex (undefined|number) –

Returns

number

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.BiString

BiString.inverse()
Returns

bistring.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

BiString.lastBoundsOf(searchValue, fromIndex)

Like lastIndexOf(), but returns both the start and end positions for convenience.

Arguments
  • searchValue (string) –

  • fromIndex (undefined|number) –

Returns

alignment.Bounds

BiString.lastIndexOf(searchValue, fromIndex)

Like String.prototype.lastIndexOf(), finds the last occurrence of a substring.

Arguments
  • searchValue (string) –

  • fromIndex (undefined|number) –

Returns

number

BiString.length

type: number

The length of the modified string.

BiString.match(regexp)

Like String.prototype.match(), returns the result of a regular expression match.

Arguments
  • regexp (RegExp) –

Returns

RegExpMatchArray|null

BiString.matchAll(regexp)

Like String.prototype.matchAll(), returns an iterator over all regular expression matches.

Arguments
  • regexp (RegExp) –

Returns

IterableIterator

BiString.modified

type: string

The current value of the string, after all modifications.

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

BiString.original

type: string

The original string, before any modifications.

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

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

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|regex.Replacer) –

Returns

bistring.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

alignment.Bounds

BiString.slice(start, end)

Extract a slice of this BiString, with similar semantics to String.prototype.slice().

Arguments
  • start (number) –

  • end (undefined|number) –

Returns

bistring.BiString

BiString.split(separator, limit)

Like String.prototype.split(), splits this string into chunks using a separator.

Arguments
  • separator (string|RegExp) –

  • limit (undefined|number) –

Returns

bistring.BiString[]

BiString.startsWith(searchString, position)

Like String.prototype.startsWith(), returns whether this string starts with the given prefix.

Arguments
  • searchString (string) –

  • position (undefined|number) –

Returns

boolean

BiString.substring(start, end)

Extract a substring of this BiString, with similar semantics to String.prototype.substring().

Arguments
  • start (number) –

  • end (undefined|number) –

Returns

bistring.BiString

BiString.toLowerCase()

Like String.prototype.toLowerCase(), converts a string to lowercase.

Returns

bistring.BiString

BiString.toUpperCase()

Like String.prototype.toUpperCase(), converts a string to uppercase.

Returns

bistring.BiString

BiString.trim()

Like String.prototype.trim(), returns a new string with leading and trailing whitespace removed.

Returns

bistring.BiString

BiString.trimEnd()

Like String.prototype.trim(), returns a new string with trailing whitespace removed.

Returns

bistring.BiString

BiString.trimStart()

Like String.prototype.trim(), returns a new string with leading whitespace removed.

Returns

bistring.BiString