hasOpening()

Checks whether the primitive value of a specified object has the opening chars or given opening chars.

Wrap.prototype.hasOpening()

Checks whether the primitive value of a specified object has the opening chars or given opening chars.

If given opening chars in the constructor are the empty string, the method returns false.

wrap.class.ts
public hasOpening(opening?: string): boolean {
  return (
    this.#opening.length >= 1 &&
    (typeof opening === 'string' ? this.#opening === opening : true)
  );
}

Parameters

opening?: string

Optional opening chars of a string type to check if the primitive value contains them at the beginning.

Returns

The return value is a boolean indicating whether the primitive value has the opening chars or given opening chars.

Example usage

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

// Returns true.
new Wrap(`[`, `]`, 'quote').hasOpening();

// Returns false.
new Wrap(``, `]`, 'quote').hasOpening();

Given closing chars

// Example usage of given opening chars.
import { Wrap } from '@angular-package/wrapper';

// Returns true.
new Wrap(`[`, `]`, 'quote').hasOpening('[');

// Returns false.
new Wrap(`[`, `]`, 'quote').hasOpening('');

// Returns false.
new Wrap(``, `]`, 'quote').hasOpening('');

// Returns false.
new Wrap(``, `]`, 'quote').hasOpening('[');

Last updated