isAttribute()

Attribute.isAttribute()

The method checks whether the value of any type is the Wrap instance of any or given opening and closing chars.

attribute.class.ts
public static isAttribute<Name extends string, Value extends string>(
  value: any,
  name?: Name,
  val?: Value
): value is Attribute<Name, Value> {
  return typeof value === 'object' && value instanceof this
    ? (typeof name === 'string' ? value.name === name : true) &&
        (typeof val === 'string' ? value.value === val : true)
    : false;
}
Generic type variables

Name extends string

Value extends string

Parameters

Name: type
Description

value: any

name?: Name

Optional opening chars of a generic type variable Opening to check if the given value contains.

val?: Value

Optional closing chars of a generic type variable Closing to check if the given value contains.

Returns

Return type

value is Attribute<Name, Value>

The return value is a boolean type indicating whether the value is an instance of Wrap of any, or the given opening, closing, and text.

Example usage

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

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

// Returns true confirming the type Wrap<"[", "", "]">
Wrap.isWrap(tagWrap);

// Returns true, confirming the type Wrap<"[", "", "]">
Wrap.isWrap(tagWrap, '[', ']');

// Returns true, confirming the type Wrap<"[", "quote", "]">
Wrap.isWrap(tagWrap, '[', ']', 'quote');

// Returns true, confirming the type Wrap<"[", "", "]">
Wrap.isWrap<'[', ']'>(tagWrap, '[', ']');

// Returns false, denying the type Wrap<"[", "span", "]">
Wrap.isWrap(tagWrap, '[', ']', 'span');

// Returns false denying the value is Wrap<"(", "", ")">
Wrap.isWrap(tagWrap, '(', ')');

// Returns false denying the value is Wrap<"(", "", ")">
Wrap.isWrap<'[', ']'>(null as any);

// Returns false denying the value is Wrap<"[", "", "]">
Wrap.isWrap(null as any, '[', ']');

Last updated

Was this helpful?