static hasOpening()

Checks whether the text has given opening chars at the beginning.

Wrap.hasOpening()

Checks whether the text has given opening chars at the beginning.

wrap.class.ts
public static hasOpening(text: string, opening: string): boolean {
  return (
    typeof text === 'string' &&
    text.length >= 1 &&
    typeof opening === 'string' &&
    opening.length >= 1 &&
    text.slice(0, opening.length) === opening
  );
}

Parameters

text: string

The text of string, to check whether it contains given opening chars.

opening: string

The opening chars of string to check if a given text contains.

Returns

The return value is a boolean indicating whether the text contains opening chars at the beginning.

Example usage

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

const quote = new Wrap(`[`, `]`, 'quote');

// Returns true.
Wrap.hasOpening(quote.valueOf(), '[');

// Returns false.
Wrap.hasOpening(quote.valueOf(), '>');

// Returns false.
Wrap.hasOpening(quote.valueOf(), '');

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

Last updated