Static methods

Public

Wrapper.define()

Defines a new Wrapper instance consisting of the allowed opening and closing.

Good to know: The opening and closing parameters are filtered by the allowed chars.

wrapper.class.ts
public static define<Opening extends string, Closing extends string>(
  opening: Opening,
  closing: Closing
): Wrapper<Opening, Closing> {
  return new this(
    this.allowedChars.filterText(opening),
    this.allowedChars.filterText(closing)
  );
}
Generic type variables

Opening extends string

A generic type variable constrained by the string, by default of the value captured from the provided opening indicates the type of the opening in the Wrapper via return type.

Closing extends string

A generic type variable constrained by the string, by default of the value captured from the provided closing indicates the type of the closing in the Wrapper via return type.

Parameters

Name: typeDescription

opening: Opening

The allowed opening of the wrap of a generic type variable Opening.

closing: Closing

The allowed closing of the wrap of a generic type variable Closing.

Returns

The return value is a new Wrapper instance of given opening and closing.

Example usage

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

// Returns Wrap {'()'}
Wrapper.define('(', ')');

// Returns Wrapper{''}, char ! is not allowed.
Wrapper.define('!', '!');

Wrapper.getAllowedChars()

Gets the allowed characters of the AllowedChars type from the static Wrapper.

Good to know: The method refers to a private static property allowedChars which is the default value for filtering the wrap in the static define(), setWrap(), wrapText() methods.

wrapper.class.ts
public static getAllowedChars(): AllowedChars {
  return this.allowedChars;
}

Returns

The return value is a an AllowedChars pattern of allowed characters.

Example usage

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

// Returns the default /([\[\]\(\)<>{}])/g
Wrapper.getAllowedChars();

Wrapper.getWrap()

Gets an instance of Wrap stored in the static Wrapper.

Good to know: The method refers to a private static property wrap that is used by the static wrapText() method for wrapping the text.

wrapper.class.ts
public static getWrap<
  Opening extends string = string,
  Closing extends string = string
>(): Wrap<Opening, Closing> {
  return this.wrap as Wrap<Opening, Closing>;
}
Generic type variables

Opening extends string

A generic type variable constrained by the string indicates the type of the opening in the Wrap via return type.

Closing extends string

A generic type variable constrained by the string indicates the type of the closing in the Wrap via return type.

Returns

The return value is an instance of Wrap.

Example usage

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

// Returns `Wrap {'[]'}` of type `Wrap<string, string>`
Wrapper.getWrap();

// Returns `Wrap {'[]'}` of type `Wrap<"[", "]">`
Wrapper.getWrap<'[', ']'>();

Wrapper.isWrapper()

The method checks if the value of any type is an instance of the Wrapper.

wrapper.class.ts
public static isWrapper<Opening extends string, Closing extends string>(
  value: any,
  opening?: Opening,
  closing?: Closing
): value is Wrapper<Opening, Closing> {
  return isInstance(value, this) && super.isWrap(value, opening, closing);
}
Generic type variables

Opening extends string

A generic type variable constrained by the string, by default of the value captured from the provided opening indicates the type of the opening in the Wrapper via return type.

Closing extends string

A generic type variable constrained by the string, by default of the value captured from the provided closing indicates the type of the closing in the Wrapper via return type.

Parameters

Name: typeDescription

value: any

The value of any type to test against the instance of Wrapper.

opening?: Opening

An optional wrap opening to check if the given value contains.

closing?: Closing

An optional wrap closing to check if the given value contains.

Returns

Return type

value is Wrapper

The return type indicates the value is the Wrapper instance.

The return value is a boolean type indicating whether the value is an instance of Wrapper.

Example usage

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

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

// Returns true confirming the type Wrapper<string>
Wrapper.isWrapper(tagWrapper);

// Returns true confirming the type Wrapper<"[]">
Wrapper.isWrapper<'[', ']'>(tagWrapper);

// Returns false denying the type Wrapper<"[]">
Wrapper.isWrapper<'[', ']'>(null as any);

Wrapper.setAllowedChars()

The method sets the default pattern of allowed characters for static Wrapper.

Good to know: The allowed characters refers to a private static allowedChars property, which is the default value for filtering the wrap in the static define(), setWrap(), wrapText() methods.

wrapper.class.ts
public static setAllowedChars(allowedChars: RegExp): typeof Wrapper {
  this.allowedChars = new AllowedChars(allowedChars);
  return this;
}

Parameters

Name: typeDescription

allowedChars: RegExp

The allowed characters of the RegExp to set.

Returns

The return value is a static Wrapper.

Example usage

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

// Set the allowed chars for static `Wrapper`.
Wrapper.setAllowedChars(/[^<>]/g);

// Returns /[^<>]/g
Wrapper.getAllowedChars();

Wrapper.setWrap()

Sets a new instance of Wrap into the static Wrapper. The wrap set by this method is used to wrap the text by the static wrapText() method for wrapping the text.

Good to know: The opening and closing parameters are filtered by the allowed characters of static Wrapper set by the static method setAllowedChars().

wrapper.class.ts
public static setWrap<Opening extends string, Closing extends string>(
  opening: Opening,
  closing: Closing
): typeof Wrapper {
  this.wrap = new Wrap(
    this.allowedChars.filterText(opening),
    this.allowedChars.filterText(closing)
  );
  return this;
}
Generic type variables

Opening extends string

A generic type variable constrained by the string, by default of the value captured from the provided opening indicates the type of the Wrap opening.

Closing extends string

A generic type variable constrained by the string, by default of the value captured from the provided closing indicates the type of the Wrap closing.

Parameters

Name: typeDescription

opening: Opening

The wrap opening of a generic type variable Opening.

closing: Closing

The wrap closing of a generic type variable Closing.

Returns

The return value is a static Wrapper.

Example usage

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

// Set the `Wrap`.
Wrapper.setWrap('<', '>');

// Returns Wrap {'<>'} of type `Wrap<string, string>`
Wrapper.getWrap();

// Returns Wrap {'<>'} of type `Wrap<"<", ">">`
Wrapper.getWrap<'<', '>'>();

Wrapper.wrapText()

The static method wraps the specified text with a stored Wrap instance in the static Wrapper or with a given opening or closing.

Good to know: The opening and closing parameters are filtered by the allowed chars of static Wrapper set by the static method setAllowedChars().

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

Text extends string

A generic type variable constrained by the string indicates the type of the text in the Wrapped via return type.

Opening extends string

A generic type variable constrained by the string, by default of the value captured from the provided opening indicates the type of the opening in the Wrapped via return type.

Closing extends string

A generic type variable constrained by the string, by default of the value captured from the provided closing indicates the type of the closing in the Wrapped via return type.

Parameters

Name: typeDescription

text: Text

The text of a generic type variable Text to wrap it with a stored Wrap in the static Wrapper or provided allowed chars.

opening: Opening

An optional wrap opening of a generic type variable Opening to wrap the given text. If the opening is not provided, then the opening from the Wrap instance of static Wrapper is used.

closing: Closing

An optional wrap closing of a generic type variable Closing to wrap the given text. If the closing is not provided, then the closing from the Wrap instance of static Wrapper is used.

Returns

The return value is a new Wrapped instance of given text.

Example usage

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

// Set the wrap.
Wrapper.setWrap('<', '>');

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

// Returns Wrapped {'[[[Lorem Ipsum>'} of Wrapped<"Lorem Ipsum ", "[[[", string>
Wrapper.wrapText(`Lorem Ipsum `, '[[[');

// Returns Wrapped {'<Lorem Ipsum]]]'} of Wrapped<"Lorem Ipsum ", string, "]]]">
Wrapper.wrapText(`Lorem Ipsum `, undefined, ']]]');

Last updated