replaceOpening()

Wrapper.replaceOpening()

Replaces given opening chars with a given replacement value at the beginning of the given text.

wrapper.class.ts
public static replaceOpening(
  text: string,
  opening: string,
  replaceValue: string
): string {
  return this.hasOpening(text, opening)
    ? text.replace(opening, String(replaceValue))
    : text;
}

Parameters

text: string

The text of string type in which the given opening chars are replaced by a given replacement value.

opening: string

The opening chars of the string to replace by a given replacement value at the beginning of the given text.

replaceValue: string

The replacement value of a string type for the given opening characters in the given text.

Returns

The return value is the given text of string type with a replaced opening chars by a given replacement value or the specified text unchanged if it does not contain the given opening chars.

Example usage

Single bracket

// Example usage.
import { Wrapper } from '@angular-package/wrapper';

const quote = new Wrapper('[', ']', 'quote');

// Returns <quote] of string.
Wrapper.replaceOpening(quote.valueOf(), '[', '<');

// Returns {{quote] of string.
Wrapper.replaceOpening(quote.valueOf(), '[', '{{');

Triple bracket

// Example usage.
import { Wrapper } from '@angular-package/wrapper';

const quote = new Wrapper('[[', ']]', '[quote]');

// Returns <[[quote]]] of string.
Wrapper.replaceOpening(quote.valueOf(), '[', '<');

// Returns {{[[quote]]] of string.
Wrapper.replaceOpening(quote.valueOf(), '[', '{{');

// Returns {quote]]] of string.
Wrapper.replaceOpening(quote.valueOf(), '[[[', '{');

// Returns style=""[quote]]] of string.
Wrapper.replaceOpening(quote.valueOf(), quote.opening, ' style=""');

Last updated