unwrap()

Wrapper.unwrap()

The method returns the given text without the given opening and closing chars.

wrapper.class.ts
public static unwrap(text: string, opening = '', closing = ''): string {
  return (
    (text = this.replaceClosing(text, closing, '')),
    (text = this.replaceOpening(text, opening, '')),
    text
  );
}

Parameters

text: string

The text of the string from which given opening and closing chars are removed.

opening: string

The opening chars of the string to be removed in the given text.

closing: string

The closing chars of the string to be removed in the given text.

Returns

The return value is the given text of string type without the given opening and closing chars or unchanged text if it does not contain the given opening and closing chars.

Example usage

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

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

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

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

Last updated