Instance methods
Public
Wrapper.prototype.isTextWrapped()
Wrapper.prototype.isTextWrapped()
The method checks if the provided text
is wrapped with the wrap of the specified Wrapper
object.
public isTextWrapped<Text extends string>(text: Text): text is Text {
return this.textHasClosing(text) && this.textHasOpening(text);
}
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
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()
Wrapper.prototype.textHasClosing()
Checks if the provided text
has a closing of the specified Wrapper
object.
public textHasClosing<Text extends string>(text: Text): text is Text {
return (
isStringType(text) && text.slice(-this.closing.length) === this.closing
);
}
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
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()
Wrapper.prototype.textHasOpening()
Checks if the provided text
has an opening of the specified Wrapper
object.
public textHasOpening<Text extends string>(text: Text): text is Text {
return (
isStringType(text) && text.slice(0, this.opening.length) === this.opening
);
}
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
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()
Wrapper.prototype.unwrapText()
Returns the unwrapped text, without the opening and closing of the Wrapper
.
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
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()
Wrapper.prototype.wrapText()
Wraps specific text with the wrap, the opening
, and closing
of the Wrapper
object.
public wrapText<Text extends string>(
text: Text
): Wrapped<Text, Opening, Closing> {
return new Wrapped(text, this);
}
Parameters
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
Was this helpful?