Instance methods

Public

Wrapper.prototype.isTextWrapped()

The method checks if the provided text is wrapped with the wrap of the specified Wrapper object.

wrapper.class.ts
public isTextWrapped<Text extends string>(text: Text): text is Text {
  return this.textHasClosing(text) && this.textHasOpening(text);
}
Generic type variables

Text extends string

​A generic type variable constrained by the string, by default of the value captured from the provided text parameter, confirms the text type via the return type.

Parameters

Name: typeDescription

text: Text

The text of a generic type variable Text to check whether it is wrapped.

Returns

The return value is a boolean indicating whether the provided text is wrapped.

Example usage

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

// Returns true of text is "[quote]"
new Wrapper(`[`, `]`).isTextWrapped(`[quote]`);

Wrapper.prototype.textHasClosing()

Checks if the provided text has a closing of the specified Wrapper object.

wrapper.class.ts
public textHasClosing<Text extends string>(text: Text): text is Text {
  return (
    isStringType(text) && text.slice(-this.closing.length) === this.closing
  );
}
Generic type variables

Text extends string

​A generic type variable constrained by the string, by default of the value captured from the provided text parameter, confirms the text type via the return type.

Parameters

Name: typeDescription

text: Text

The text to test against the existence of the closing.

Returns

The return value is a boolean indicating whether the given text has the closing of the wrap.

Example usage

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

// Returns true of text is "[quote]"
new Wrapper(`[`, `]`).textHasClosing(`[quote]`);

Wrapper.prototype.textHasOpening()

Checks if the provided text has an opening of the specified Wrapper object.

wrapper.class.ts
public textHasOpening<Text extends string>(text: Text): text is Text {
  return (
    isStringType(text) && text.slice(0, this.opening.length) === this.opening
  );
}
Generic type variables

Text extends string

​A generic type variable constrained by the string, by default of the value captured from the provided text parameter, confirms the text type via the return type.

Parameters

Name: typeDescription

text: Text

The text to test against the existence of the opening.

Returns

The return value is a boolean indicating whether the given text has the opening of the wrap.

Example usage

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

// Returns true of text is "[quote]"
new Wrapper(`[`, `]`).textHasOpening(`[quote]`);

Wrapper.prototype.unwrapText()

Returns the unwrapped text, without the opening and closing of the Wrapper.

wrapper.class.ts
public unwrapText(text: string): string {
  this.textHasClosing(text) &&
    (text = text.valueOf().slice(0, text.length - this.closing.length));
  this.textHasOpening(text) &&
    (text = text.valueOf().slice(this.opening.length));
  return text;
}

Parameters

Name: typeDescription

text: string

The text to unwrap.

Returns

The return value is the unwrapped text of a string if the opening or closing is found or the given text.

Example usage

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

// Define a new `Wrapper`.
const wrapper = new Wrapper('[', ']');

 // Returns [[There is a wrapped text]]
const unwrapped = wrapper.unwrapText('[[[There is a wrapped text]]]');

// Returns [There is a wrapped text]
wrapper.unwrapText(unwrapped);

Wrapper.prototype.wrapText()

Wraps specific text with the wrap, the opening, and closing of the Wrapper object.

wrapper.class.ts
public wrapText<Text extends string>(
  text: Text
): Wrapped<Text, Opening, Closing> {
  return new Wrapped(text, this);
}
Generic type variables

Text extends string

​A generic type variable constrained by the string by default of the value captured from the provided text parameter indicates the text type of Wrapped via the return type.

Parameters

Name: typeDescription

text: Text

The text of a generic type variable Text, to be wrapped.

Returns

The return value is a new instance of Wrapped type consisting of the wrapped text.

Example usage

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

// Returns Wrapped {'[Lorem]'} of Wrapped<"Lorem", "[", "]">
new Wrapper('[', ']').wrapText('Lorem');

// Returns Wrapped {'{Lorem}'} of Wrapped<"Lorem", "{", "}">
new Wrapper('{', '}').wrapText('Lorem');

Last updated